forked from carvel-dev/kapp-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkbld.go
54 lines (40 loc) · 1.08 KB
/
kbld.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
package template
import (
"bytes"
"io"
goexec "os/exec"
"github.com/k14s/kapp-controller/pkg/apis/kappctrl/v1alpha1"
"github.com/k14s/kapp-controller/pkg/exec"
)
type Kbld struct {
opts v1alpha1.AppTemplateKbld
genericOpts GenericOpts
}
var _ Template = &Kbld{}
func NewKbld(opts v1alpha1.AppTemplateKbld, genericOpts GenericOpts) *Kbld {
return &Kbld{opts, genericOpts}
}
func (t *Kbld) TemplateDir(dirPath string) exec.CmdRunResult {
return t.template(dirPath, nil)
}
func (t *Kbld) TemplateStream(input io.Reader) exec.CmdRunResult {
return t.template("-", input)
}
func (t *Kbld) template(dirPath string, input io.Reader) exec.CmdRunResult {
args := t.addArgs([]string{"-f", dirPath})
var stdoutBs, stderrBs bytes.Buffer
cmd := goexec.Command("kbld", args...)
cmd.Stdin = input
cmd.Stdout = &stdoutBs
cmd.Stderr = &stderrBs
err := cmd.Run()
result := exec.CmdRunResult{
Stdout: stdoutBs.String(),
Stderr: stderrBs.String(),
}
result.AttachErrorf("Templating dir: %s", err)
return result
}
func (t *Kbld) addArgs(args []string) []string {
return args
}