From cc0aa10fc370a1ecf3f685a6d7fbab415f342b33 Mon Sep 17 00:00:00 2001 From: wangyelei Date: Fri, 13 Dec 2024 11:51:40 +0800 Subject: [PATCH] chore: component annotations updated failed (#8634) --- controllers/apps/cluster_controller_test.go | 4 ++++ controllers/apps/transformer_cluster_component.go | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/controllers/apps/cluster_controller_test.go b/controllers/apps/cluster_controller_test.go index 1bace46152d..eda071cbdf6 100644 --- a/controllers/apps/cluster_controller_test.go +++ b/controllers/apps/cluster_controller_test.go @@ -23,6 +23,7 @@ import ( "encoding/json" "fmt" "slices" + "strconv" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -1185,13 +1186,16 @@ var _ = Describe("Cluster Controller", func() { })()).ShouldNot(HaveOccurred()) By("check cluster and component objects been upgraded") + var clusterGenerate int64 Eventually(testapps.CheckObj(&testCtx, clusterKey, func(g Gomega, cluster *appsv1.Cluster) { g.Expect(cluster.Spec.ComponentSpecs[0].ComponentDef).Should(Equal(newCompDefObj.Name)) g.Expect(cluster.Spec.ComponentSpecs[0].ServiceVersion).Should(Equal(defaultServiceVersion)) + clusterGenerate = cluster.Generation })).Should(Succeed()) Eventually(testapps.CheckObj(&testCtx, compKey, func(g Gomega, comp *appsv1.Component) { g.Expect(comp.Spec.CompDef).Should(Equal(newCompDefObj.Name)) g.Expect(comp.Spec.ServiceVersion).Should(Equal(defaultServiceVersion)) + g.Expect(strconv.Itoa(int(clusterGenerate))).Should(Equal(comp.Annotations[constant.KubeBlocksGenerationKey])) })).Should(Succeed()) }) diff --git a/controllers/apps/transformer_cluster_component.go b/controllers/apps/transformer_cluster_component.go index 3ad4c915e24..8e871c9c671 100644 --- a/controllers/apps/transformer_cluster_component.go +++ b/controllers/apps/transformer_cluster_component.go @@ -181,10 +181,8 @@ func copyAndMergeComponent(oldCompObj, newCompObj *appsv1.Component) *appsv1.Com compProto := newCompObj // merge labels and annotations - ictrlutil.MergeMetadataMapInplace(compObjCopy.Annotations, &compProto.Annotations) - ictrlutil.MergeMetadataMapInplace(compObjCopy.Labels, &compProto.Labels) - compObjCopy.Annotations = compProto.Annotations - compObjCopy.Labels = compProto.Labels + ictrlutil.MergeMetadataMapInplace(compProto.Annotations, &compObjCopy.Annotations) + ictrlutil.MergeMetadataMapInplace(compProto.Labels, &compObjCopy.Labels) // merge spec compObjCopy.Spec.CompDef = compProto.Spec.CompDef