update placement integration testing code with patcher (#217)

Signed-off-by: haoqing0110 <qhao@redhat.com>
This commit is contained in:
Qing Hao
2023-07-12 05:44:44 -04:00
committed by GitHub
parent 5db224052b
commit 320098e78a
4 changed files with 377 additions and 466 deletions
+158 -161
View File
@@ -20,53 +20,41 @@ import (
clusterapiv1beta1 "open-cluster-management.io/api/cluster/v1beta1"
clusterapiv1beta2 "open-cluster-management.io/api/cluster/v1beta2"
"open-cluster-management.io/ocm/pkg/common/patcher"
"open-cluster-management.io/ocm/test/integration/util"
)
func assertPlacementDecisionCreated(placement *clusterapiv1beta1.Placement) {
ginkgo.By("Check if placementdecision is created")
gomega.Eventually(func() bool {
pdl, err := clusterClient.ClusterV1beta1().PlacementDecisions(placement.Namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: placementLabel + "=" + placement.Name,
})
if err != nil {
return false
}
if len(pdl.Items) == 0 {
return false
}
for _, pd := range pdl.Items {
if controlled := metav1.IsControlledBy(&pd.ObjectMeta, placement); !controlled {
return false
}
}
return true
}, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue())
// assert placement
func assertCreatingPlacement(placement *clusterapiv1beta1.Placement) *clusterapiv1beta1.Placement {
ginkgo.By("Create placement")
newplacement, err := clusterClient.ClusterV1beta1().Placements(placement.Namespace).Create(context.Background(), placement, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return newplacement
}
func assertCreatingPlacementDecision(name, namespace string, clusterNames []string) {
ginkgo.By(fmt.Sprintf("Create placementdecision %s", name))
placementDecision := &clusterapiv1beta1.PlacementDecision{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
Labels: map[string]string{
placementLabel: name,
},
},
func assertCreatingPlacementWithDecision(placement *clusterapiv1beta1.Placement, numberOfDecisionClusters, numberOfPlacementDecisions int) {
newplacement := assertCreatingPlacement(placement)
assertPlacementDecisionCreated(newplacement)
assertPlacementDecisionNumbers(newplacement.Name, newplacement.Namespace, numberOfDecisionClusters, numberOfPlacementDecisions)
if placement.Spec.NumberOfClusters != nil {
assertPlacementConditionSatisfied(newplacement.Name, newplacement.Namespace, numberOfDecisionClusters, numberOfDecisionClusters == int(*placement.Spec.NumberOfClusters))
}
placementDecision, err := clusterClient.ClusterV1beta1().PlacementDecisions(namespace).Create(context.Background(), placementDecision, metav1.CreateOptions{})
}
var clusterDecisions []clusterapiv1beta1.ClusterDecision
for _, clusterName := range clusterNames {
clusterDecisions = append(clusterDecisions, clusterapiv1beta1.ClusterDecision{
ClusterName: clusterName,
})
}
func assertPatchingPlacementSpec(newPlacement *clusterapiv1beta1.Placement) {
ginkgo.By("Patching placement spec")
placementPatcher := patcher.NewPatcher[
*clusterapiv1beta1.Placement, clusterapiv1beta1.PlacementSpec, clusterapiv1beta1.PlacementStatus](
clusterClient.ClusterV1beta1().Placements(newPlacement.Namespace))
placementDecision.Status.Decisions = clusterDecisions
placementDecision, err = clusterClient.ClusterV1beta1().PlacementDecisions(namespace).UpdateStatus(context.Background(), placementDecision, metav1.UpdateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Eventually(func() error {
oldPlacement, err := clusterClient.ClusterV1beta1().Placements(newPlacement.Namespace).Get(context.Background(), newPlacement.Name, metav1.GetOptions{})
if err != nil {
return err
}
_, err = placementPatcher.PatchSpec(context.Background(), newPlacement, newPlacement.Spec, oldPlacement.Spec)
return err
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())
}
func assertPlacementDeleted(placementName, namespace string) {
@@ -80,52 +68,7 @@ func assertPlacementDeleted(placementName, namespace string) {
}, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue())
}
func assertNumberOfDecisions(placementName, namespace string, desiredNOD, desiredNOPD int) {
ginkgo.By("Check the number of decisions in placementdecisions")
gomega.Eventually(func() bool {
pdl, err := clusterClient.ClusterV1beta1().PlacementDecisions(namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: placementLabel + "=" + placementName,
})
if err != nil {
return false
}
if len(pdl.Items) != desiredNOPD {
return false
}
actualNOD := 0
for _, pd := range pdl.Items {
actualNOD += len(pd.Status.Decisions)
}
return actualNOD == desiredNOD
}, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue())
}
func assertClusterNamesOfDecisions(placementName, namespace string, desiredClusters []string) {
ginkgo.By(fmt.Sprintf("Check the cluster names of placementdecisions %s", placementName))
gomega.Eventually(func() bool {
pdl, err := clusterClient.ClusterV1beta1().PlacementDecisions(namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: placementLabel + "=" + placementName,
})
if err != nil {
return false
}
actualClusters := sets.NewString()
desiredClusters := sets.NewString(desiredClusters...)
for _, pd := range pdl.Items {
for _, d := range pd.Status.Decisions {
actualClusters.Insert(d.ClusterName)
}
}
if actualClusters.Equal(desiredClusters) {
return true
}
ginkgo.By(fmt.Sprintf("Expect %v, but got %v", desiredClusters.List(), actualClusters.List()))
return false
}, eventuallyTimeout*2, eventuallyInterval).Should(gomega.BeTrue())
}
func assertPlacementDecisionGroupStatus(placementName, namespace string, decisionGroupStatus []clusterapiv1beta1.DecisionGroupStatus) {
func assertPlacementStatusDecisionGroups(placementName, namespace string, decisionGroupStatus []clusterapiv1beta1.DecisionGroupStatus) {
ginkgo.By("Check the group status of placement")
gomega.Eventually(func() bool {
placement, err := clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), placementName, metav1.GetOptions{})
@@ -191,29 +134,99 @@ func assertPlacementConditionMisconfigured(placementName, namespace string, misC
}, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue())
}
func assertBindingClusterSet(clusterSetName, namespace string) {
ginkgo.By("Create clusterset/clustersetbinding")
clusterset := &clusterapiv1beta2.ManagedClusterSet{
ObjectMeta: metav1.ObjectMeta{
Name: clusterSetName,
},
}
_, err := clusterClient.ClusterV1beta2().ManagedClusterSets().Create(context.Background(), clusterset, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
csb := &clusterapiv1beta2.ManagedClusterSetBinding{
// assert placement decision
func assertCreatingPlacementDecision(name, namespace string, clusterNames []string) {
ginkgo.By(fmt.Sprintf("Create placementdecision %s", name))
placementDecision := &clusterapiv1beta1.PlacementDecision{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: clusterSetName,
},
Spec: clusterapiv1beta2.ManagedClusterSetBindingSpec{
ClusterSet: clusterSetName,
Name: name,
Labels: map[string]string{
placementLabel: name,
},
},
}
_, err = clusterClient.ClusterV1beta2().ManagedClusterSetBindings(namespace).Create(context.Background(), csb, metav1.CreateOptions{})
placementDecision, err := clusterClient.ClusterV1beta1().PlacementDecisions(namespace).Create(context.Background(), placementDecision, metav1.CreateOptions{})
var clusterDecisions []clusterapiv1beta1.ClusterDecision
for _, clusterName := range clusterNames {
clusterDecisions = append(clusterDecisions, clusterapiv1beta1.ClusterDecision{
ClusterName: clusterName,
})
}
placementDecision.Status.Decisions = clusterDecisions
placementDecision, err = clusterClient.ClusterV1beta1().PlacementDecisions(namespace).UpdateStatus(context.Background(), placementDecision, metav1.UpdateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}
func assertPlacementDecisionCreated(placement *clusterapiv1beta1.Placement) {
ginkgo.By("Check if placementdecision is created")
gomega.Eventually(func() bool {
pdl, err := clusterClient.ClusterV1beta1().PlacementDecisions(placement.Namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: placementLabel + "=" + placement.Name,
})
if err != nil {
return false
}
if len(pdl.Items) == 0 {
return false
}
for _, pd := range pdl.Items {
if controlled := metav1.IsControlledBy(&pd.ObjectMeta, placement); !controlled {
return false
}
}
return true
}, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue())
}
func assertPlacementDecisionNumbers(placementName, namespace string, desiredNumOfDecisionClusters, desiredNumOfDecisions int) {
ginkgo.By("Check the number of decisions in placementdecisions")
gomega.Eventually(func() bool {
pdl, err := clusterClient.ClusterV1beta1().PlacementDecisions(namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: placementLabel + "=" + placementName,
})
if err != nil {
return false
}
if len(pdl.Items) != desiredNumOfDecisions {
return false
}
actualNumOfDecisionClusters := 0
for _, pd := range pdl.Items {
actualNumOfDecisionClusters += len(pd.Status.Decisions)
}
return actualNumOfDecisionClusters == desiredNumOfDecisionClusters
}, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue())
}
func assertPlacementDecisionClusterNames(placementName, namespace string, desiredClusters []string) {
ginkgo.By(fmt.Sprintf("Check the cluster names of placementdecisions %s", placementName))
gomega.Eventually(func() bool {
pdl, err := clusterClient.ClusterV1beta1().PlacementDecisions(namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: placementLabel + "=" + placementName,
})
if err != nil {
return false
}
actualClusters := sets.NewString()
desiredClusters := sets.NewString(desiredClusters...)
for _, pd := range pdl.Items {
for _, d := range pd.Status.Decisions {
actualClusters.Insert(d.ClusterName)
}
}
if actualClusters.Equal(desiredClusters) {
return true
}
ginkgo.By(fmt.Sprintf("Expect %v, but got %v", desiredClusters.List(), actualClusters.List()))
return false
}, eventuallyTimeout*2, eventuallyInterval).Should(gomega.BeTrue())
}
// assert clusterset
func assertCreatingClusterSet(clusterSetName string, labels ...string) {
ginkgo.By(fmt.Sprintf("Create clusterset %s", clusterSetName))
clusterset := &clusterapiv1beta2.ManagedClusterSet{
@@ -241,6 +254,29 @@ func assertCreatingClusterSet(clusterSetName string, labels ...string) {
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}
func assertBindingClusterSet(clusterSetName, namespace string) {
ginkgo.By("Create clusterset/clustersetbinding")
clusterset := &clusterapiv1beta2.ManagedClusterSet{
ObjectMeta: metav1.ObjectMeta{
Name: clusterSetName,
},
}
_, err := clusterClient.ClusterV1beta2().ManagedClusterSets().Create(context.Background(), clusterset, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
csb := &clusterapiv1beta2.ManagedClusterSetBinding{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: clusterSetName,
},
Spec: clusterapiv1beta2.ManagedClusterSetBindingSpec{
ClusterSet: clusterSetName,
},
}
_, err = clusterClient.ClusterV1beta2().ManagedClusterSetBindings(namespace).Create(context.Background(), csb, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}
func assertDeletingClusterSet(clusterSetName string) {
ginkgo.By(fmt.Sprintf("Delete clusterset %s", clusterSetName))
err := clusterClient.ClusterV1beta2().ManagedClusterSets().Delete(context.Background(), clusterSetName, metav1.DeleteOptions{})
@@ -286,6 +322,7 @@ func assertDeletingClusterSetBinding(clusterSetName, namespace string) {
}, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue())
}
// assert clusters
func assertCreatingClusters(clusterSetName string, num int, labels ...string) []string {
ginkgo.By(fmt.Sprintf("Create %d clusters", num))
@@ -336,10 +373,10 @@ func assertCleanupClusters() []string {
return clusterNames
}
func assertUpdatingClusterWithClusterResources(managedClusterName string, res []string) {
func assertPatchingClusterStatusWithResources(managedClusterName string, res []string) {
ginkgo.By(fmt.Sprintf("Updating ManagedClusters %s cluster resources", managedClusterName))
mc, err := clusterClient.ClusterV1().ManagedClusters().Get(context.Background(), managedClusterName, metav1.GetOptions{})
oldmc, err := clusterClient.ClusterV1().ManagedClusters().Get(context.Background(), managedClusterName, metav1.GetOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
allocatable := map[clusterapiv1.ResourceName]resource.Quantity{}
@@ -354,27 +391,35 @@ func assertUpdatingClusterWithClusterResources(managedClusterName string, res []
capacity[clusterapiv1.ResourceMemory], err = resource.ParseQuantity(res[3])
gomega.Expect(err).ToNot(gomega.HaveOccurred())
mc.Status = clusterapiv1.ManagedClusterStatus{
Allocatable: allocatable,
Capacity: capacity,
Conditions: []metav1.Condition{},
}
_, err = clusterClient.ClusterV1().ManagedClusters().UpdateStatus(context.Background(), mc, metav1.UpdateOptions{})
newmc := oldmc.DeepCopy()
newmc.Status.Allocatable = allocatable
newmc.Status.Capacity = capacity
managedClusterPatcher := patcher.NewPatcher[
*clusterapiv1.ManagedCluster, clusterapiv1.ManagedClusterSpec, clusterapiv1.ManagedClusterStatus](
clusterClient.ClusterV1().ManagedClusters())
_, err = managedClusterPatcher.PatchStatus(context.Background(), newmc, newmc.Status, oldmc.Status)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}
func assertUpdatingClusterWithClusterTaint(managedClusterName string, taint *clusterapiv1.Taint) {
func assertPatchingClusterSpecWithTaint(managedClusterName string, taint *clusterapiv1.Taint) {
ginkgo.By(fmt.Sprintf("Updating ManagedClusters %s taint", managedClusterName))
if taint == nil {
return
}
mc, err := clusterClient.ClusterV1().ManagedClusters().Get(context.Background(), managedClusterName, metav1.GetOptions{})
oldmc, err := clusterClient.ClusterV1().ManagedClusters().Get(context.Background(), managedClusterName, metav1.GetOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
mc.Spec.Taints = append(mc.Spec.Taints, *taint)
newmc := oldmc.DeepCopy()
newmc.Spec.Taints = append(newmc.Spec.Taints, *taint)
_, err = clusterClient.ClusterV1().ManagedClusters().Update(context.Background(), mc, metav1.UpdateOptions{})
managedClusterPatcher := patcher.NewPatcher[
*clusterapiv1.ManagedCluster, clusterapiv1.ManagedClusterSpec, clusterapiv1.ManagedClusterStatus](
clusterClient.ClusterV1().ManagedClusters())
_, err = managedClusterPatcher.PatchSpec(context.Background(), newmc, newmc.Spec, oldmc.Spec)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}
@@ -395,54 +440,6 @@ func assertDeletingClusters(clusterNames ...string) {
}
}
func assertCreatingPlacement(name, namespace string, noc *int32, prioritizerPolicy clusterapiv1beta1.PrioritizerPolicy, tolerations []clusterapiv1beta1.Toleration, groupStrategy clusterapiv1beta1.GroupStrategy) *clusterapiv1beta1.Placement {
ginkgo.By("Create placement")
placement := &clusterapiv1beta1.Placement{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
Spec: clusterapiv1beta1.PlacementSpec{
NumberOfClusters: noc,
PrioritizerPolicy: prioritizerPolicy,
Tolerations: tolerations,
DecisionStrategy: clusterapiv1beta1.DecisionStrategy{GroupStrategy: groupStrategy},
},
}
placement, err := clusterClient.ClusterV1beta1().Placements(namespace).Create(context.Background(), placement, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return placement
}
func assertCreatingPlacementWithDecision(name, namespace string, numberOfClusters *int32, numberOfDecisionClusters, numberOfPlacementDecisions int, prioritizerPolicy clusterapiv1beta1.PrioritizerPolicy, tolerations []clusterapiv1beta1.Toleration, groupStrategy clusterapiv1beta1.GroupStrategy) {
placement := assertCreatingPlacement(name, namespace, numberOfClusters, prioritizerPolicy, tolerations, groupStrategy)
assertPlacementDecisionCreated(placement)
assertNumberOfDecisions(name, namespace, numberOfDecisionClusters, numberOfPlacementDecisions)
if numberOfClusters != nil {
assertPlacementConditionSatisfied(name, namespace, numberOfDecisionClusters, numberOfDecisionClusters == int(*numberOfClusters))
}
}
func assertUpdatingPlacement(name, namespace string, noc *int32, clusterSet []string, predicate []clusterapiv1beta1.ClusterPredicate, prioritizerPolicy clusterapiv1beta1.PrioritizerPolicy, tolerations []clusterapiv1beta1.Toleration) {
ginkgo.By("Updating placement")
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{})
return err
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())
}
func assertCreatingAddOnPlacementScores(clusternamespace, crname, scorename string, score int32) {
ginkgo.By(fmt.Sprintf("Create namespace %s for addonplacementscores %s", clusternamespace, crname))
if _, err := kubeClient.CoreV1().Namespaces().Get(context.Background(), clusternamespace, metav1.GetOptions{}); err != nil {
+112 -90
View File
@@ -17,6 +17,7 @@ import (
controllers "open-cluster-management.io/ocm/pkg/placement/controllers"
"open-cluster-management.io/ocm/pkg/placement/controllers/scheduling"
testinghelpers "open-cluster-management.io/ocm/pkg/placement/helpers/testing"
"open-cluster-management.io/ocm/test/integration/util"
)
@@ -84,7 +85,8 @@ var _ = ginkgo.Describe("Placement", func() {
ginkgo.It("Should re-create placementdecisions successfully once placementdecisions are deleted", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
assertCreatingClusters(clusterSet1Name, 5)
assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 5, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(10).Build()
assertCreatingPlacementWithDecision(placement, 5, 1)
ginkgo.By("Delete placementdecisions")
placementDecisions, err := clusterClient.ClusterV1beta1().PlacementDecisions(namespace).List(context.Background(), metav1.ListOptions{
@@ -97,28 +99,28 @@ var _ = ginkgo.Describe("Placement", func() {
}
// check if the placementdecisions are re-created
placement, err := clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), placementName, metav1.GetOptions{})
placement, err = clusterClient.ClusterV1beta1().Placements(namespace).Get(context.Background(), placementName, metav1.GetOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
assertPlacementDecisionCreated(placement)
assertNumberOfDecisions(placementName, namespace, 5, 1)
assertPlacementDecisionGroupStatus(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{{Decisions: []string{placementName + "-decision-0"}, ClustersCount: 5}})
assertPlacementDecisionNumbers(placementName, namespace, 5, 1)
assertPlacementStatusDecisionGroups(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{{Decisions: []string{placementName + "-decision-0"}, ClustersCount: 5}})
})
ginkgo.It("Should create empty placementdecision when no cluster selected", func() {
placement := assertCreatingPlacement(placementName, namespace, nil, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
assertPlacementDecisionCreated(placement)
assertNumberOfDecisions(placementName, namespace, 0, 1)
assertPlacementDecisionGroupStatus(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{{Decisions: []string{placementName + "-decision-0"}, ClustersCount: 0}})
placement := testinghelpers.NewPlacement(namespace, placementName).Build()
assertCreatingPlacementWithDecision(placement, 0, 1)
assertPlacementStatusDecisionGroups(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{{Decisions: []string{placementName + "-decision-0"}, ClustersCount: 0}})
})
ginkgo.It("Should create multiple placementdecisions once scheduled", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
assertCreatingClusters(clusterSet1Name, 101)
assertCreatingPlacementWithDecision(placementName, namespace, nil, 101, 2, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).Build()
assertCreatingPlacementWithDecision(placement, 101, 2)
nod := 101
assertNumberOfDecisions(placementName, namespace, nod, 2)
assertPlacementDecisionGroupStatus(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{{Decisions: []string{placementName + "-decision-0", placementName + "-decision-1"}, ClustersCount: 101}})
assertPlacementDecisionNumbers(placementName, namespace, nod, 2)
assertPlacementStatusDecisionGroups(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{{Decisions: []string{placementName + "-decision-0", placementName + "-decision-1"}, ClustersCount: 101}})
assertPlacementConditionSatisfied(placementName, namespace, nod, true)
})
@@ -127,19 +129,21 @@ var _ = ginkgo.Describe("Placement", func() {
assertBindingClusterSet(clusterSet2Name, namespace)
assertCreatingClusters(clusterSet1Name, 2)
assertCreatingClusters(clusterSet2Name, 3)
assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 5, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(10).Build()
assertCreatingPlacementWithDecision(placement, 5, 1)
// update ClusterSets
assertUpdatingPlacement(placementName, namespace, noc(10), []string{clusterSet1Name}, []clusterapiv1beta1.ClusterPredicate{}, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{})
assertNumberOfDecisions(placementName, namespace, 2, 1)
placement.Spec.ClusterSets = []string{clusterSet1Name}
assertPatchingPlacementSpec(placement)
assertPlacementDecisionNumbers(placementName, namespace, 2, 1)
})
ginkgo.It("Should schedule placement successfully once spec.Predicates LabelSelector changes", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
assertCreatingClusters(clusterSet1Name, 2, "cloud", "Azure")
assertCreatingClusters(clusterSet1Name, 3, "cloud", "Amazon")
assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 5, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(10).Build()
assertCreatingPlacementWithDecision(placement, 5, 1)
ginkgo.By("add the predicates")
// add a predicates
@@ -154,9 +158,10 @@ var _ = ginkgo.Describe("Placement", func() {
},
},
}
assertUpdatingPlacement(placementName, namespace, noc(10), []string{}, predicates, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{})
assertNumberOfDecisions(placementName, namespace, 3, 1)
assertPlacementDecisionGroupStatus(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{{Decisions: []string{placementName + "-decision-0"}, ClustersCount: 3}})
placement.Spec.Predicates = predicates
assertPatchingPlacementSpec(placement)
assertPlacementDecisionNumbers(placementName, namespace, 3, 1)
assertPlacementStatusDecisionGroups(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{{Decisions: []string{placementName + "-decision-0"}, ClustersCount: 3}})
ginkgo.By("change the predicates")
// change the predicates
@@ -171,15 +176,18 @@ var _ = ginkgo.Describe("Placement", func() {
},
},
}
assertUpdatingPlacement(placementName, namespace, noc(10), []string{}, predicates, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{})
assertNumberOfDecisions(placementName, namespace, 2, 1)
placement.Spec.Predicates = predicates
assertPatchingPlacementSpec(placement)
assertPlacementDecisionNumbers(placementName, namespace, 2, 1)
})
ginkgo.It("Should schedule placement successfully once spec.Predicates ClaimSelector changes", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
assertCreatingClusters(clusterSet1Name, 2, "cloud", "Azure")
assertCreatingClusters(clusterSet1Name, 3, "cloud", "Amazon")
assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 5, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(10).Build()
assertCreatingPlacementWithDecision(placement, 5, 1)
ginkgo.By("add the predicates")
// add a predicates
predicates := []clusterapiv1beta1.ClusterPredicate{
@@ -197,8 +205,9 @@ var _ = ginkgo.Describe("Placement", func() {
},
},
}
assertUpdatingPlacement(placementName, namespace, noc(10), []string{}, predicates, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{})
assertNumberOfDecisions(placementName, namespace, 3, 1)
placement.Spec.Predicates = predicates
assertPatchingPlacementSpec(placement)
assertPlacementDecisionNumbers(placementName, namespace, 3, 1)
ginkgo.By("change the predicates")
// change the predicates
@@ -217,34 +226,40 @@ var _ = ginkgo.Describe("Placement", func() {
},
},
}
assertUpdatingPlacement(placementName, namespace, noc(10), []string{}, predicates, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{})
assertNumberOfDecisions(placementName, namespace, 2, 1)
placement.Spec.Predicates = predicates
assertPatchingPlacementSpec(placement)
assertPlacementDecisionNumbers(placementName, namespace, 2, 1)
})
ginkgo.It("Should schedule successfully once spec.NumberOfClusters is reduced", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
assertCreatingClusters(clusterSet1Name, 5)
assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 5, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(10).Build()
assertCreatingPlacementWithDecision(placement, 5, 1)
ginkgo.By("Reduce NOC of the placement")
noc := int32(4)
assertUpdatingPlacement(placementName, namespace, &noc, []string{}, []clusterapiv1beta1.ClusterPredicate{}, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{})
placement.Spec.NumberOfClusters = &noc
assertPatchingPlacementSpec(placement)
nod := int(noc)
assertNumberOfDecisions(placementName, namespace, nod, 1)
assertPlacementDecisionNumbers(placementName, namespace, nod, 1)
assertPlacementConditionSatisfied(placementName, namespace, nod, true)
})
ginkgo.It("Should schedule successfully once spec.NumberOfClusters is increased", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
assertCreatingClusters(clusterSet1Name, 10)
assertCreatingPlacementWithDecision(placementName, namespace, noc(5), 5, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(5).Build()
assertCreatingPlacementWithDecision(placement, 5, 1)
ginkgo.By("Increase NOC of the placement")
noc := int32(8)
assertUpdatingPlacement(placementName, namespace, &noc, []string{}, []clusterapiv1beta1.ClusterPredicate{}, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{})
placement.Spec.NumberOfClusters = &noc
assertPatchingPlacementSpec(placement)
nod := int(noc)
assertNumberOfDecisions(placementName, namespace, nod, 1)
assertPlacementDecisionNumbers(placementName, namespace, nod, 1)
assertPlacementConditionSatisfied(placementName, namespace, nod, true)
})
@@ -252,18 +267,18 @@ var _ = ginkgo.Describe("Placement", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
assertCreatingClusters(clusterSet1Name, 1)
assertCreatingPlacement(placementName, namespace, noc(1), clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{
{
Key: "key1",
Operator: clusterapiv1beta1.TolerationOpExists,
Value: "value1",
},
}, clusterapiv1beta1.GroupStrategy{})
assertNumberOfDecisions(placementName, namespace, 0, 1)
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(1).AddToleration(&clusterapiv1beta1.Toleration{
Key: "key1",
Operator: clusterapiv1beta1.TolerationOpExists,
Value: "value1",
}).Build()
assertCreatingPlacement(placement)
assertPlacementDecisionNumbers(placementName, namespace, 0, 1)
assertPlacementConditionMisconfigured(placementName, namespace, true)
assertUpdatingPlacement(placementName, namespace, noc(1), []string{}, []clusterapiv1beta1.ClusterPredicate{}, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{})
assertNumberOfDecisions(placementName, namespace, 1, 1)
placement.Spec.Tolerations = []clusterapiv1beta1.Toleration{}
assertPatchingPlacementSpec(placement)
assertPlacementDecisionNumbers(placementName, namespace, 1, 1)
assertPlacementConditionMisconfigured(placementName, namespace, false)
assertPlacementConditionSatisfied(placementName, namespace, 1, true)
})
@@ -271,14 +286,15 @@ var _ = ginkgo.Describe("Placement", func() {
ginkgo.It("Should be satisfied once new clusters are added", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
assertCreatingClusters(clusterSet1Name, 5)
assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 5, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(10).Build()
assertCreatingPlacementWithDecision(placement, 5, 1)
// add more clusters
ginkgo.By("Add the cluster")
assertCreatingClusters(clusterSet1Name, 5)
nod := 10
assertNumberOfDecisions(placementName, namespace, nod, 1)
assertPlacementDecisionNumbers(placementName, namespace, nod, 1)
assertPlacementConditionSatisfied(placementName, namespace, nod, true)
})
@@ -287,21 +303,22 @@ var _ = ginkgo.Describe("Placement", func() {
assertCreatingClusterSet(clusterSet1Name, "vendor", "openShift")
assertCreatingClusterSetBinding(clusterSet1Name, namespace)
clusters1 := assertCreatingClusters(clusterName+"1", 1, "vendor", "openShift")
assertCreatingPlacementWithDecision(placementName, namespace, noc(2), 1, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(2).Build()
assertCreatingPlacementWithDecision(placement, 1, 1)
// add more clusters
ginkgo.By("Add the cluster")
clusters2 := assertCreatingClusters(clusterName+"2", 1, "vendor", "openShift")
assertNumberOfDecisions(placementName, namespace, 2, 1)
assertPlacementDecisionNumbers(placementName, namespace, 2, 1)
assertPlacementConditionSatisfied(placementName, namespace, 2, true)
ginkgo.By("Delete the cluster")
assertDeletingClusters(clusters1...)
assertNumberOfDecisions(placementName, namespace, 1, 1)
assertPlacementDecisionNumbers(placementName, namespace, 1, 1)
assertDeletingClusters(clusters2...)
assertNumberOfDecisions(placementName, namespace, 0, 1)
assertPlacementDecisionNumbers(placementName, namespace, 0, 1)
})
ginkgo.It("Should update the decision group once clusters added/deleted", func() {
@@ -311,24 +328,23 @@ var _ = ginkgo.Describe("Placement", func() {
canary := assertCreatingClusters(clusterSet1Name, 3, "vendor", "openShift")
noncanary := assertCreatingClusters(clusterSet1Name, 3)
assertCreatingPlacementWithDecision(placementName, namespace, nil, 6, 3,
clusterapiv1beta1.PrioritizerPolicy{},
[]clusterapiv1beta1.Toleration{},
clusterapiv1beta1.GroupStrategy{
ClustersPerDecisionGroup: intstr.FromInt(2),
DecisionGroups: []clusterapiv1beta1.DecisionGroup{
{
GroupName: "canary",
ClusterSelector: clusterapiv1beta1.ClusterSelector{
LabelSelector: metav1.LabelSelector{MatchLabels: map[string]string{"vendor": "openShift"}},
},
placement := testinghelpers.NewPlacement(namespace, placementName).WithGroupStrategy(clusterapiv1beta1.GroupStrategy{
ClustersPerDecisionGroup: intstr.FromInt(2),
DecisionGroups: []clusterapiv1beta1.DecisionGroup{
{
GroupName: "canary",
ClusterSelector: clusterapiv1beta1.ClusterSelector{
LabelSelector: metav1.LabelSelector{MatchLabels: map[string]string{"vendor": "openShift"}},
},
},
})
},
}).Build()
assertCreatingPlacementWithDecision(placement, 6, 3)
assertNumberOfDecisions(placementName, namespace, 6, 3)
assertPlacementDecisionNumbers(placementName, namespace, 6, 3)
assertPlacementConditionSatisfied(placementName, namespace, 6, true)
assertPlacementDecisionGroupStatus(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{
assertPlacementStatusDecisionGroups(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{
{
DecisionGroupIndex: 0,
DecisionGroupName: "canary",
@@ -349,7 +365,7 @@ var _ = ginkgo.Describe("Placement", func() {
ginkgo.By("Delete the cluster")
assertDeletingClusters(canary[0], noncanary[0])
assertPlacementDecisionGroupStatus(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{
assertPlacementStatusDecisionGroups(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{
{
DecisionGroupIndex: 0,
DecisionGroupName: "canary",
@@ -366,8 +382,8 @@ var _ = ginkgo.Describe("Placement", func() {
ginkgo.By("Add the canary cluster")
c := assertCreatingClusters(clusterSet1Name, 1, "vendor", "openShift")
canary = append(canary, c...)
assertNumberOfDecisions(placementName, namespace, 5, 2)
assertPlacementDecisionGroupStatus(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{
assertPlacementDecisionNumbers(placementName, namespace, 5, 2)
assertPlacementStatusDecisionGroups(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{
{
DecisionGroupIndex: 0,
DecisionGroupName: "canary",
@@ -383,8 +399,8 @@ var _ = ginkgo.Describe("Placement", func() {
ginkgo.By("Add the non canary cluster")
c = assertCreatingClusters(clusterSet1Name, 1)
noncanary = append(noncanary, c...)
assertNumberOfDecisions(placementName, namespace, 6, 3)
assertPlacementDecisionGroupStatus(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{
assertPlacementDecisionNumbers(placementName, namespace, 6, 3)
assertPlacementStatusDecisionGroups(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{
{
DecisionGroupIndex: 0,
DecisionGroupName: "canary",
@@ -407,8 +423,8 @@ var _ = ginkgo.Describe("Placement", func() {
assertDeletingClusters(canary[1:]...)
assertDeletingClusters(noncanary[1:]...)
assertDeletingClusterSet("global")
assertNumberOfDecisions(placementName, namespace, 0, 1)
assertPlacementDecisionGroupStatus(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{{Decisions: []string{placementName + "-decision-0"}, ClustersCount: 0}})
assertPlacementDecisionNumbers(placementName, namespace, 0, 1)
assertPlacementStatusDecisionGroups(placementName, namespace, []clusterapiv1beta1.DecisionGroupStatus{{Decisions: []string{placementName + "-decision-0"}, ClustersCount: 0}})
})
@@ -417,33 +433,35 @@ var _ = ginkgo.Describe("Placement", func() {
assertCreatingClusterSet("global")
assertCreatingClusterSetBinding("global", namespace)
clusters1 := assertCreatingClusters(clusterName+"1", 1)
assertCreatingPlacementWithDecision(placementName, namespace, noc(2), 1, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(2).Build()
assertCreatingPlacementWithDecision(placement, 1, 1)
ginkgo.By("Add the cluster")
clusters2 := assertCreatingClusters(clusterName+"2", 1)
assertNumberOfDecisions(placementName, namespace, 2, 1)
assertPlacementDecisionNumbers(placementName, namespace, 2, 1)
assertPlacementConditionSatisfied(placementName, namespace, 2, true)
ginkgo.By("Delete the cluster")
assertDeletingClusters(clusters1...)
assertNumberOfDecisions(placementName, namespace, 1, 1)
assertPlacementDecisionNumbers(placementName, namespace, 1, 1)
assertDeletingClusters(clusters2...)
assertNumberOfDecisions(placementName, namespace, 0, 1)
assertPlacementDecisionNumbers(placementName, namespace, 0, 1)
})
ginkgo.It("Should schedule successfully once new clusterset is bound", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
assertCreatingClusters(clusterSet1Name, 5)
assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 5, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(10).Build()
assertCreatingPlacementWithDecision(placement, 5, 1)
ginkgo.By("Bind one more clusterset to the placement namespace")
assertBindingClusterSet(clusterSet2Name, namespace)
assertCreatingClusters(clusterSet2Name, 3)
nod := 8
assertNumberOfDecisions(placementName, namespace, nod, 1)
assertPlacementDecisionNumbers(placementName, namespace, nod, 1)
assertPlacementConditionSatisfied(placementName, namespace, nod, false)
})
@@ -452,7 +470,8 @@ var _ = ginkgo.Describe("Placement", func() {
assertCreatingClusterSet(clusterSet1Name, "vendor", "openShift")
assertCreatingClusterSetBinding(clusterSet1Name, namespace)
clusters1 := assertCreatingClusters(clusterName+"1", 1, "vendor", "openShift")
assertCreatingPlacementWithDecision(placementName, namespace, noc(2), 1, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(2).Build()
assertCreatingPlacementWithDecision(placement, 1, 1)
ginkgo.By("Bind one more labelselector clusterset to the placement namespace")
assertCreatingClusterSet(clusterSet2Name, "vendor", "IKS")
@@ -460,7 +479,7 @@ var _ = ginkgo.Describe("Placement", func() {
clusters2 := assertCreatingClusters(clusterName+"2", 1, "vendor", "IKS")
nod := 2
assertNumberOfDecisions(placementName, namespace, nod, 1)
assertPlacementDecisionNumbers(placementName, namespace, nod, 1)
assertPlacementConditionSatisfied(placementName, namespace, nod, true)
assertDeletingClusters(clusters1[0], clusters2[0])
@@ -469,19 +488,20 @@ var _ = ginkgo.Describe("Placement", func() {
ginkgo.It("Should schedule successfully once a clusterset deleted/added", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
assertCreatingClusters(clusterSet1Name, 5)
assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 5, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(10).Build()
assertCreatingPlacementWithDecision(placement, 5, 1)
assertNumberOfDecisions(placementName, namespace, 5, 1)
assertPlacementDecisionNumbers(placementName, namespace, 5, 1)
assertPlacementConditionSatisfied(placementName, namespace, 5, false)
ginkgo.By("Delete the clusterset")
assertDeletingClusterSet(clusterSet1Name)
assertNumberOfDecisions(placementName, namespace, 0, 1)
assertPlacementDecisionNumbers(placementName, namespace, 0, 1)
ginkgo.By("Add the clusterset back")
assertCreatingClusterSet(clusterSet1Name)
assertNumberOfDecisions(placementName, namespace, 5, 1)
assertPlacementDecisionNumbers(placementName, namespace, 5, 1)
assertPlacementConditionSatisfied(placementName, namespace, 5, false)
})
@@ -490,24 +510,25 @@ var _ = ginkgo.Describe("Placement", func() {
assertCreatingClusterSetBinding(clusterSet1Name, namespace)
clusters1 := assertCreatingClusters(clusterName+"1", 1, "vendor", "openShift")
clusters2 := assertCreatingClusters(clusterName+"2", 1, "vendor", "IKS")
assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 1, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(10).Build()
assertCreatingPlacementWithDecision(placement, 1, 1)
assertNumberOfDecisions(placementName, namespace, 1, 1)
assertPlacementDecisionNumbers(placementName, namespace, 1, 1)
assertPlacementConditionSatisfied(placementName, namespace, 1, false)
ginkgo.By("Delete the clusterset")
assertDeletingClusterSet(clusterSet1Name)
assertNumberOfDecisions(placementName, namespace, 0, 1)
assertPlacementDecisionNumbers(placementName, namespace, 0, 1)
ginkgo.By("Add the clusterset back")
assertCreatingClusterSet(clusterSet1Name, "vendor", "openShift")
assertNumberOfDecisions(placementName, namespace, 1, 1)
assertPlacementDecisionNumbers(placementName, namespace, 1, 1)
assertPlacementConditionSatisfied(placementName, namespace, 1, false)
ginkgo.By("Delete the cluster")
assertDeletingClusters(clusters1...)
assertNumberOfDecisions(placementName, namespace, 0, 1)
assertPlacementDecisionNumbers(placementName, namespace, 0, 1)
assertDeletingClusters(clusters2...)
})
@@ -515,19 +536,20 @@ var _ = ginkgo.Describe("Placement", func() {
ginkgo.It("Should schedule successfully once a clustersetbinding deleted/added", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
assertCreatingClusters(clusterSet1Name, 5)
assertCreatingPlacementWithDecision(placementName, namespace, noc(10), 5, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
assertNumberOfDecisions(placementName, namespace, 5, 1)
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(10).Build()
assertCreatingPlacementWithDecision(placement, 5, 1)
assertPlacementDecisionNumbers(placementName, namespace, 5, 1)
assertPlacementConditionSatisfied(placementName, namespace, 5, false)
ginkgo.By("Delete the clustersetbinding")
assertDeletingClusterSetBinding(clusterSet1Name, namespace)
assertNumberOfDecisions(placementName, namespace, 0, 1)
assertPlacementDecisionNumbers(placementName, namespace, 0, 1)
ginkgo.By("Add the clustersetbinding back")
assertCreatingClusterSetBinding(clusterSet1Name, namespace)
assertNumberOfDecisions(placementName, namespace, 5, 1)
assertPlacementDecisionNumbers(placementName, namespace, 5, 1)
assertPlacementConditionSatisfied(placementName, namespace, 5, false)
})
+51 -152
View File
@@ -16,6 +16,7 @@ import (
controllers "open-cluster-management.io/ocm/pkg/placement/controllers"
"open-cluster-management.io/ocm/pkg/placement/controllers/scheduling"
testinghelpers "open-cluster-management.io/ocm/pkg/placement/helpers/testing"
"open-cluster-management.io/ocm/test/integration/util"
)
@@ -68,19 +69,17 @@ var _ = ginkgo.Describe("Prioritizers", func() {
clusterResources[1] = []string{"7", "10", "90", "100"}
clusterResources[2] = []string{"9", "10", "80", "100"}
// placement settings
prioritizerPolicy := clusterapiv1beta1.PrioritizerPolicy{}
//Creating the clusters with resources
assertBindingClusterSet(clusterSet1Name, namespace)
clusterNames := assertCreatingClusters(clusterSet1Name, 3)
for i, name := range clusterNames {
assertUpdatingClusterWithClusterResources(name, clusterResources[i])
assertPatchingClusterStatusWithResources(name, clusterResources[i])
}
//Checking the result of the placement
assertCreatingPlacementWithDecision(placementName, namespace, noc(2), 2, 1, prioritizerPolicy, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[0], clusterNames[1]})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(2).Build()
assertCreatingPlacementWithDecision(placement, 2, 1)
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[0], clusterNames[1]})
})
ginkgo.It("Should schedule successfully based on SchedulePolicy ResourceAllocatableCPU & ResourceAllocatableMemory", func() {
@@ -90,37 +89,20 @@ var _ = ginkgo.Describe("Prioritizers", func() {
clusterResources[1] = []string{"7", "10", "90", "100"}
clusterResources[2] = []string{"9", "10", "80", "100"}
// placement settings
prioritizerPolicy := clusterapiv1beta1.PrioritizerPolicy{
Mode: clusterapiv1beta1.PrioritizerPolicyModeExact,
Configurations: []clusterapiv1beta1.PrioritizerConfig{
{
ScoreCoordinate: &clusterapiv1beta1.ScoreCoordinate{
Type: clusterapiv1beta1.ScoreCoordinateTypeBuiltIn,
BuiltIn: "ResourceAllocatableCPU",
},
Weight: 1,
},
{
ScoreCoordinate: &clusterapiv1beta1.ScoreCoordinate{
Type: clusterapiv1beta1.ScoreCoordinateTypeBuiltIn,
BuiltIn: "ResourceAllocatableMemory",
},
Weight: 1,
},
},
}
//Creating the clusters with resources
assertBindingClusterSet(clusterSet1Name, namespace)
clusterNames := assertCreatingClusters(clusterSet1Name, 3)
for i, name := range clusterNames {
assertUpdatingClusterWithClusterResources(name, clusterResources[i])
assertPatchingClusterStatusWithResources(name, clusterResources[i])
}
//Checking the result of the placement
assertCreatingPlacementWithDecision(placementName, namespace, noc(2), 2, 1, prioritizerPolicy, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(2).
WithPrioritizerPolicy(clusterapiv1beta1.PrioritizerPolicyModeExact).
WithPrioritizerConfig("ResourceAllocatableCPU", 1).
WithPrioritizerConfig("ResourceAllocatableMemory", 1).Build()
assertCreatingPlacementWithDecision(placement, 2, 1)
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
})
@@ -131,43 +113,21 @@ var _ = ginkgo.Describe("Prioritizers", func() {
clusterResources[1] = []string{"7", "10", "90", "100"}
clusterResources[2] = []string{"9", "10", "80", "100"}
// placement settings
prioritizerPolicy := clusterapiv1beta1.PrioritizerPolicy{
Mode: clusterapiv1beta1.PrioritizerPolicyModeAdditive,
Configurations: []clusterapiv1beta1.PrioritizerConfig{
{
ScoreCoordinate: &clusterapiv1beta1.ScoreCoordinate{
Type: clusterapiv1beta1.ScoreCoordinateTypeBuiltIn,
BuiltIn: "Steady",
},
Weight: 3,
},
{
ScoreCoordinate: &clusterapiv1beta1.ScoreCoordinate{
Type: clusterapiv1beta1.ScoreCoordinateTypeBuiltIn,
BuiltIn: "ResourceAllocatableCPU",
},
Weight: 1,
},
{
ScoreCoordinate: &clusterapiv1beta1.ScoreCoordinate{
Type: clusterapiv1beta1.ScoreCoordinateTypeBuiltIn,
BuiltIn: "ResourceAllocatableMemory",
},
Weight: 1,
},
},
}
//Creating the clusters with resources
assertBindingClusterSet(clusterSet1Name, namespace)
clusterNames := assertCreatingClusters(clusterSet1Name, 3)
for i, name := range clusterNames {
assertUpdatingClusterWithClusterResources(name, clusterResources[i])
assertPatchingClusterStatusWithResources(name, clusterResources[i])
}
//Checking the result of the placement
assertCreatingPlacementWithDecision(placementName, namespace, noc(2), 2, 1, prioritizerPolicy, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(2).
WithPrioritizerPolicy(clusterapiv1beta1.PrioritizerPolicyModeAdditive).
WithPrioritizerConfig("Steady", 3).
WithPrioritizerConfig("ResourceAllocatableCPU", 1).
WithPrioritizerConfig("ResourceAllocatableMemory", 1).Build()
assertCreatingPlacementWithDecision(placement, 2, 1)
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
ginkgo.By("Adding fake placement decisions")
assertCreatingPlacementDecision(placementName+"-1", namespace, []string{clusterNames[1]})
@@ -175,10 +135,10 @@ var _ = ginkgo.Describe("Prioritizers", func() {
clusterNames = append(clusterNames, clusterName+"-4")
newClusterResources := []string{"10", "10", "100", "100"}
newClusters := assertCreatingClusters(clusterSet1Name, 1)
assertUpdatingClusterWithClusterResources(newClusters[0], newClusterResources)
assertPatchingClusterStatusWithResources(newClusters[0], newClusterResources)
//Checking the result of the placement
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
})
ginkgo.It("Should schedule successfully based on SchedulePolicy balance", func() {
@@ -188,39 +148,23 @@ var _ = ginkgo.Describe("Prioritizers", func() {
clusterResources[1] = []string{"7", "10", "90", "100"}
clusterResources[2] = []string{"9", "10", "80", "100"}
// placement settings
prioritizerPolicy := clusterapiv1beta1.PrioritizerPolicy{
Mode: clusterapiv1beta1.PrioritizerPolicyModeExact,
Configurations: []clusterapiv1beta1.PrioritizerConfig{
{
ScoreCoordinate: &clusterapiv1beta1.ScoreCoordinate{
Type: clusterapiv1beta1.ScoreCoordinateTypeBuiltIn,
BuiltIn: "Balance",
},
Weight: 2,
},
{
ScoreCoordinate: &clusterapiv1beta1.ScoreCoordinate{
Type: clusterapiv1beta1.ScoreCoordinateTypeBuiltIn,
BuiltIn: "ResourceAllocatableCPU",
},
Weight: 1,
},
},
}
//Creating the clusters with resources
assertBindingClusterSet(clusterSet1Name, namespace)
clusterNames := assertCreatingClusters(clusterSet1Name, 3)
for i, name := range clusterNames {
assertUpdatingClusterWithClusterResources(name, clusterResources[i])
assertPatchingClusterStatusWithResources(name, clusterResources[i])
}
ginkgo.By("Adding fake placement decisions")
assertCreatingPlacementDecision("fake-1", namespace, []string{clusterNames[0]})
//Checking the result of the placement
assertCreatingPlacementWithDecision(placementName, namespace, noc(2), 2, 1, prioritizerPolicy, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[1], clusterNames[2]})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(2).
WithPrioritizerPolicy(clusterapiv1beta1.PrioritizerPolicyModeExact).
WithPrioritizerConfig("Balance", 2).
WithPrioritizerConfig("ResourceAllocatableCPU", 1).Build()
assertCreatingPlacementWithDecision(placement, 2, 1)
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[1], clusterNames[2]})
})
ginkgo.It("Should re-schedule successfully once a new cluster with resources added/deleted", func() {
@@ -230,52 +174,35 @@ var _ = ginkgo.Describe("Prioritizers", func() {
clusterResources[1] = []string{"7", "10", "90", "100"}
clusterResources[2] = []string{"9", "10", "80", "100"}
// placement settings
prioritizerPolicy := clusterapiv1beta1.PrioritizerPolicy{
Mode: clusterapiv1beta1.PrioritizerPolicyModeExact,
Configurations: []clusterapiv1beta1.PrioritizerConfig{
{
ScoreCoordinate: &clusterapiv1beta1.ScoreCoordinate{
Type: clusterapiv1beta1.ScoreCoordinateTypeBuiltIn,
BuiltIn: "ResourceAllocatableCPU",
},
Weight: 1,
},
{
ScoreCoordinate: &clusterapiv1beta1.ScoreCoordinate{
Type: clusterapiv1beta1.ScoreCoordinateTypeBuiltIn,
BuiltIn: "ResourceAllocatableMemory",
},
Weight: 1,
},
},
}
//Creating the clusters with resources
assertBindingClusterSet(clusterSet1Name, namespace)
clusterNames := assertCreatingClusters(clusterSet1Name, 3)
for i, name := range clusterNames {
assertUpdatingClusterWithClusterResources(name, clusterResources[i])
assertPatchingClusterStatusWithResources(name, clusterResources[i])
}
//Checking the result of the placement
assertCreatingPlacementWithDecision(placementName, namespace, noc(2), 2, 1, prioritizerPolicy, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(2).
WithPrioritizerPolicy(clusterapiv1beta1.PrioritizerPolicyModeExact).
WithPrioritizerConfig("ResourceAllocatableCPU", 1).
WithPrioritizerConfig("ResourceAllocatableMemory", 1).Build()
assertCreatingPlacementWithDecision(placement, 2, 1)
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
ginkgo.By("Adding a new cluster with resources")
clusterNames = append(clusterNames, clusterName+"-4")
newClusterResources := []string{"10", "10", "100", "100"}
newClusters := assertCreatingClusters(clusterSet1Name, 1)
assertUpdatingClusterWithClusterResources(newClusters[0], newClusterResources)
assertPatchingClusterStatusWithResources(newClusters[0], newClusterResources)
//Checking the result of the placement
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[2], newClusters[0]})
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[2], newClusters[0]})
ginkgo.By("Deleting the cluster")
assertDeletingClusters(newClusters[0])
//Checking the result of the placement
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
})
})
@@ -283,23 +210,6 @@ var _ = ginkgo.Describe("Prioritizers", func() {
ginkgo.It("Should schedule successfully based on AddOnPlacementScore", func() {
// cluster settings
// placement settings
prioritizerPolicy := clusterapiv1beta1.PrioritizerPolicy{
Mode: clusterapiv1beta1.PrioritizerPolicyModeExact,
Configurations: []clusterapiv1beta1.PrioritizerConfig{
{
ScoreCoordinate: &clusterapiv1beta1.ScoreCoordinate{
Type: clusterapiv1beta1.ScoreCoordinateTypeAddOn,
AddOn: &clusterapiv1beta1.AddOnScore{
ResourceName: "demo",
ScoreName: "demo",
},
},
Weight: 1,
},
},
}
//Creating the clusters with resources
assertBindingClusterSet(clusterSet1Name, namespace)
clusterNames := assertCreatingClusters(clusterSet1Name, 3)
@@ -308,37 +218,26 @@ var _ = ginkgo.Describe("Prioritizers", func() {
assertCreatingAddOnPlacementScores(clusterNames[2], "demo", "demo", 100)
//Checking the result of the placement
assertCreatingPlacementWithDecision(placementName, namespace, noc(2), 2, 1, prioritizerPolicy, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[1], clusterNames[2]})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(2).
WithPrioritizerPolicy(clusterapiv1beta1.PrioritizerPolicyModeExact).
WithScoreCoordinateAddOn("demo", "demo", 1).Build()
assertCreatingPlacementWithDecision(placement, 2, 1)
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[1], clusterNames[2]})
})
ginkgo.It("Should reschedule every ResyncInterval and update desicion when AddOnPlacementScore changes", func() {
// placement settings
prioritizerPolicy := clusterapiv1beta1.PrioritizerPolicy{
Mode: clusterapiv1beta1.PrioritizerPolicyModeExact,
Configurations: []clusterapiv1beta1.PrioritizerConfig{
{
ScoreCoordinate: &clusterapiv1beta1.ScoreCoordinate{
Type: clusterapiv1beta1.ScoreCoordinateTypeAddOn,
AddOn: &clusterapiv1beta1.AddOnScore{
ResourceName: "demo",
ScoreName: "demo",
},
},
Weight: 1,
},
},
}
//Creating the clusters with resources
assertBindingClusterSet(clusterSet1Name, namespace)
clusterNames := assertCreatingClusters(clusterSet1Name, 3)
//Creating the placement
assertCreatingPlacementWithDecision(placementName, namespace, noc(2), 2, 1, prioritizerPolicy, []clusterapiv1beta1.Toleration{}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(2).
WithPrioritizerPolicy(clusterapiv1beta1.PrioritizerPolicyModeExact).
WithScoreCoordinateAddOn("demo", "demo", 1).Build()
assertCreatingPlacementWithDecision(placement, 2, 1)
//Checking the result of the placement when no AddOnPlacementScores
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[0], clusterNames[1]})
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[0], clusterNames[1]})
//Creating the AddOnPlacementScores
assertCreatingAddOnPlacementScores(clusterNames[0], "demo", "demo", 80)
@@ -346,7 +245,7 @@ var _ = ginkgo.Describe("Prioritizers", func() {
assertCreatingAddOnPlacementScores(clusterNames[2], "demo", "demo", 100)
//Checking the result of the placement when AddOnPlacementScores added
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[1], clusterNames[2]})
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[1], clusterNames[2]})
//update the AddOnPlacementScores
assertCreatingAddOnPlacementScores(clusterNames[0], "demo", "demo", 100)
@@ -354,7 +253,7 @@ var _ = ginkgo.Describe("Prioritizers", func() {
assertCreatingAddOnPlacementScores(clusterNames[2], "demo", "demo", 100)
//Checking the result of the placement when AddOnPlacementScores updated
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[0], clusterNames[2]})
})
})
+56 -63
View File
@@ -17,6 +17,7 @@ import (
controllers "open-cluster-management.io/ocm/pkg/placement/controllers"
"open-cluster-management.io/ocm/pkg/placement/controllers/scheduling"
testinghelpers "open-cluster-management.io/ocm/pkg/placement/helpers/testing"
"open-cluster-management.io/ocm/test/integration/util"
)
@@ -66,35 +67,33 @@ var _ = ginkgo.Describe("TaintToleration", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
clusterNames := assertCreatingClusters(clusterSet1Name, 3)
assertUpdatingClusterWithClusterTaint(clusterNames[0], &clusterapiv1.Taint{
assertPatchingClusterSpecWithTaint(clusterNames[0], &clusterapiv1.Taint{
Key: "key1",
Value: "value1",
Effect: clusterapiv1.TaintEffectNoSelect,
})
assertUpdatingClusterWithClusterTaint(clusterNames[1], &clusterapiv1.Taint{
assertPatchingClusterSpecWithTaint(clusterNames[1], &clusterapiv1.Taint{
Key: "key2",
Value: "value2",
Effect: clusterapiv1.TaintEffectNoSelect,
})
assertUpdatingClusterWithClusterTaint(clusterNames[2], &clusterapiv1.Taint{
assertPatchingClusterSpecWithTaint(clusterNames[2], &clusterapiv1.Taint{
Key: "key2",
Value: "value3",
Effect: clusterapiv1.TaintEffectNoSelect,
})
//Checking the result of the placement
assertCreatingPlacementWithDecision(placementName, namespace, noc(3), 2, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{
{
Key: "key1",
Operator: clusterapiv1beta1.TolerationOpExists,
},
{
Key: "key2",
Operator: clusterapiv1beta1.TolerationOpEqual,
Value: "value2",
},
}, clusterapiv1beta1.GroupStrategy{})
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[0], clusterNames[1]})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(3).AddToleration(&clusterapiv1beta1.Toleration{
Key: "key1",
Operator: clusterapiv1beta1.TolerationOpExists,
}).AddToleration(&clusterapiv1beta1.Toleration{
Key: "key2",
Operator: clusterapiv1beta1.TolerationOpEqual,
Value: "value2",
}).Build()
assertCreatingPlacementWithDecision(placement, 2, 1)
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[0], clusterNames[1]})
})
ginkgo.It("Should schedule when taint/toleration effect matches", func() {
@@ -102,55 +101,51 @@ var _ = ginkgo.Describe("TaintToleration", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
clusterNames := assertCreatingClusters(clusterSet1Name, 4)
assertUpdatingClusterWithClusterTaint(clusterNames[0], &clusterapiv1.Taint{
assertPatchingClusterSpecWithTaint(clusterNames[0], &clusterapiv1.Taint{
Key: "key1",
Value: "value1",
Effect: clusterapiv1.TaintEffectNoSelect,
})
assertUpdatingClusterWithClusterTaint(clusterNames[1], &clusterapiv1.Taint{
assertPatchingClusterSpecWithTaint(clusterNames[1], &clusterapiv1.Taint{
Key: "key2",
Value: "value2",
Effect: clusterapiv1.TaintEffectNoSelectIfNew,
})
assertUpdatingClusterWithClusterTaint(clusterNames[2], &clusterapiv1.Taint{
assertPatchingClusterSpecWithTaint(clusterNames[2], &clusterapiv1.Taint{
Key: "key3",
Value: "value3",
Effect: clusterapiv1.TaintEffectPreferNoSelect,
})
//Taint/toleration matches, effect not match
assertCreatingPlacementWithDecision(placementName, namespace, noc(4), 2, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{
{
Key: "key1",
Operator: clusterapiv1beta1.TolerationOpExists,
Effect: clusterapiv1.TaintEffectPreferNoSelect,
},
{
Key: "key2",
Operator: clusterapiv1beta1.TolerationOpExists,
Effect: clusterapiv1.TaintEffectNoSelect,
},
{
Key: "key3",
Operator: clusterapiv1beta1.TolerationOpExists,
Effect: clusterapiv1.TaintEffectNoSelect,
},
{
Key: "key4",
Operator: clusterapiv1beta1.TolerationOpExists,
Effect: clusterapiv1.TaintEffectNoSelect,
},
}, clusterapiv1beta1.GroupStrategy{})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(4).AddToleration(&clusterapiv1beta1.Toleration{
Key: "key1",
Operator: clusterapiv1beta1.TolerationOpExists,
Effect: clusterapiv1.TaintEffectPreferNoSelect,
}).AddToleration(&clusterapiv1beta1.Toleration{
Key: "key2",
Operator: clusterapiv1beta1.TolerationOpExists,
Effect: clusterapiv1.TaintEffectNoSelect,
}).AddToleration(&clusterapiv1beta1.Toleration{
Key: "key3",
Operator: clusterapiv1beta1.TolerationOpExists,
Effect: clusterapiv1.TaintEffectNoSelect,
}).AddToleration(&clusterapiv1beta1.Toleration{
Key: "key4",
Operator: clusterapiv1beta1.TolerationOpExists,
Effect: clusterapiv1.TaintEffectNoSelect,
}).Build()
assertCreatingPlacementWithDecision(placement, 2, 1)
//Checking the result of the placement
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[2], clusterNames[3]})
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[2], clusterNames[3]})
//Taint effect is NoSelectIfNew, tolerations doesn't match, cluster is in decision
assertUpdatingClusterWithClusterTaint(clusterNames[3], &clusterapiv1.Taint{
assertPatchingClusterSpecWithTaint(clusterNames[3], &clusterapiv1.Taint{
Key: "key4",
Value: "value4",
Effect: clusterapiv1.TaintEffectNoSelectIfNew,
})
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[2], clusterNames[3]})
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[2], clusterNames[3]})
})
ginkgo.It("Should reschedule when expire TolerationSeconds", func() {
@@ -163,19 +158,19 @@ var _ = ginkgo.Describe("TaintToleration", func() {
assertBindingClusterSet(clusterSet1Name, namespace)
clusterNames := assertCreatingClusters(clusterSet1Name, 4)
assertUpdatingClusterWithClusterTaint(clusterNames[0], &clusterapiv1.Taint{
assertPatchingClusterSpecWithTaint(clusterNames[0], &clusterapiv1.Taint{
Key: "key1",
Value: "value1",
Effect: clusterapiv1.TaintEffectNoSelect,
TimeAdded: addedTime,
})
assertUpdatingClusterWithClusterTaint(clusterNames[1], &clusterapiv1.Taint{
assertPatchingClusterSpecWithTaint(clusterNames[1], &clusterapiv1.Taint{
Key: "key2",
Value: "value2",
Effect: clusterapiv1.TaintEffectNoSelect,
TimeAdded: addedTime,
})
assertUpdatingClusterWithClusterTaint(clusterNames[2], &clusterapiv1.Taint{
assertPatchingClusterSpecWithTaint(clusterNames[2], &clusterapiv1.Taint{
Key: "key2",
Value: "value2",
Effect: clusterapiv1.TaintEffectNoSelect,
@@ -183,32 +178,30 @@ var _ = ginkgo.Describe("TaintToleration", func() {
})
//Checking the result of the placement
assertCreatingPlacementWithDecision(placementName, namespace, noc(4), 3, 1, clusterapiv1beta1.PrioritizerPolicy{}, []clusterapiv1beta1.Toleration{
{
Key: "key1",
Operator: clusterapiv1beta1.TolerationOpExists,
TolerationSeconds: &tolerationSeconds_10,
},
{
Key: "key2",
Operator: clusterapiv1beta1.TolerationOpExists,
TolerationSeconds: &tolerationSeconds_20,
},
}, clusterapiv1beta1.GroupStrategy{})
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[0], clusterNames[1], clusterNames[3]})
placement := testinghelpers.NewPlacement(namespace, placementName).WithNOC(4).AddToleration(&clusterapiv1beta1.Toleration{
Key: "key1",
Operator: clusterapiv1beta1.TolerationOpExists,
TolerationSeconds: &tolerationSeconds_10,
}).AddToleration(&clusterapiv1beta1.Toleration{
Key: "key2",
Operator: clusterapiv1beta1.TolerationOpExists,
TolerationSeconds: &tolerationSeconds_20,
}).Build()
assertCreatingPlacementWithDecision(placement, 3, 1)
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[0], clusterNames[1], clusterNames[3]})
//Check placement requeue, clusterNames[0] should be removed when TolerationSeconds expired.
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[1], clusterNames[3]})
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[1], clusterNames[3]})
//Check placement requeue, clusterNames[1] should be removed when TolerationSeconds expired.
assertClusterNamesOfDecisions(placementName, namespace, []string{clusterNames[3]})
assertPlacementDecisionClusterNames(placementName, namespace, []string{clusterNames[3]})
//Check placement update, clusterNames[3] should be removed when new taint added.
assertUpdatingClusterWithClusterTaint(clusterNames[3], &clusterapiv1.Taint{
assertPatchingClusterSpecWithTaint(clusterNames[3], &clusterapiv1.Taint{
Key: "key3",
Value: "value3",
Effect: clusterapiv1.TaintEffectNoSelect,
TimeAdded: metav1.NewTime(addedTime_60),
})
assertClusterNamesOfDecisions(placementName, namespace, []string{})
assertPlacementDecisionClusterNames(placementName, namespace, []string{})
})
})
})