-
Notifications
You must be signed in to change notification settings - Fork 21
/
ytt.go
64 lines (49 loc) · 1.75 KB
/
ytt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2022 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package carvelhelpers
import (
"io"
yttui "github.com/vmware-tanzu/carvel-ytt/pkg/cmd/ui"
"github.com/vmware-tanzu/carvel-ytt/pkg/files"
"github.com/vmware-tanzu/carvel-ytt/pkg/workspace"
"github.com/vmware-tanzu/carvel-ytt/pkg/workspace/datavalues"
)
// ProcessYTTPackage processes configuration directory with ytt tool
// Implements similar functionality as `ytt -f <config-dir>`
func ProcessYTTPackage(configDirs ...string) ([]byte, error) {
yttFiles, err := files.NewSortedFilesFromPaths(configDirs, files.SymlinkAllowOpts{})
if err != nil {
return nil, err
}
lib := workspace.NewRootLibrary(yttFiles)
libCtx := workspace.LibraryExecutionContext{Current: lib, Root: lib}
libExecFact := workspace.NewLibraryExecutionFactory(&NoopUI{}, workspace.TemplateLoaderOpts{})
loader := libExecFact.New(libCtx)
valuesDoc, libraryValueDoc, err := loader.Values([]*datavalues.Envelope{}, datavalues.NewNullSchema())
if err != nil {
return nil, err
}
result, err := loader.Eval(valuesDoc, libraryValueDoc, []*datavalues.SchemaEnvelope{})
if err != nil {
return nil, err
}
return result.DocSet.AsBytes()
}
// NoopUI implement noop interface for logging used with carvel tooling
type NoopUI struct{}
var _ yttui.UI = NoopUI{}
// Printf noop print
func (ui NoopUI) Printf(_ string, _ ...interface{}) {}
// Debugf noop debug
func (ui NoopUI) Debugf(_ string, _ ...interface{}) {}
// Warnf noop warn
func (ui NoopUI) Warnf(_ string, _ ...interface{}) {}
// DebugWriter noop debug writer
func (ui NoopUI) DebugWriter() io.Writer {
return noopWriter{}
}
type noopWriter struct{}
func (n noopWriter) Write(_ []byte) (int, error) {
return 0, nil
}
var _ io.Writer = noopWriter{}