diff --git a/pkg/controllers/workgenerator/controller_integration_test.go b/pkg/controllers/workgenerator/controller_integration_test.go index cf2e39925..f5b6f2491 100644 --- a/pkg/controllers/workgenerator/controller_integration_test.go +++ b/pkg/controllers/workgenerator/controller_integration_test.go @@ -6,6 +6,8 @@ Licensed under the MIT license. package workgenerator import ( + "crypto/sha256" + "encoding/json" "fmt" "strconv" "time" @@ -64,13 +66,14 @@ const ( ) var _ = Describe("Test Work Generator Controller", func() { - Context("Test Bound ClusterResourceBinding", func() { var binding *placementv1beta1.ClusterResourceBinding ignoreTypeMeta := cmpopts.IgnoreFields(metav1.TypeMeta{}, "Kind", "APIVersion") ignoreWorkOption := cmpopts.IgnoreFields(metav1.ObjectMeta{}, "UID", "ResourceVersion", "ManagedFields", "CreationTimestamp", "Generation") - + var emptyArray []string + jsonBytes, _ := json.Marshal(emptyArray) + emptyHash := fmt.Sprintf("%x", sha256.Sum256(jsonBytes)) BeforeEach(func() { memberClusterName = "cluster-" + utils.RandStr() testCRPName = "crp" + utils.RandStr() @@ -306,6 +309,10 @@ var _ = Describe("Test Work Generator Controller", func() { placementv1beta1.ParentBindingLabel: binding.Name, placementv1beta1.ParentResourceSnapshotIndexLabel: "1", }, + Annotations: map[string]string{ + placementv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation: emptyHash, + placementv1beta1.ParentResourceOverrideSnapshotHashAnnotation: emptyHash, + }, }, Spec: placementv1beta1.WorkSpec{ Workload: placementv1beta1.WorkloadTemplate{ @@ -395,6 +402,10 @@ var _ = Describe("Test Work Generator Controller", func() { placementv1beta1.ParentBindingLabel: binding.Name, placementv1beta1.ParentResourceSnapshotIndexLabel: "1", }, + Annotations: map[string]string{ + placementv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation: emptyHash, + placementv1beta1.ParentResourceOverrideSnapshotHashAnnotation: emptyHash, + }, }, Spec: placementv1beta1.WorkSpec{ Workload: placementv1beta1.WorkloadTemplate{ @@ -492,6 +503,10 @@ var _ = Describe("Test Work Generator Controller", func() { placementv1beta1.ParentBindingLabel: binding.Name, placementv1beta1.ParentResourceSnapshotIndexLabel: "1", }, + Annotations: map[string]string{ + placementv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation: emptyHash, + placementv1beta1.ParentResourceOverrideSnapshotHashAnnotation: emptyHash, + }, }, Spec: placementv1beta1.WorkSpec{ Workload: placementv1beta1.WorkloadTemplate{ @@ -531,6 +546,10 @@ var _ = Describe("Test Work Generator Controller", func() { placementv1beta1.EnvelopeNameLabel: "envelop-configmap", placementv1beta1.EnvelopeNamespaceLabel: "app", }, + Annotations: map[string]string{ + placementv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation: emptyHash, + placementv1beta1.ParentResourceOverrideSnapshotHashAnnotation: emptyHash, + }, }, Spec: placementv1beta1.WorkSpec{ Workload: placementv1beta1.WorkloadTemplate{ @@ -609,6 +628,10 @@ var _ = Describe("Test Work Generator Controller", func() { placementv1beta1.ParentBindingLabel: binding.Name, placementv1beta1.ParentResourceSnapshotIndexLabel: "2", }, + Annotations: map[string]string{ + placementv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation: emptyHash, + placementv1beta1.ParentResourceOverrideSnapshotHashAnnotation: emptyHash, + }, }, Spec: placementv1beta1.WorkSpec{ Workload: placementv1beta1.WorkloadTemplate{ @@ -647,6 +670,10 @@ var _ = Describe("Test Work Generator Controller", func() { placementv1beta1.EnvelopeNameLabel: "envelop-configmap", placementv1beta1.EnvelopeNamespaceLabel: "app", }, + Annotations: map[string]string{ + placementv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation: emptyHash, + placementv1beta1.ParentResourceOverrideSnapshotHashAnnotation: emptyHash, + }, }, Spec: placementv1beta1.WorkSpec{ Workload: placementv1beta1.WorkloadTemplate{ @@ -787,6 +814,10 @@ var _ = Describe("Test Work Generator Controller", func() { placementv1beta1.ParentResourceSnapshotIndexLabel: "2", placementv1beta1.ParentBindingLabel: binding.Name, }, + Annotations: map[string]string{ + placementv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation: emptyHash, + placementv1beta1.ParentResourceOverrideSnapshotHashAnnotation: emptyHash, + }, }, Spec: placementv1beta1.WorkSpec{ Workload: placementv1beta1.WorkloadTemplate{ @@ -857,6 +888,10 @@ var _ = Describe("Test Work Generator Controller", func() { placementv1beta1.ParentResourceSnapshotIndexLabel: "2", placementv1beta1.ParentBindingLabel: binding.Name, }, + Annotations: map[string]string{ + placementv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation: emptyHash, + placementv1beta1.ParentResourceOverrideSnapshotHashAnnotation: emptyHash, + }, }, Spec: placementv1beta1.WorkSpec{ Workload: placementv1beta1.WorkloadTemplate{ @@ -1082,6 +1117,7 @@ var _ = Describe("Test Work Generator Controller", func() { Context("Test Bound ClusterResourceBinding with a single resource snapshot and valid overrides", func() { var masterSnapshot *placementv1beta1.ClusterResourceSnapshot + var roHash, croHash string BeforeEach(func() { masterSnapshot = generateResourceSnapshot(1, 1, 0, [][]byte{ @@ -1089,21 +1125,25 @@ var _ = Describe("Test Work Generator Controller", func() { }) Expect(k8sClient.Create(ctx, masterSnapshot)).Should(Succeed()) By(fmt.Sprintf("master resource snapshot %s created", masterSnapshot.Name)) - spec := placementv1beta1.ResourceBindingSpec{ - State: placementv1beta1.BindingStateBound, - ResourceSnapshotName: masterSnapshot.Name, - TargetCluster: memberClusterName, - ClusterResourceOverrideSnapshots: []string{ - validClusterResourceOverrideSnapshotName, - }, - ResourceOverrideSnapshots: []placementv1beta1.NamespacedName{ - { - Name: validResourceOverrideSnapshotName, - Namespace: appNamespaceName, - }, + crolist := []string{validClusterResourceOverrideSnapshotName} + roList := []placementv1beta1.NamespacedName{ + { + Name: validResourceOverrideSnapshotName, + Namespace: appNamespaceName, }, } + spec := placementv1beta1.ResourceBindingSpec{ + State: placementv1beta1.BindingStateBound, + ResourceSnapshotName: masterSnapshot.Name, + TargetCluster: memberClusterName, + ClusterResourceOverrideSnapshots: crolist, + ResourceOverrideSnapshots: roList, + } createClusterResourceBinding(&binding, spec) + jsonBytes, _ := json.Marshal(roList) + roHash = fmt.Sprintf("%x", sha256.Sum256(jsonBytes)) + jsonBytes, _ = json.Marshal(crolist) + croHash = fmt.Sprintf("%x", sha256.Sum256(jsonBytes)) }) AfterEach(func() { @@ -1146,6 +1186,10 @@ var _ = Describe("Test Work Generator Controller", func() { placementv1beta1.ParentBindingLabel: binding.Name, placementv1beta1.ParentResourceSnapshotIndexLabel: "1", }, + Annotations: map[string]string{ + placementv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation: croHash, + placementv1beta1.ParentResourceOverrideSnapshotHashAnnotation: roHash, + }, }, Spec: placementv1beta1.WorkSpec{ Workload: placementv1beta1.WorkloadTemplate{ @@ -1374,6 +1418,10 @@ var _ = Describe("Test Work Generator Controller", func() { placementv1beta1.ParentBindingLabel: binding.Name, placementv1beta1.ParentResourceSnapshotIndexLabel: "1", }, + Annotations: map[string]string{ + placementv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation: emptyHash, + placementv1beta1.ParentResourceOverrideSnapshotHashAnnotation: emptyHash, + }, }, Spec: placementv1beta1.WorkSpec{ Workload: placementv1beta1.WorkloadTemplate{ diff --git a/test/e2e/rollout_test.go b/test/e2e/rollout_test.go index 1db441dfa..a87624bb8 100644 --- a/test/e2e/rollout_test.go +++ b/test/e2e/rollout_test.go @@ -655,7 +655,7 @@ var _ = Describe("placing wrapped resources using a CRP", Ordered, func() { }) }) - Context("Test a CRP place custom resource successfully, should wait to update resource on multiple member clusters", Ordered, func() { + FContext("Test a CRP place custom resource successfully, should wait to update resource on multiple member clusters", Ordered, func() { crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess()) workNamespace := appNamespace() var wantSelectedResources []placementv1beta1.ResourceIdentifier