Skip to content

Commit a7675f8

Browse files
authored
test: add RP apply strategy tests (#226)
--------- Signed-off-by: Zhiying Lin <zhiyingl456@gmail.com>
1 parent 43fdbf0 commit a7675f8

11 files changed

+1687
-269
lines changed

test/e2e/actuals_test.go

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func validateConfigMapOnCluster(cluster *framework.Cluster, name types.Namespace
111111
return nil
112112
}
113113

114-
func validateOverrideAnnotationOfConfigMapOnCluster(cluster *framework.Cluster, wantAnnotations map[string]string) error {
114+
func validateAnnotationOfConfigMapOnCluster(cluster *framework.Cluster, wantAnnotations map[string]string) error {
115115
workNamespaceName := fmt.Sprintf(workNamespaceNameTemplate, GinkgoParallelProcess())
116116
appConfigMapName := fmt.Sprintf(appConfigMapNameTemplate, GinkgoParallelProcess())
117117

@@ -519,6 +519,41 @@ func crpRolloutPendingDueToExternalStrategyConditions(generation int64) []metav1
519519
}
520520
}
521521

522+
func rpAppliedFailedConditions(generation int64) []metav1.Condition {
523+
return []metav1.Condition{
524+
{
525+
Type: string(placementv1beta1.ResourcePlacementScheduledConditionType),
526+
Status: metav1.ConditionTrue,
527+
Reason: scheduler.FullyScheduledReason,
528+
ObservedGeneration: generation,
529+
},
530+
{
531+
Type: string(placementv1beta1.ResourcePlacementRolloutStartedConditionType),
532+
Status: metav1.ConditionTrue,
533+
Reason: condition.RolloutStartedReason,
534+
ObservedGeneration: generation,
535+
},
536+
{
537+
Type: string(placementv1beta1.ResourcePlacementOverriddenConditionType),
538+
Status: metav1.ConditionTrue,
539+
Reason: condition.OverrideNotSpecifiedReason,
540+
ObservedGeneration: generation,
541+
},
542+
{
543+
Type: string(placementv1beta1.ResourcePlacementWorkSynchronizedConditionType),
544+
Status: metav1.ConditionTrue,
545+
Reason: condition.WorkSynchronizedReason,
546+
ObservedGeneration: generation,
547+
},
548+
{
549+
Type: string(placementv1beta1.ResourcePlacementAppliedConditionType),
550+
Status: metav1.ConditionFalse,
551+
Reason: condition.ApplyFailedReason,
552+
ObservedGeneration: generation,
553+
},
554+
}
555+
}
556+
522557
func crpAppliedFailedConditions(generation int64) []metav1.Condition {
523558
return []metav1.Condition{
524559
{
@@ -599,6 +634,45 @@ func crpNotAvailableConditions(generation int64, hasOverride bool) []metav1.Cond
599634
}
600635
}
601636

637+
func rpDiffReportedConditions(generation int64, hasOverride bool) []metav1.Condition {
638+
overrideConditionReason := condition.OverrideNotSpecifiedReason
639+
if hasOverride {
640+
overrideConditionReason = condition.OverriddenSucceededReason
641+
}
642+
return []metav1.Condition{
643+
{
644+
Type: string(placementv1beta1.ResourcePlacementScheduledConditionType),
645+
Status: metav1.ConditionTrue,
646+
Reason: scheduler.FullyScheduledReason,
647+
ObservedGeneration: generation,
648+
},
649+
{
650+
Type: string(placementv1beta1.ResourcePlacementRolloutStartedConditionType),
651+
Status: metav1.ConditionTrue,
652+
Reason: condition.RolloutStartedReason,
653+
ObservedGeneration: generation,
654+
},
655+
{
656+
Type: string(placementv1beta1.ResourcePlacementOverriddenConditionType),
657+
Status: metav1.ConditionTrue,
658+
Reason: overrideConditionReason,
659+
ObservedGeneration: generation,
660+
},
661+
{
662+
Type: string(placementv1beta1.ResourcePlacementWorkSynchronizedConditionType),
663+
Status: metav1.ConditionTrue,
664+
Reason: condition.WorkSynchronizedReason,
665+
ObservedGeneration: generation,
666+
},
667+
{
668+
Type: string(placementv1beta1.ResourcePlacementDiffReportedConditionType),
669+
Status: metav1.ConditionTrue,
670+
Reason: condition.DiffReportedStatusTrueReason,
671+
ObservedGeneration: generation,
672+
},
673+
}
674+
}
675+
602676
func crpDiffReportedConditions(generation int64, hasOverride bool) []metav1.Condition {
603677
overrideConditionReason := condition.OverrideNotSpecifiedReason
604678
if hasOverride {

test/e2e/placement_apply_strategy_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var _ = Describe("validating CRP when resources exists", Ordered, func() {
7777

7878
// Create the CRP.
7979
strategy := &placementv1beta1.ApplyStrategy{AllowCoOwnership: true}
80-
createCRPWithApplyStrategy(crpName, strategy)
80+
createCRPWithApplyStrategy(crpName, strategy, nil)
8181
})
8282

8383
AfterAll(func() {
@@ -136,7 +136,7 @@ var _ = Describe("validating CRP when resources exists", Ordered, func() {
136136

137137
// Create the CRP.
138138
strategy := &placementv1beta1.ApplyStrategy{AllowCoOwnership: false}
139-
createCRPWithApplyStrategy(crpName, strategy)
139+
createCRPWithApplyStrategy(crpName, strategy, nil)
140140
})
141141

142142
AfterAll(func() {
@@ -189,7 +189,7 @@ var _ = Describe("validating CRP when resources exists", Ordered, func() {
189189
Type: placementv1beta1.ApplyStrategyTypeServerSideApply,
190190
AllowCoOwnership: false,
191191
}
192-
createCRPWithApplyStrategy(crpName, strategy)
192+
createCRPWithApplyStrategy(crpName, strategy, nil)
193193
})
194194

195195
AfterAll(func() {
@@ -242,7 +242,7 @@ var _ = Describe("validating CRP when resources exists", Ordered, func() {
242242
Type: placementv1beta1.ApplyStrategyTypeServerSideApply,
243243
AllowCoOwnership: false,
244244
}
245-
createCRPWithApplyStrategy(crpName, strategy)
245+
createCRPWithApplyStrategy(crpName, strategy, nil)
246246
})
247247

248248
AfterAll(func() {
@@ -371,7 +371,7 @@ var _ = Describe("validating CRP when resources exists", Ordered, func() {
371371
ServerSideApplyConfig: &placementv1beta1.ServerSideApplyConfig{ForceConflicts: true},
372372
AllowCoOwnership: true,
373373
}
374-
createCRPWithApplyStrategy(crpName, strategy)
374+
createCRPWithApplyStrategy(crpName, strategy, nil)
375375
})
376376

377377
AfterAll(func() {

test/e2e/placement_cro_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ var _ = Context("creating clusterResourceOverride with different rules for each
391391
for i, cluster := range allMemberClusters {
392392
wantAnnotations := map[string]string{croTestAnnotationKey: fmt.Sprintf("%s-%d", croTestAnnotationValue, i)}
393393
Expect(validateAnnotationOfWorkNamespaceOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of work namespace on %s", cluster.ClusterName)
394-
Expect(validateOverrideAnnotationOfConfigMapOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of configmap on %s", cluster.ClusterName)
394+
Expect(validateAnnotationOfConfigMapOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of configmap on %s", cluster.ClusterName)
395395
}
396396
})
397397
})
@@ -466,7 +466,7 @@ var _ = Context("creating clusterResourceOverride with different rules for each
466466
for _, cluster := range allMemberClusters {
467467
wantAnnotations := map[string]string{croTestAnnotationKey: fmt.Sprintf("test-%s", cluster.ClusterName)}
468468
Expect(validateAnnotationOfWorkNamespaceOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of work namespace on %s", cluster.ClusterName)
469-
Expect(validateOverrideAnnotationOfConfigMapOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of configmap on %s", cluster.ClusterName)
469+
Expect(validateAnnotationOfConfigMapOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of configmap on %s", cluster.ClusterName)
470470
}
471471
})
472472
})
@@ -691,7 +691,7 @@ var _ = Context("creating clusterResourceOverride with delete rules for one clus
691691
cluster := allMemberClusters[idx]
692692
wantAnnotations := map[string]string{croTestAnnotationKey1: croTestAnnotationValue1}
693693
Expect(validateAnnotationOfWorkNamespaceOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of work namespace on %s", cluster.ClusterName)
694-
Expect(validateOverrideAnnotationOfConfigMapOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of configmap on %s", cluster.ClusterName)
694+
Expect(validateAnnotationOfConfigMapOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of configmap on %s", cluster.ClusterName)
695695
}
696696
})
697697

test/e2e/placement_drift_diff_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var _ = Describe("take over existing resources", func() {
7474
ComparisonOption: placementv1beta1.ComparisonOptionTypePartialComparison,
7575
WhenToTakeOver: placementv1beta1.WhenToTakeOverTypeAlways,
7676
}
77-
createCRPWithApplyStrategy(crpName, applyStrategy)
77+
createCRPWithApplyStrategy(crpName, applyStrategy, nil)
7878
})
7979

8080
It("should update CRP status as expected", func() {
@@ -174,7 +174,7 @@ var _ = Describe("take over existing resources", func() {
174174
ComparisonOption: placementv1beta1.ComparisonOptionTypePartialComparison,
175175
WhenToTakeOver: placementv1beta1.WhenToTakeOverTypeIfNoDiff,
176176
}
177-
createCRPWithApplyStrategy(crpName, applyStrategy)
177+
createCRPWithApplyStrategy(crpName, applyStrategy, nil)
178178
})
179179

180180
It("should update CRP status as expected", func() {
@@ -346,7 +346,7 @@ var _ = Describe("take over existing resources", func() {
346346
ComparisonOption: placementv1beta1.ComparisonOptionTypeFullComparison,
347347
WhenToTakeOver: placementv1beta1.WhenToTakeOverTypeIfNoDiff,
348348
}
349-
createCRPWithApplyStrategy(crpName, applyStrategy)
349+
createCRPWithApplyStrategy(crpName, applyStrategy, nil)
350350
})
351351

352352
It("should update CRP status as expected", func() {
@@ -526,7 +526,7 @@ var _ = Describe("detect drifts on placed resources", func() {
526526
ComparisonOption: placementv1beta1.ComparisonOptionTypeFullComparison,
527527
WhenToApply: placementv1beta1.WhenToApplyTypeAlways,
528528
}
529-
createCRPWithApplyStrategy(crpName, applyStrategy)
529+
createCRPWithApplyStrategy(crpName, applyStrategy, nil)
530530
})
531531

532532
It("should update CRP status as expected", func() {
@@ -665,7 +665,7 @@ var _ = Describe("detect drifts on placed resources", func() {
665665
ComparisonOption: placementv1beta1.ComparisonOptionTypePartialComparison,
666666
WhenToApply: placementv1beta1.WhenToApplyTypeIfNotDrifted,
667667
}
668-
createCRPWithApplyStrategy(crpName, applyStrategy)
668+
createCRPWithApplyStrategy(crpName, applyStrategy, nil)
669669
})
670670

671671
It("should update CRP status as expected", func() {
@@ -849,7 +849,7 @@ var _ = Describe("detect drifts on placed resources", func() {
849849
ComparisonOption: placementv1beta1.ComparisonOptionTypeFullComparison,
850850
WhenToApply: placementv1beta1.WhenToApplyTypeIfNotDrifted,
851851
}
852-
createCRPWithApplyStrategy(crpName, applyStrategy)
852+
createCRPWithApplyStrategy(crpName, applyStrategy, nil)
853853
})
854854

855855
It("should update CRP status as expected", func() {
@@ -1079,7 +1079,7 @@ var _ = Describe("report diff mode", func() {
10791079
Type: placementv1beta1.ApplyStrategyTypeReportDiff,
10801080
WhenToTakeOver: placementv1beta1.WhenToTakeOverTypeNever,
10811081
}
1082-
createCRPWithApplyStrategy(crpName, applyStrategy)
1082+
createCRPWithApplyStrategy(crpName, applyStrategy, nil)
10831083
})
10841084

10851085
It("should update CRP status as expected", func() {

test/e2e/placement_ro_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ var _ = Context("creating resourceOverride with different rules for each cluster
383383
It("should have override annotations on the configmap", func() {
384384
for i, cluster := range allMemberClusters {
385385
wantAnnotations := map[string]string{roTestAnnotationKey: fmt.Sprintf("%s-%d", roTestAnnotationValue, i)}
386-
Expect(validateOverrideAnnotationOfConfigMapOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of configmap on %s", cluster.ClusterName)
386+
Expect(validateAnnotationOfConfigMapOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of configmap on %s", cluster.ClusterName)
387387
}
388388
})
389389
})
@@ -498,7 +498,7 @@ var _ = Context("creating resourceOverride and clusterResourceOverride, resource
498498
want := map[string]string{croTestAnnotationKey: croTestAnnotationValue}
499499
for _, cluster := range allMemberClusters {
500500
Expect(validateAnnotationOfWorkNamespaceOnCluster(cluster, want)).Should(Succeed(), "Failed to override the annotation of work namespace on %s", cluster.ClusterName)
501-
Expect(validateOverrideAnnotationOfConfigMapOnCluster(cluster, want)).ShouldNot(Succeed(), "ResourceOverride Should win, ClusterResourceOverride annotated on $s", cluster.ClusterName)
501+
Expect(validateAnnotationOfConfigMapOnCluster(cluster, want)).ShouldNot(Succeed(), "ResourceOverride Should win, ClusterResourceOverride annotated on $s", cluster.ClusterName)
502502
}
503503
})
504504
})
@@ -837,7 +837,7 @@ var _ = Context("creating resourceOverride with delete configMap", Ordered, func
837837
for idx := 0; idx < 2; idx++ {
838838
cluster := allMemberClusters[idx]
839839
wantAnnotations := map[string]string{roTestAnnotationKey: roTestAnnotationValue}
840-
Expect(validateOverrideAnnotationOfConfigMapOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of configmap on %s", cluster.ClusterName)
840+
Expect(validateAnnotationOfConfigMapOnCluster(cluster, wantAnnotations)).Should(Succeed(), "Failed to override the annotation of configmap on %s", cluster.ClusterName)
841841
}
842842
})
843843

0 commit comments

Comments
 (0)