Skip to content

Commit

Permalink
stabilize placement integration test
Browse files Browse the repository at this point in the history
Signed-off-by: haoqing0110 <qhao@redhat.com>
  • Loading branch information
haoqing0110 committed Jun 5, 2023
1 parent 72d87a2 commit cc7f37d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 47 deletions.
29 changes: 19 additions & 10 deletions test/integration/placement/assertion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -410,16 +411,24 @@ 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())

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())
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.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{})
if err != nil {
return err
}
return nil
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())
}

func assertCreatingAddOnPlacementScores(clusternamespace, crname, scorename string, score int32) {
Expand Down
51 changes: 14 additions & 37 deletions test/integration/placement/placement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
})
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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)
})

Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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)
})

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit cc7f37d

Please sign in to comment.