-
Notifications
You must be signed in to change notification settings - Fork 41
/
helm.go
96 lines (82 loc) · 1.92 KB
/
helm.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package helm
import (
"fmt"
"github.com/maistra/maistra-test-tool/pkg/util/shell"
"github.com/maistra/maistra-test-tool/pkg/util/test"
)
type cmd struct {
chart string
namespace string
release string
setValues []string
valuesStdIn string
version string
}
func Namespace(ns string) cmd {
return cmd{namespace: ns}
}
func (c cmd) Release(name string) cmd {
c.release = name
return c
}
func (c cmd) Chart(chart string) cmd {
c.chart = chart
return c
}
func (c cmd) Version(ver string) cmd {
c.version = ver
return c
}
func (c cmd) Set(keyValue string) cmd {
c.setValues = append(c.setValues, keyValue)
return c
}
func (c cmd) ValuesString(values string) cmd {
c.valuesStdIn = values
return c
}
func (c cmd) Install(t test.TestHelper) {
if c.chart == "" {
t.Fatalf("chart must be specified to install helm release")
}
if c.release == "" {
t.Fatalf("release name must be specified to install helm release")
}
if c.namespace == "" {
t.Fatalf("namespace must be specified to install helm release")
}
cmd := fmt.Sprintf("helm install %s %s -n %s", c.release, c.chart, c.namespace)
if c.version != "" {
cmd += fmt.Sprintf(" --version %s", c.version)
}
for _, val := range c.setValues {
cmd += fmt.Sprintf(" --set %s", val)
}
if c.valuesStdIn != "" {
cmd += fmt.Sprintf(` -f - <<EOF
%s
EOF`, c.valuesStdIn)
}
shell.Execute(t, cmd)
}
func (c cmd) Uninstall(t test.TestHelper) {
if c.release == "" {
t.Fatalf("release name must be specified to uninstall helm release")
}
if c.namespace == "" {
t.Fatalf("namespace must be specified to uninstall helm release")
}
shell.Executef(t, "helm uninstall %s -n %s", c.release, c.namespace)
}
type repo struct {
url string
}
func Repo(url string) repo {
return repo{url: url}
}
func (r repo) Add(t test.TestHelper, name string) {
if name == "" {
t.Fatalf("repo name must be specified")
}
shell.Executef(t, "helm repo add %s %s", name, r.url)
}