Skip to content

Commit

Permalink
fix: vscale ops is always running when need to rerender configuration (
Browse files Browse the repository at this point in the history
…#8718)

(cherry picked from commit ed79737)
  • Loading branch information
wangyelei committed Dec 26, 2024
1 parent 3451a26 commit 8d039ac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
30 changes: 23 additions & 7 deletions controllers/apps/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ var _ = Describe("Cluster Controller", func() {

testUpdateAnnoAndLabels := func(compName string,
changeCluster func(cluster *appsv1.Cluster),
checkWorkloadFunc func(g Gomega, labels, annotations map[string]string),
checkWorkloadFunc func(g Gomega, labels, annotations map[string]string, isInstanceSet bool),
checkRelatedObjFunc func(g Gomega, obj client.Object)) {
Expect(testapps.ChangeObj(&testCtx, clusterObj, func(obj *appsv1.Cluster) {
changeCluster(obj)
Expand All @@ -1244,7 +1244,7 @@ var _ = Describe("Cluster Controller", func() {
workloadName := constant.GenerateWorkloadNamePattern(clusterObj.Name, defaultCompName)
Eventually(testapps.CheckObj(&testCtx, client.ObjectKey{Name: workloadName,
Namespace: testCtx.DefaultNamespace}, func(g Gomega, compObj *appsv1.Component) {
checkWorkloadFunc(g, compObj.Spec.Labels, compObj.Spec.Annotations)
checkWorkloadFunc(g, compObj.Spec.Labels, compObj.Spec.Annotations, false)
})).Should(Succeed())

By("check related objects annotations and labels")
Expand All @@ -1256,7 +1256,7 @@ var _ = Describe("Cluster Controller", func() {
// The labels and annotations of the Pod will be kept consistent with those of the InstanceSet
Eventually(testapps.CheckObj(&testCtx, client.ObjectKey{Name: workloadName, Namespace: testCtx.DefaultNamespace},
func(g Gomega, instanceSet *workloadsv1.InstanceSet) {
checkWorkloadFunc(g, instanceSet.Spec.Template.GetLabels(), instanceSet.Spec.Template.GetAnnotations())
checkWorkloadFunc(g, instanceSet.Spec.Template.GetLabels(), instanceSet.Spec.Template.GetAnnotations(), true)
})).Should(Succeed())
}

Expand All @@ -1278,7 +1278,7 @@ var _ = Describe("Cluster Controller", func() {
addMetaMap(&cluster.Spec.ComponentSpecs[0].Annotations, key1, value1)
addMetaMap(&cluster.Spec.ComponentSpecs[0].Labels, key1, value1)
},
func(g Gomega, labels, annotations map[string]string) {
func(g Gomega, labels, annotations map[string]string, isInstanceSet bool) {
g.Expect(labels[key1]).Should(Equal(value1))
g.Expect(annotations[key1]).Should(Equal(value1))
},
Expand All @@ -1287,14 +1287,22 @@ var _ = Describe("Cluster Controller", func() {
g.Expect(obj.GetAnnotations()[key1]).Should(Equal(value1))
})

By("merge instanceSet template annotations")
workloadName := constant.GenerateWorkloadNamePattern(clusterObj.Name, defaultCompName)
podTemplateKey := "pod-template-key"
podTemplateValue := "pod-template-value"
Expect(testapps.GetAndChangeObj(&testCtx, client.ObjectKey{Name: workloadName, Namespace: testCtx.DefaultNamespace}, func(instanceSet *workloadsv1.InstanceSet) {
instanceSet.Spec.Template.Annotations[podTemplateKey] = podTemplateValue
})()).Should(Succeed())

By("override annotations and labels")
value2 := "value2"
testUpdateAnnoAndLabels(defaultCompName,
func(cluster *appsv1.Cluster) {
addMetaMap(&cluster.Spec.ComponentSpecs[0].Annotations, key1, value2)
addMetaMap(&cluster.Spec.ComponentSpecs[0].Labels, key1, value2)
},
func(g Gomega, labels, annotations map[string]string) {
func(g Gomega, labels, annotations map[string]string, isInstanceSet bool) {
g.Expect(labels[key1]).Should(Equal(value2))
g.Expect(annotations[key1]).Should(Equal(value2))
},
Expand All @@ -1303,6 +1311,12 @@ var _ = Describe("Cluster Controller", func() {
g.Expect(obj.GetAnnotations()[key1]).Should(Equal(value2))
})

By("check InstanceSet template annotations should keep the custom annotations")
Eventually(testapps.CheckObj(&testCtx, client.ObjectKey{Name: workloadName, Namespace: testCtx.DefaultNamespace},
func(g Gomega, instanceSet *workloadsv1.InstanceSet) {
g.Expect(instanceSet.Spec.Template.Annotations[podTemplateKey]).Should(Equal(podTemplateValue))
})).Should(Succeed())

By("delete the annotations and labels, but retain the deleted annotations and labels for related objects")
key2 := "key2"
testUpdateAnnoAndLabels(defaultCompName,
Expand All @@ -1314,9 +1328,11 @@ var _ = Describe("Cluster Controller", func() {
key2: value2,
}
},
func(g Gomega, labels, annotations map[string]string) {
func(g Gomega, labels, annotations map[string]string, isInstanceSet bool) {
g.Expect(labels).ShouldNot(HaveKey(key1))
g.Expect(annotations).ShouldNot(HaveKey(key1))
if !isInstanceSet {
g.Expect(annotations).ShouldNot(HaveKey(key1))
}
g.Expect(labels[key2]).Should(Equal(value2))
g.Expect(annotations[key2]).Should(Equal(value2))
},
Expand Down
7 changes: 6 additions & 1 deletion controllers/apps/transformer_component_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,12 @@ func copyAndMergeITS(oldITS, newITS *workloads.InstanceSet) *workloads.InstanceS
}
intctrlutil.MergeMetadataMapInplace(itsProto.Annotations, &itsObjCopy.Annotations)
intctrlutil.MergeMetadataMapInplace(itsProto.Labels, &itsObjCopy.Labels)
itsObjCopy.Spec.Template = *itsProto.Spec.Template.DeepCopy()
// merge pod spec template annotations
intctrlutil.MergeMetadataMapInplace(itsProto.Spec.Template.Annotations, &itsObjCopy.Spec.Template.Annotations)
podTemplateCopy := *itsProto.Spec.Template.DeepCopy()
podTemplateCopy.Annotations = itsObjCopy.Spec.Template.Annotations

itsObjCopy.Spec.Template = podTemplateCopy
itsObjCopy.Spec.Replicas = itsProto.Spec.Replicas
itsObjCopy.Spec.Roles = itsProto.Spec.Roles
itsObjCopy.Spec.MembershipReconfiguration = itsProto.Spec.MembershipReconfiguration
Expand Down

0 comments on commit 8d039ac

Please sign in to comment.