Skip to content

Commit b7c61ff

Browse files
committed
Fix e2e test to utilise chart which is able to install with wait option
1 parent 2b23ccc commit b7c61ff

File tree

3 files changed

+83
-19
lines changed

3 files changed

+83
-19
lines changed

controllers/helmchartproxy/helmchartproxy_controller_phases.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ func constructHelmReleaseProxy(existing *addonsv1alpha1.HelmReleaseProxy, helmCh
226226
if !cmp.Equal(existing.Spec.Values, parsedValues) {
227227
changed = true
228228
}
229+
if existing.Spec.ReleaseDrift != helmChartProxy.Spec.ReleaseDrift {
230+
changed = true
231+
}
229232

230233
if !changed {
231234
return nil
@@ -289,6 +292,9 @@ func shouldReinstallHelmRelease(ctx context.Context, existing *addonsv1alpha1.He
289292
case existing.Spec.ReleaseNamespace != helmChartProxy.Spec.ReleaseNamespace:
290293
log.V(2).Info("ReleaseNamespace changed", "existing", existing.Spec.ReleaseNamespace, "helmChartProxy", helmChartProxy.Spec.ReleaseNamespace)
291294
return true
295+
case existing.Spec.ReleaseDrift != helmChartProxy.Spec.ReleaseDrift:
296+
log.V(2).Info("ReleaseDrift changed", "existing", existing.Spec.ReleaseDrift, "helmChartProxy", helmChartProxy.Spec.ReleaseDrift)
297+
return true
292298
}
293299

294300
return false

test/e2e/helm_releasedrift.go

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ import (
3535
"sigs.k8s.io/cluster-api/test/framework"
3636
)
3737

38+
type ValidationType string
39+
40+
const (
41+
ValidationEventually ValidationType = "Eventually"
42+
ValidationConsistently ValidationType = "Consistently"
43+
)
44+
3845
// HelmReleaseDriftInput specifies the input for Helm release drift Deployment validation and verifying that it was successful.
3946
type HelmReleaseDriftInput struct {
4047
BootstrapClusterProxy framework.ClusterProxy
@@ -44,6 +51,7 @@ type HelmReleaseDriftInput struct {
4451
UpdatedDeploymentReplicas int32
4552
ExpectedDeploymentReplicas int32
4653
ExpectedRevision int
54+
Validation ValidationType
4755
}
4856

4957
func HelmReleaseDriftWithDeployment(ctx context.Context, inputGetter func() HelmReleaseDriftInput) {
@@ -54,6 +62,7 @@ func HelmReleaseDriftWithDeployment(ctx context.Context, inputGetter func() Helm
5462
)
5563
input = inputGetter()
5664
hcp := input.HelmChartProxy
65+
Expect(input.Validation).NotTo(BeEmpty(), "HelmReleaseDriftInput must contains validation type to be defined")
5766

5867
// Get workload Cluster proxy
5968
By("creating a clusterctl proxy to the workload cluster")
@@ -73,17 +82,31 @@ func HelmReleaseDriftWithDeployment(ctx context.Context, inputGetter func() Helm
7382
Expect(err).NotTo(HaveOccurred())
7483

7584
deploymentName := ctrlclient.ObjectKeyFromObject(deployment)
76-
// Wait for Helm release Deployment replicas to be returned back
77-
Eventually(func() error {
78-
if err := mgmtClient.Get(ctx, deploymentName, deployment); err != nil {
79-
return err
80-
}
81-
if *deployment.Spec.Replicas != input.ExpectedDeploymentReplicas && deployment.Status.ReadyReplicas != input.ExpectedDeploymentReplicas {
82-
return fmt.Errorf("expected Deployment replicas to be %d, got %d", input.ExpectedDeploymentReplicas, deployment.Status.ReadyReplicas)
83-
}
84-
85-
return nil
86-
}, e2eConfig.GetIntervals("default", "wait-helm-release-drift")...).Should(Succeed())
85+
if input.Validation == ValidationEventually {
86+
// Wait for Helm release Deployment replicas to be returned back
87+
Eventually(func() error {
88+
if err = mgmtClient.Get(ctx, deploymentName, deployment); err != nil {
89+
return err
90+
}
91+
if *deployment.Spec.Replicas != input.ExpectedDeploymentReplicas && deployment.Status.ReadyReplicas != input.ExpectedDeploymentReplicas {
92+
return fmt.Errorf("expected Deployment replicas to be %d, got %d", input.ExpectedDeploymentReplicas, deployment.Status.ReadyReplicas)
93+
}
94+
95+
return nil
96+
}, e2eConfig.GetIntervals("default", "wait-helm-release-drift")...).Should(Succeed())
97+
}
98+
if input.Validation == ValidationConsistently {
99+
Consistently(func() error {
100+
if err = mgmtClient.Get(ctx, deploymentName, deployment); err != nil {
101+
return err
102+
}
103+
if *deployment.Spec.Replicas != input.ExpectedDeploymentReplicas && deployment.Status.ReadyReplicas != input.ExpectedDeploymentReplicas {
104+
return fmt.Errorf("expected Deployment replicas to be %d, got %d", input.ExpectedDeploymentReplicas, deployment.Status.ReadyReplicas)
105+
}
106+
107+
return nil
108+
}, e2eConfig.GetIntervals("default", "wait-helm-release-drift")...).Should(Succeed())
109+
}
87110

88111
helmUpgradeInput := HelmUpgradeInput{
89112
BootstrapClusterProxy: workloadClusterProxy,

test/e2e/helm_test.go

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ var _ = Describe("Workload cluster creation", func() {
220220
})
221221
})
222222

223-
It("Install and manage Helm chart with ReleaseDrift option enabled", func() {
223+
FIt("Install and manage Helm chart with ReleaseDrift option enabled", func() {
224224
clusterName = fmt.Sprintf("%s-%s", specName, util.RandomString(6))
225225
clusterctl.ApplyClusterTemplateAndWait(ctx, createApplyClusterTemplateInput(
226226
specName,
@@ -235,7 +235,7 @@ var _ = Describe("Workload cluster creation", func() {
235235

236236
hcp := &addonsv1alpha1.HelmChartProxy{
237237
ObjectMeta: metav1.ObjectMeta{
238-
Name: "nginx-ingress",
238+
Name: "ahoy",
239239
Namespace: namespace.Name,
240240
},
241241
Spec: addonsv1alpha1.HelmChartProxySpec{
@@ -244,13 +244,17 @@ var _ = Describe("Workload cluster creation", func() {
244244
"nginxIngress": "enabled",
245245
},
246246
},
247-
ReleaseName: "nginx-ingress",
248-
ReleaseNamespace: "nginx-namespace",
249-
ChartName: "nginx-ingress",
250-
RepoURL: "https://helm.nginx.com/stable",
247+
ChartName: "hello-world",
248+
RepoURL: "https://helm.github.io/examples",
249+
ReleaseName: "ahoy",
250+
ReleaseNamespace: "ahoy-namespace",
251251
ValuesTemplate: nginxValues,
252-
ReleaseDrift: true,
253252
ReconcileStrategy: string(addonsv1alpha1.ReconcileStrategyContinuous),
253+
ReleaseDrift: true,
254+
Options: addonsv1alpha1.HelmOptions{
255+
Wait: true,
256+
Timeout: &metav1.Duration{Duration: 5 * time.Minute},
257+
},
254258
},
255259
}
256260

@@ -267,7 +271,7 @@ var _ = Describe("Workload cluster creation", func() {
267271
})
268272

269273
// Updating Nginx deployment and waiting for the release drift
270-
By("Updating Nginx deployment and waiting for the release drift", func() {
274+
By("Updating Nginx deployment and waiting for release drift", func() {
271275
HelmReleaseDriftWithDeployment(ctx, func() HelmReleaseDriftInput {
272276
return HelmReleaseDriftInput{
273277
BootstrapClusterProxy: bootstrapClusterProxy,
@@ -277,6 +281,37 @@ var _ = Describe("Workload cluster creation", func() {
277281
UpdatedDeploymentReplicas: 2,
278282
ExpectedDeploymentReplicas: 1,
279283
ExpectedRevision: 2,
284+
Validation: ValidationEventually,
285+
}
286+
})
287+
})
288+
289+
// Update existing Helm chart
290+
By("Updating HelmChartProxy disabling release drift option", func() {
291+
hcp.Spec.ReleaseDrift = false
292+
HelmUpgradeSpec(ctx, func() HelmUpgradeInput {
293+
return HelmUpgradeInput{
294+
BootstrapClusterProxy: bootstrapClusterProxy,
295+
Namespace: namespace,
296+
ClusterName: clusterName,
297+
HelmChartProxy: hcp,
298+
ExpectedRevision: 1,
299+
}
300+
})
301+
})
302+
303+
// Updating Nginx deployment and waiting for the release drift
304+
By("Updating Nginx deployment and waiting release drift to be inactive for a long time", func() {
305+
HelmReleaseDriftWithDeployment(ctx, func() HelmReleaseDriftInput {
306+
return HelmReleaseDriftInput{
307+
BootstrapClusterProxy: bootstrapClusterProxy,
308+
Namespace: namespace,
309+
ClusterName: clusterName,
310+
HelmChartProxy: hcp,
311+
UpdatedDeploymentReplicas: 2,
312+
ExpectedDeploymentReplicas: 2,
313+
ExpectedRevision: 1,
314+
Validation: ValidationConsistently,
280315
}
281316
})
282317
})

0 commit comments

Comments
 (0)