From 373733a5d22c5531f8c87441ce4e94bbe7b78951 Mon Sep 17 00:00:00 2001 From: mgianluc Date: Thu, 15 Feb 2024 13:50:57 +0100 Subject: [PATCH] Properly handle upgrade scenario with extra metadata If extra metadata has not changed, still set HelmReleaseSummaries MetadataHash. --- controllers/handlers_helm.go | 2 +- test/fv/helm_test.go | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/controllers/handlers_helm.go b/controllers/handlers_helm.go index ffbc6b6d..a9a9f12a 100644 --- a/controllers/handlers_helm.go +++ b/controllers/handlers_helm.go @@ -1681,7 +1681,7 @@ func addExtraMetadata(ctx context.Context, requestedChart *configv1alpha1.HelmCh lastDeployedMetadataHash := getMetadataHashFromHelmChartSummary(requestedChart, clusterSummary) if reflect.DeepEqual(metadataHash, lastDeployedMetadataHash) { - return nil + return updateMetadataHashOnHelmChartSummary(ctx, requestedChart, metadataHash, clusterSummary) } actionConfig, err := actionConfigInit(requestedChart.ReleaseNamespace, kubeconfig) diff --git a/test/fv/helm_test.go b/test/fv/helm_test.go index 0f0dbb6b..e5a1fdae 100644 --- a/test/fv/helm_test.go +++ b/test/fv/helm_test.go @@ -129,7 +129,7 @@ var _ = Describe("Helm", func() { Byf("Verifying wildfly deployment is created in the workload cluster") Eventually(func() error { - depl := &appsv1.Deployment{} + depl = &appsv1.Deployment{} return workloadClient.Get(context.TODO(), types.NamespacedName{Namespace: "wildfly", Name: "wildfly"}, depl) }, timeout, pollingInterval).Should(BeNil()) @@ -146,7 +146,7 @@ var _ = Describe("Helm", func() { clusterSummary.Spec.ClusterNamespace, clusterSummary.Spec.ClusterName, configv1alpha1.FeatureHelm, nil, charts) - Byf("Changing ClusterProfile requiring different chart version for kyverno") + Byf("Changing ClusterProfile requiring different chart version for kyverno and update extra labels") Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: clusterProfile.Name}, currentClusterProfile)).To(Succeed()) currentClusterProfile.Spec.HelmCharts = []configv1alpha1.HelmChart{ { @@ -168,6 +168,12 @@ var _ = Describe("Helm", func() { HelmChartAction: configv1alpha1.HelmChartActionInstall, }, } + currentClusterProfile.Spec.ExtraLabels = map[string]string{ + randomString(): randomString(), + randomString(): randomString(), + randomString(): randomString(), + } + currentClusterProfile.Spec.ExtraAnnotations = nil Expect(k8sClient.Update(context.TODO(), currentClusterProfile)).To(Succeed()) verifyClusterSummary(controllers.ClusterProfileLabelName, @@ -176,14 +182,14 @@ var _ = Describe("Helm", func() { Byf("Verifying kyverno deployment is still present in the workload cluster") Eventually(func() error { - depl := &appsv1.Deployment{} + depl = &appsv1.Deployment{} return workloadClient.Get(context.TODO(), types.NamespacedName{Namespace: "kyverno", Name: "kyverno-admission-controller"}, depl) }, timeout, pollingInterval).Should(BeNil()) Byf("Verifying wildfly deployment is still in the workload cluster") Eventually(func() error { - depl := &appsv1.Deployment{} + depl = &appsv1.Deployment{} return workloadClient.Get(context.TODO(), types.NamespacedName{Namespace: "wildfly", Name: "wildfly"}, depl) }, timeout, pollingInterval).Should(BeNil()) @@ -200,6 +206,15 @@ var _ = Describe("Helm", func() { clusterSummary.Spec.ClusterNamespace, clusterSummary.Spec.ClusterName, configv1alpha1.FeatureHelm, nil, charts) + Byf("Verifying kyverno deployment has proper labels/annotations") + Expect(workloadClient.Get(context.TODO(), + types.NamespacedName{Namespace: "kyverno", Name: "kyverno-admission-controller"}, depl)) + content, err = runtime.DefaultUnstructuredConverter.ToUnstructured(depl) + Expect(err).To(BeNil()) + u.SetUnstructuredContent(content) + verifyExtraLabels(&u, currentClusterProfile.Spec.ExtraLabels) + verifyExtraAnnotations(&u, currentClusterProfile.Spec.ExtraAnnotations) + Byf("Changing ClusterProfile to not require wildfly anymore") Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: clusterProfile.Name}, currentClusterProfile)).To(Succeed()) currentClusterProfile.Spec.HelmCharts = []configv1alpha1.HelmChart{