Skip to content

Commit

Permalink
Merge pull request #461 from gianlucam76/fix
Browse files Browse the repository at this point in the history
Properly handle upgrade scenario with extra metadata
  • Loading branch information
gianlucam76 authored Feb 15, 2024
2 parents 98685bd + 373733a commit 870d713
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion controllers/handlers_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 19 additions & 4 deletions test/fv/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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{
{
Expand All @@ -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,
Expand All @@ -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())
Expand All @@ -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{
Expand Down

0 comments on commit 870d713

Please sign in to comment.