Skip to content

Commit a8c5f30

Browse files
committed
update stop integration test
Signed-off-by: Britania Rodriguez Reyes <[email protected]>
1 parent 22f8aa5 commit a8c5f30

File tree

4 files changed

+223
-424
lines changed

4 files changed

+223
-424
lines changed

pkg/controllers/updaterun/controller_integration_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/google/go-cmp/cmp"
2727
. "github.com/onsi/ginkgo/v2"
2828
. "github.com/onsi/gomega"
29-
"github.com/prometheus/client_golang/prometheus"
3029
prometheusclientmodel "github.com/prometheus/client_model/go"
3130

3231
corev1 "k8s.io/api/core/v1"
@@ -363,24 +362,6 @@ func generateSucceededMetric(updateRun *placementv1beta1.ClusterStagedUpdateRun)
363362
}
364363
}
365364

366-
func labelPairsToMap(pairs []*prometheusclientmodel.LabelPair) prometheus.Labels {
367-
m := prometheus.Labels{}
368-
for _, p := range pairs {
369-
m[p.GetName()] = p.GetValue()
370-
}
371-
return m
372-
}
373-
374-
func removeMetricFromMetricList(metricList []*prometheusclientmodel.Metric, metricToRemove *prometheusclientmodel.Metric) []*prometheusclientmodel.Metric {
375-
var result []*prometheusclientmodel.Metric
376-
for _, metric := range metricList {
377-
if !cmp.Equal(labelPairsToMap(metric.Label), labelPairsToMap(metricToRemove.Label)) {
378-
result = append(result, metric)
379-
}
380-
}
381-
return result
382-
}
383-
384365
func generateTestClusterStagedUpdateRun() *placementv1beta1.ClusterStagedUpdateRun {
385366
return &placementv1beta1.ClusterStagedUpdateRun{
386367
ObjectMeta: metav1.ObjectMeta{
@@ -480,25 +461,44 @@ func generateTestClusterResourceBindingsAndClusters(policySnapshotIndex int) ([]
480461
return resourceBindings, targetClusters, unscheduledClusters
481462
}
482463

483-
func generateSmallTestClusterResourceBindingsAndClusters(policySnapshotIndex int) ([]*placementv1beta1.ClusterResourceBinding, []*clusterv1beta1.MemberCluster, []*clusterv1beta1.MemberCluster) {
464+
func generateSmallTestClusterResourceBindingsAndClusters(policySnapshotIndex int, numUnscheduledClusters int) ([]*placementv1beta1.ClusterResourceBinding, []*clusterv1beta1.MemberCluster, []*clusterv1beta1.MemberCluster) {
484465
numTargetClusters := 3
485466
policySnapshotName := fmt.Sprintf(placementv1beta1.PolicySnapshotNameFmt, testCRPName, policySnapshotIndex)
486-
resourceBindings := make([]*placementv1beta1.ClusterResourceBinding, numTargetClusters)
467+
resourceBindings := make([]*placementv1beta1.ClusterResourceBinding, numTargetClusters+numUnscheduledClusters)
487468
targetClusters := make([]*clusterv1beta1.MemberCluster, numTargetClusters)
488469
for i := range targetClusters {
489470
// split the clusters into 2 regions
490471
region := regionEastus
491472
if i%2 == 0 {
492473
region = regionWestus
493474
}
494-
// reserse the order of the clusters by index
475+
// reverse the order of the clusters by index
495476
targetClusters[i] = generateTestMemberCluster(numTargetClusters-1-i, "cluster-"+strconv.Itoa(i), map[string]string{"group": "prod", "region": region})
496477
resourceBindings[i] = generateTestClusterResourceBinding(policySnapshotName, targetClusters[i].Name, placementv1beta1.BindingStateScheduled)
497478
}
498-
unscheduledClusters := make([]*clusterv1beta1.MemberCluster, 0)
479+
480+
resourceBindings, unscheduledClusters := generateTestUnscheduledClusterResourceBindingsAndClusters(policySnapshotIndex, numUnscheduledClusters, resourceBindings)
499481
return resourceBindings, targetClusters, unscheduledClusters
500482
}
501483

484+
func generateTestUnscheduledClusterResourceBindingsAndClusters(policySnapshotIndex int, numUnscheduledClusters int, bindings []*placementv1beta1.ClusterResourceBinding) ([]*placementv1beta1.ClusterResourceBinding, []*clusterv1beta1.MemberCluster) {
485+
policySnapshotName := fmt.Sprintf(placementv1beta1.PolicySnapshotNameFmt, testCRPName, policySnapshotIndex)
486+
targetClusters := len(bindings) - numUnscheduledClusters
487+
unscheduledClusters := make([]*clusterv1beta1.MemberCluster, numUnscheduledClusters)
488+
// Half of the unscheduled clusters have old policy snapshot.
489+
for i := range numUnscheduledClusters / 2 {
490+
unscheduledClusters[i] = generateTestMemberCluster(i, "unscheduled-cluster-"+strconv.Itoa(i), map[string]string{"group": "staging"})
491+
// Update the policySnapshot name so that these clusters are considered to-be-deleted.
492+
bindings[targetClusters+i] = generateTestClusterResourceBinding(policySnapshotName+"a", unscheduledClusters[i].Name, placementv1beta1.BindingStateUnscheduled)
493+
}
494+
// The other half of the unscheduled clusters have latest policy snapshot but still unscheduled.
495+
for i := numUnscheduledClusters / 2; i < numUnscheduledClusters; i++ {
496+
unscheduledClusters[i] = generateTestMemberCluster(i, "unscheduled-cluster-"+strconv.Itoa(i), map[string]string{"group": "staging"})
497+
bindings[targetClusters+i] = generateTestClusterResourceBinding(policySnapshotName, unscheduledClusters[i].Name, placementv1beta1.BindingStateUnscheduled)
498+
}
499+
return bindings, unscheduledClusters
500+
}
501+
502502
func generateTestClusterResourceBinding(policySnapshotName, targetCluster string, state placementv1beta1.BindingState) *placementv1beta1.ClusterResourceBinding {
503503
binding := &placementv1beta1.ClusterResourceBinding{
504504
ObjectMeta: metav1.ObjectMeta{

pkg/controllers/updaterun/execution_integration_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() {
728728

729729
updateRun = generateTestClusterStagedUpdateRun()
730730
crp = generateTestClusterResourcePlacement()
731-
resourceBindings, targetClusters, _ = generateSmallTestClusterResourceBindingsAndClusters(1)
731+
resourceBindings, targetClusters, _ = generateSmallTestClusterResourceBindingsAndClusters(1, 0)
732732
policySnapshot = generateTestClusterSchedulingPolicySnapshot(1, len(targetClusters))
733733
resourceSnapshot = generateTestClusterResourceSnapshot()
734734
resourceSnapshot = generateTestClusterResourceSnapshot()
@@ -810,7 +810,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() {
810810
Expect(k8sClient.Create(ctx, updateRun)).To(Succeed())
811811

812812
By("Validating the initialization succeeded and the execution started")
813-
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy)
813+
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, 0)
814814
wantStatus = generateExecutionStartedStatus(updateRun, initialized)
815815
validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "")
816816

@@ -904,7 +904,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() {
904904
Expect(k8sClient.Create(ctx, updateRun)).To(Succeed())
905905

906906
By("Validating the initialization succeeded and the execution started")
907-
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy)
907+
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, 0)
908908
wantStatus = generateExecutionStartedStatus(updateRun, initialized)
909909
validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "")
910910

@@ -1013,7 +1013,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() {
10131013
Expect(k8sClient.Create(ctx, updateRun)).To(Succeed())
10141014

10151015
By("Validating the initialization succeeded and the execution started")
1016-
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy)
1016+
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, 0)
10171017
wantStatus = generateExecutionStartedStatus(updateRun, initialized)
10181018
validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "")
10191019

@@ -1145,7 +1145,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() {
11451145
Expect(k8sClient.Create(ctx, updateRun)).To(Succeed())
11461146

11471147
By("Validating the initialization succeeded and the execution started")
1148-
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy)
1148+
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, 0)
11491149
wantStatus = generateExecutionStartedStatus(updateRun, initialized)
11501150
validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "")
11511151

@@ -1237,7 +1237,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() {
12371237
Expect(k8sClient.Create(ctx, updateRun)).To(Succeed())
12381238

12391239
By("Validating the initialization succeeded and the execution started")
1240-
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy)
1240+
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, 0)
12411241
wantStatus = generateExecutionStartedStatus(updateRun, initialized)
12421242
validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "")
12431243

@@ -1300,7 +1300,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() {
13001300
Expect(k8sClient.Create(ctx, updateRun)).To(Succeed())
13011301

13021302
By("Validating the initialization succeeded and the execution has not started")
1303-
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy)
1303+
initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, 0)
13041304
wantStatus = generateExecutionNotStartedStatus(updateRun, initialized)
13051305
validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "")
13061306

@@ -1534,7 +1534,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() {
15341534
Expect(k8sClient.Create(ctx, updateRun)).To(Succeed())
15351535

15361536
By("Validating the initialization succeeded and but not execution started")
1537-
wantStatus = generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy)
1537+
wantStatus = generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, 0)
15381538
validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "")
15391539

15401540
By("Checking update run status metrics are emitted")

pkg/controllers/updaterun/initialization_integration_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ func generateSucceededInitializationStatusForSmallClusters(
10391039
resourceSnapshotIndex string,
10401040
policySnapshot *placementv1beta1.ClusterSchedulingPolicySnapshot,
10411041
updateStrategy *placementv1beta1.ClusterStagedUpdateStrategy,
1042+
numUnscheduledClusters int,
10421043
) *placementv1beta1.UpdateRunStatus {
10431044
status := &placementv1beta1.UpdateRunStatus{
10441045
PolicySnapshotIndexUsed: policySnapshot.Labels[placementv1beta1.PolicyIndexLabel],
@@ -1065,6 +1066,10 @@ func generateSucceededInitializationStatusForSmallClusters(
10651066
generateTrueCondition(updateRun, placementv1beta1.StagedUpdateRunConditionInitialized),
10661067
},
10671068
}
1069+
for i := range numUnscheduledClusters {
1070+
status.DeletionStageStatus.Clusters = append(status.DeletionStageStatus.Clusters,
1071+
placementv1beta1.ClusterUpdatingStatus{ClusterName: fmt.Sprintf("unscheduled-cluster-%d", i)})
1072+
}
10681073
for i := range status.StagesStatus {
10691074
var beforeTasks []placementv1beta1.StageTaskStatus
10701075
for _, task := range updateStrategy.Spec.Stages[i].BeforeStageTasks {

0 commit comments

Comments
 (0)