-
Notifications
You must be signed in to change notification settings - Fork 187
/
helm.go
230 lines (191 loc) · 6.4 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//go:build e2e
// +build e2e
package helm
import (
"fmt"
"os"
"os/exec"
"strings"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
const (
// setting a long chartName to test it doesn't break with dependency charts
// see https://github.com/Azure/secrets-store-csi-driver-provider-azure/issues/596
chartName = "csi-secrets-store-provider-azure"
podIdentityChartName = "pi"
)
// InstallInput is the input for Install.
type InstallInput struct {
Config *framework.Config
NamespacedMode bool
}
// Install installs csi-secrets-store-provider-azure via Helm 3.
func Install(input InstallInput) {
Expect(input.Config).NotTo(BeNil(), "input.Config is required for Helm.Install")
cwd, err := os.Getwd()
Expect(err).To(BeNil())
// Change current working directory to repo root
// Before installing csi-secrets-store-provider-azure through Helm
os.Chdir("../..")
defer os.Chdir(cwd)
chartDir := input.Config.HelmChartDir
args := append([]string{
"install",
chartName,
chartDir,
fmt.Sprintf("--namespace=%s", framework.NamespaceKubeSystem),
fmt.Sprintf("--set=secrets-store-csi-driver.enableSecretRotation=true"),
fmt.Sprintf("--set=secrets-store-csi-driver.rotationPollInterval=30s"),
fmt.Sprintf("--set=secrets-store-csi-driver.syncSecret.enabled=true"),
fmt.Sprintf(`--set=secrets-store-csi-driver.tokenRequests[0].audience=api://AzureADTokenExchange`),
fmt.Sprintf(`--set=linux.podAnnotations.foo=bar`),
fmt.Sprintf("--set=logVerbosity=5"),
fmt.Sprintf("--set=linux.customUserAgent=csi-e2e"),
fmt.Sprintf("--set=windows.customUserAgent=csi-e2e"),
"--dependency-update",
"--wait",
"--timeout=5m",
"--debug",
})
if input.Config.IsWindowsTest {
args = append(args,
fmt.Sprintf("--set=windows.enabled=true"),
fmt.Sprintf("--set=secrets-store-csi-driver.windows.enabled=true"))
}
args = append(args, generateValueArgs(input.Config)...)
err = helm(args)
Expect(err).To(BeNil())
}
// UpgradeInput is the input for helm upgrade.
type UpgradeInput struct {
Config *framework.Config
}
// Upgrade upgrades csi-secrets-store-provider-azure to chart specified in config
func Upgrade(input UpgradeInput) {
Expect(input.Config).NotTo(BeNil(), "input.Config is required for Helm upgrade")
cwd, err := os.Getwd()
Expect(err).To(BeNil())
// Change current working directory to repo root
// Before installing csi-secrets-store-provider-azure through Helm
os.Chdir("../..")
defer os.Chdir(cwd)
chartDir := input.Config.HelmChartDir
//resolve helm dependency
dependencyArgs := append([]string{
"dependency",
"update",
chartDir,
fmt.Sprintf("--namespace=%s", framework.NamespaceKubeSystem),
"--debug",
})
err = helm(dependencyArgs)
Expect(err).To(BeNil())
args := append([]string{
"upgrade",
chartName,
chartDir,
fmt.Sprintf("--namespace=%s", framework.NamespaceKubeSystem),
fmt.Sprintf("--set=secrets-store-csi-driver.enableSecretRotation=true"),
fmt.Sprintf("--set=secrets-store-csi-driver.rotationPollInterval=30s"),
fmt.Sprintf("--set=secrets-store-csi-driver.syncSecret.enabled=true"),
fmt.Sprintf(`--set=secrets-store-csi-driver.tokenRequests[0].audience=api://AzureADTokenExchange`),
fmt.Sprintf("--set=logVerbosity=1"),
fmt.Sprintf("--set=linux.customUserAgent=csi-e2e"),
fmt.Sprintf("--set=windows.customUserAgent=csi-e2e"),
"--wait",
"--timeout=5m",
"--debug",
})
if input.Config.IsWindowsTest {
args = append(args,
fmt.Sprintf("--set=windows.enabled=true"),
fmt.Sprintf("--set=secrets-store-csi-driver.windows.enabled=true"))
}
args = append(args, generateValueArgs(input.Config)...)
err = helm(args)
Expect(err).To(BeNil())
}
// Uninstall uninstalls csi-secrets-store-provider-azure via Helm 3.
func Uninstall() {
args := []string{
"uninstall",
chartName,
fmt.Sprintf("--namespace=%s", framework.NamespaceKubeSystem),
"--debug",
}
// ignore error to allow cleanup completion
_ = helm(args)
}
// ReleaseExists checks if csi release exists
func ReleaseExists() bool {
args := []string{
"status",
chartName,
fmt.Sprintf("--namespace=%s", framework.NamespaceKubeSystem),
}
err := helm(args)
// chart not found error
return err == nil
}
func generateValueArgs(config *framework.Config) []string {
args := []string{
fmt.Sprintf("--set=linux.image.repository=%s/%s", config.Registry, config.ImageName),
fmt.Sprintf("--set=windows.image.repository=%s/%s", config.Registry, config.ImageName),
}
// Set image.tag only if there is an image version provided. Else rely on default values.
if config.ImageVersion != "" {
args = append(args, fmt.Sprintf("--set=linux.image.tag=%s", config.ImageVersion), fmt.Sprintf("--set=windows.image.tag=%s", config.ImageVersion))
}
// add the custom env file volume and mount if exists
if config.AzureEnvironmentFilePath != "" {
args = append(args,
fmt.Sprintf("--set=linux.volumes[0].name=cloudenvfile-vol,linux.volumes[0].hostPath.path=%s,linux.volumes[0].hostPath.type=File", config.AzureEnvironmentFilePath),
fmt.Sprintf("--set=linux.volumeMounts[0].name=cloudenvfile-vol,linux.volumeMounts[0].mountPath=%s", config.AzureEnvironmentFilePath),
)
}
return args
}
func helm(args []string) error {
By(fmt.Sprintf("helm %s", strings.Join(args, " ")))
cmd := exec.Command("helm", args...)
stdoutStderr, err := cmd.CombinedOutput()
fmt.Printf("%s", stdoutStderr)
return err
}
// InstallPodIdentity installs aad-pod-identity via Helm3
func InstallPodIdentity() {
// add aad-pod-identity chart repo
args := append([]string{
"repo", "add", "aad-pod-identity", "https://raw.githubusercontent.com/Azure/aad-pod-identity/master/charts",
})
err := helm(args)
Expect(err).To(BeNil())
// update helm repo
args = append([]string{
"repo", "update",
})
err = helm(args)
Expect(err).To(BeNil())
// Install aad-pod-identity helm chart
args = append([]string{
"install",
podIdentityChartName,
fmt.Sprintf("--namespace=%s", framework.NamespaceKubeSystem),
"aad-pod-identity/aad-pod-identity", "--set", "nmi.allowNetworkPluginKubenet=true", "--wait", "--timeout=5m", "--debug",
})
err = helm(args)
Expect(err).To(BeNil())
}
// UninstallPodIdentity uninstalls aad-pod-identity
func UninstallPodIdentity() {
args := []string{
"uninstall",
podIdentityChartName,
fmt.Sprintf("--namespace=%s", framework.NamespaceKubeSystem),
"--debug",
}
// ignore error to allow cleanup completion
_ = helm(args)
}