Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stabilize placement integration test #165

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 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,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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to put get in the eventually also

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) {
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