generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 82
/
helm_test.go
373 lines (337 loc) · 15.7 KB
/
helm_test.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
//go:build e2e
// +build e2e
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e
import (
"os"
"path/filepath"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
. "sigs.k8s.io/cluster-api-operator/test/framework"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var _ = Describe("Create a proper set of manifests when using helm charts", func() {
It("should deploy a quick-start cluster-api-operator chart", func() {
clusterProxy := helmClusterProxy.GetClient()
fullHelmChart := &HelmChart{
BinaryPath: helmBinaryPath,
Path: chartPath,
Name: "capi-operator",
Kubeconfig: helmClusterProxy.GetKubeconfigPath(),
Wait: true,
Output: Full,
AdditionalFlags: Flags("--create-namespace", "--namespace", operatorNamespace),
}
defer func() {
fullHelmChart.Commands = Commands(Uninstall)
fullHelmChart.AdditionalFlags = Flags("--namespace", operatorNamespace)
fullHelmChart.Run(nil)
err := clusterProxy.DeleteAllOf(ctx, &apiextensionsv1.CustomResourceDefinition{}, client.MatchingLabels{
"clusterctl.cluster.x-k8s.io/core": "capi-operator",
})
Expect(err).ToNot(HaveOccurred())
}()
_, err := fullHelmChart.Run(nil)
Expect(err).ToNot(HaveOccurred())
coreProvider := &operatorv1.CoreProvider{
ObjectMeta: metav1.ObjectMeta{
Name: coreProviderName,
Namespace: operatorNamespace,
},
}
Expect(clusterProxy.Create(ctx, coreProvider)).To(Succeed())
By("Waiting for the core provider deployment to be ready")
framework.WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{
Getter: clusterProxy,
Deployment: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: coreProviderDeploymentName, Namespace: operatorNamespace}},
}, e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
By("Waiting for core provider to be ready")
WaitFor(ctx, For(coreProvider).In(clusterProxy).ToSatisfy(
HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition),
), e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
By("Waiting for status.IntalledVersion to be set")
WaitFor(ctx, For(coreProvider).In(clusterProxy).ToSatisfy(func() bool {
return ptr.Equal(coreProvider.Status.InstalledVersion, ptr.To(coreProvider.Spec.Version))
}), e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
bootstrapProvider := &operatorv1.BootstrapProvider{ObjectMeta: metav1.ObjectMeta{
Name: bootstrapProviderName,
Namespace: operatorNamespace,
}}
deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{
Name: bootstrapProviderDeploymentName,
Namespace: operatorNamespace,
}}
Expect(clusterProxy.Create(ctx, bootstrapProvider)).To(Succeed())
By("Waiting for the bootstrap provider deployment to be ready")
framework.WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{
Getter: clusterProxy,
Deployment: deployment,
}, e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
By("Waiting for bootstrap provider to be ready")
WaitFor(ctx, For(bootstrapProvider).In(clusterProxy).ToSatisfy(
HaveStatusCondition(&bootstrapProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)),
e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
By("Waiting for status.IntalledVersion to be set")
WaitFor(ctx, For(bootstrapProvider).In(clusterProxy).ToSatisfy(func() bool {
return ptr.Equal(bootstrapProvider.Status.InstalledVersion, &bootstrapProvider.Spec.Version)
}), e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
Expect(clusterProxy.Delete(ctx, bootstrapProvider)).To(Succeed())
By("Waiting for the bootstrap provider deployment to be deleted")
WaitForDelete(ctx, For(deployment).In(clusterProxy),
e2eConfig.GetIntervals(helmClusterProxy.GetName(), "wait-controllers")...)
Expect(clusterProxy.Delete(ctx, coreProvider)).To(Succeed())
})
It("should deploy default manifest set for quick-start process", func() {
fullRun := &HelmChart{
BinaryPath: helmChart.BinaryPath,
Path: helmChart.Path,
Name: helmChart.Name,
Kubeconfig: helmChart.Kubeconfig,
DryRun: helmChart.DryRun,
Output: Manifests,
}
fullRun.Output = Manifests
manifests, err := fullRun.Run(nil)
Expect(err).ToNot(HaveOccurred())
fullChartInstall, err := os.ReadFile(filepath.Join(customManifestsFolder, "full-chart-install.yaml"))
Expect(manifests).To(MatchYAML(string(fullChartInstall)))
})
It("should not deploy providers when none specified", func() {
manifests, err := helmChart.Run(nil)
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(BeEmpty())
})
It("should deploy all providers with custom namespace and versions", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"core": "capi-custom-ns:cluster-api:v1.7.7",
"controlPlane": "kubeadm-control-plane-custom-ns:kubeadm:v1.7.7",
"bootstrap": "kubeadm-bootstrap-custom-ns:kubeadm:v1.7.7",
"infrastructure": "capd-custom-ns:docker:v1.7.7",
"addon": "helm-custom-ns:helm:v0.2.6",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "all-providers-custom-ns-versions.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy all providers with custom versions", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"core": "cluster-api:v1.7.7",
"controlPlane": "kubeadm:v1.7.7",
"bootstrap": "kubeadm:v1.7.7",
"infrastructure": "docker:v1.7.7",
"addon": "helm:v0.2.6",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "all-providers-custom-versions.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy all providers with latest version", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"core": "cluster-api",
"controlPlane": "kubeadm",
"bootstrap": "kubeadm",
"infrastructure": "docker",
"addon": "helm",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "all-providers-latest-versions.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy core, bootstrap, control plane when only infra is specified", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"infrastructure": "docker",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "only-infra.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy core when only bootstrap is specified", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"bootstrap": "kubeadm",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "only-bootstrap.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy core when only control plane is specified", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"controlPlane": "kubeadm",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "only-control-plane.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy multiple infra providers with custom namespace and versions", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"infrastructure": "capd-custom-ns:docker:v1.7.7;capz-custom-ns:azure:v1.10.0",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "multiple-infra-custom-ns-versions.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy multiple control plane providers with custom namespace and versions", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"controlPlane": "kubeadm-control-plane-custom-ns:kubeadm:v1.7.7;rke2-control-plane-custom-ns:rke2:v0.8.0",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "multiple-control-plane-custom-ns-versions.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy multiple bootstrap providers with custom namespace and versions", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"bootstrap": "kubeadm-bootstrap-custom-ns:kubeadm:v1.7.7;rke2-bootstrap-custom-ns:rke2:v0.8.0",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "multiple-bootstrap-custom-ns-versions.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy core when only addon is specified", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"addon": "helm",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "only-addon.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy core, bootstrap, control plane when only infra and addon is specified", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"infrastructure": "docker",
"addon": "helm",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "only-infra-and-addon.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy core and infra with feature gates enabled", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "aws-variables",
"configSecret.namespace": "default",
"infrastructure": "aws:v2.4.0",
"addon": "helm:",
"image.manager.tag": "v0.9.1",
"cert-manager.enabled": "false",
"cert-manager.installCRDs": "false",
"core": "cluster-api:v1.6.2",
"manager.featureGates.core.ClusterTopology": "true",
"manager.featureGates.core.MachinePool": "true",
"manager.featureGates.aws.ClusterTopology": "true",
"manager.featureGates.aws.MachinePool": "true",
"manager.featureGates.aws.EKSEnableIAM": "true",
"manager.featureGates.aws.EKSAllowAddRoles": "true",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "feature-gates.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy all providers with manager defined but no feature gates enabled", func() {
manifests, err := helmChart.Run(map[string]string{
"configSecret.name": "test-secret-name",
"configSecret.namespace": "test-secret-namespace",
"infrastructure": "azure",
"addon": "helm",
"core": "cluster-api",
"manager.cert-manager.enabled": "false",
"manager.cert-manager.installCRDs": "false",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "all-providers-latest-versions.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy all providers when manager is defined but another infrastructure spec field is defined", func() {
manifests, err := helmChart.Run(map[string]string{
"core": "cluster-api",
"controlPlane": "kubeadm",
"bootstrap": "kubeadm",
"infrastructure": "docker",
"addon": "helm",
"manager.featureGates.core.ClusterTopology": "true",
"manager.featureGates.core.MachinePool": "true",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "manager-defined-missing-other-infra-spec.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
It("should deploy kubeadm control plane with manager specified", func() {
manifests, err := helmChart.Run(map[string]string{
"core": "cluster-api",
"controlPlane": "kubeadm",
"bootstrap": "kubeadm",
"infrastructure": "docker",
"addon": "helm",
"manager.featureGates.kubeadm.ClusterTopology": "true",
"manager.featureGates.kubeadm.MachinePool": "true",
})
Expect(err).ToNot(HaveOccurred())
Expect(manifests).ToNot(BeEmpty())
expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "kubeadm-manager-defined.yaml"))
Expect(err).ToNot(HaveOccurred())
Expect(manifests).To(MatchYAML(string(expectedManifests)))
})
})