From fed5020c12c8fe97aea86196dd2f8b467f702f9e Mon Sep 17 00:00:00 2001 From: Qing Hao Date: Tue, 6 Jun 2023 13:25:27 +0800 Subject: [PATCH] stabilize placement integration test (#165) Signed-off-by: haoqing0110 --- test/integration/placement/assertion_test.go | 26 ++++++---- test/integration/placement/placement_test.go | 51 ++++++-------------- 2 files changed, 31 insertions(+), 46 deletions(-) diff --git a/test/integration/placement/assertion_test.go b/test/integration/placement/assertion_test.go index 557c2913e..6bd12baa2 100644 --- a/test/integration/placement/assertion_test.go +++ b/test/integration/placement/assertion_test.go @@ -3,10 +3,11 @@ package placement import ( "context" "fmt" - "open-cluster-management.io/ocm/test/integration/util" "sort" "time" + "open-cluster-management.io/ocm/test/integration/util" + "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -410,16 +411,23 @@ func assertCreatingPlacementWithDecision(name, namespace string, noc *int32, nod } } -func assertUpdatingPlacement(name, namespace string, noc *int32, prioritizerPolicy clusterapiv1beta1.PrioritizerPolicy, tolerations []clusterapiv1beta1.Toleration) { +func assertUpdatingPlacement(name, namespace string, noc *int32, clusterSet []string, predicate []clusterapiv1beta1.ClusterPredicate, prioritizerPolicy clusterapiv1beta1.PrioritizerPolicy, tolerations []clusterapiv1beta1.Toleration) { ginkgo.By("Updating placement") - placement, err := clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), name, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + gomega.Eventually(func() error { + placement, err := clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), name, metav1.GetOptions{}) + if err != nil { + return err + } - placement.Spec.NumberOfClusters = noc - placement.Spec.Tolerations = tolerations - placement.Spec.PrioritizerPolicy = prioritizerPolicy - placement, err = clusterClient.ClusterV1beta1().Placements(namespace).Update(context.Background(), placement, metav1.UpdateOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + placement.Spec.NumberOfClusters = noc + placement.Spec.ClusterSets = clusterSet + placement.Spec.Predicates = predicate + placement.Spec.PrioritizerPolicy = prioritizerPolicy + placement.Spec.Tolerations = tolerations + + _, err = clusterClient.ClusterV1beta1().Placements(namespace).Update(context.Background(), placement, metav1.UpdateOptions{}) + return err + }, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred()) } func assertCreatingAddOnPlacementScores(clusternamespace, crname, scorename string, score int32) { diff --git a/test/integration/placement/placement_test.go b/test/integration/placement/placement_test.go index 67d9bb22e..4f2a098b5 100644 --- a/test/integration/placement/placement_test.go +++ b/test/integration/placement/placement_test.go @@ -3,9 +3,10 @@ package placement import ( "context" "fmt" - "open-cluster-management.io/ocm/test/integration/util" "time" + "open-cluster-management.io/ocm/test/integration/util" + "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" "github.com/openshift/library-go/pkg/controller/controllercmd" @@ -125,11 +126,7 @@ var _ = ginkgo.Describe("Placement", func() { assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 5, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) // update ClusterSets - placement, err := clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), placementName, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - placement.Spec.ClusterSets = []string{clusterSet1Name} - placement, err = clusterClient.ClusterV1beta1().Placements(namespace).Update(context.Background(), placement, metav1.UpdateOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + assertUpdatingPlacement(placementName, namespace, noc(10), []string{clusterSet1Name}, []clusterapiv1beta1.ClusterPredicate{}, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) assertNumberOfDecisions(placementName, namespace, 2) }) @@ -142,9 +139,7 @@ var _ = ginkgo.Describe("Placement", func() { ginkgo.By("add the predicates") // add a predicates - placement, err := clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), placementName, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - placement.Spec.Predicates = []clusterapiv1beta1.ClusterPredicate{ + predicates := []clusterapiv1beta1.ClusterPredicate{ { RequiredClusterSelector: clusterapiv1beta1.ClusterSelector{ LabelSelector: metav1.LabelSelector{ @@ -155,15 +150,12 @@ var _ = ginkgo.Describe("Placement", func() { }, }, } - placement, err = clusterClient.ClusterV1beta1().Placements(namespace).Update(context.Background(), placement, metav1.UpdateOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + assertUpdatingPlacement(placementName, namespace, noc(10), []string{}, predicates, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) assertNumberOfDecisions(placementName, namespace, 3) ginkgo.By("change the predicates") // change the predicates - placement, err = clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), placementName, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - placement.Spec.Predicates = []clusterapiv1beta1.ClusterPredicate{ + predicates = []clusterapiv1beta1.ClusterPredicate{ { RequiredClusterSelector: clusterapiv1beta1.ClusterSelector{ LabelSelector: metav1.LabelSelector{ @@ -174,8 +166,7 @@ var _ = ginkgo.Describe("Placement", func() { }, }, } - placement, err = clusterClient.ClusterV1beta1().Placements(namespace).Update(context.Background(), placement, metav1.UpdateOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + assertUpdatingPlacement(placementName, namespace, noc(10), []string{}, predicates, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) assertNumberOfDecisions(placementName, namespace, 2) }) @@ -187,9 +178,7 @@ var _ = ginkgo.Describe("Placement", func() { ginkgo.By("add the predicates") // add a predicates - placement, err := clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), placementName, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - placement.Spec.Predicates = []clusterapiv1beta1.ClusterPredicate{ + predicates := []clusterapiv1beta1.ClusterPredicate{ { RequiredClusterSelector: clusterapiv1beta1.ClusterSelector{ ClaimSelector: clusterapiv1beta1.ClusterClaimSelector{ @@ -204,15 +193,12 @@ var _ = ginkgo.Describe("Placement", func() { }, }, } - _, err = clusterClient.ClusterV1beta1().Placements(namespace).Update(context.Background(), placement, metav1.UpdateOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + assertUpdatingPlacement(placementName, namespace, noc(10), []string{}, predicates, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) assertNumberOfDecisions(placementName, namespace, 3) ginkgo.By("change the predicates") // change the predicates - placement, err = clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), placementName, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - placement.Spec.Predicates = []clusterapiv1beta1.ClusterPredicate{ + predicates = []clusterapiv1beta1.ClusterPredicate{ { RequiredClusterSelector: clusterapiv1beta1.ClusterSelector{ ClaimSelector: clusterapiv1beta1.ClusterClaimSelector{ @@ -227,8 +213,7 @@ var _ = ginkgo.Describe("Placement", func() { }, }, } - _, err = clusterClient.ClusterV1beta1().Placements(namespace).Update(context.Background(), placement, metav1.UpdateOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + assertUpdatingPlacement(placementName, namespace, noc(10), []string{}, predicates, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) assertNumberOfDecisions(placementName, namespace, 2) }) @@ -238,12 +223,8 @@ var _ = ginkgo.Describe("Placement", func() { assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 5, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) ginkgo.By("Reduce NOC of the placement") - placement, err := clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), placementName, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) noc := int32(4) - placement.Spec.NumberOfClusters = &noc - placement, err = clusterClient.ClusterV1beta1().Placements(namespace).Update(context.Background(), placement, metav1.UpdateOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + assertUpdatingPlacement(placementName, namespace, &noc, []string{}, []clusterapiv1beta1.ClusterPredicate{}, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) nod := int(noc) assertNumberOfDecisions(placementName, namespace, nod) @@ -256,12 +237,8 @@ var _ = ginkgo.Describe("Placement", func() { assertCreatingPlacementWithDecision(placementName, namespace, noc(5), 5, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) ginkgo.By("Increase NOC of the placement") - placement, err := clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), placementName, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) noc := int32(8) - placement.Spec.NumberOfClusters = &noc - placement, err = clusterClient.ClusterV1beta1().Placements(namespace).Update(context.Background(), placement, metav1.UpdateOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + assertUpdatingPlacement(placementName, namespace, &noc, []string{}, []clusterapiv1beta1.ClusterPredicate{}, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) nod := int(noc) assertNumberOfDecisions(placementName, namespace, nod) @@ -282,7 +259,7 @@ var _ = ginkgo.Describe("Placement", func() { assertNumberOfDecisions(placementName, namespace, 0) assertPlacementConditionMisconfigured(placementName, namespace, true) - assertUpdatingPlacement(placementName, namespace, noc(1), clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) + assertUpdatingPlacement(placementName, namespace, noc(1), []string{}, []clusterapiv1beta1.ClusterPredicate{}, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}) assertNumberOfDecisions(placementName, namespace, 1) assertPlacementConditionMisconfigured(placementName, namespace, false) assertPlacementConditionSatisfied(placementName, namespace, 1, true)