@@ -549,7 +549,7 @@ var _ = Describe("Updaterun initialization tests", func() {
549549 validateFailedInitCondition (ctx , updateRun , "referenced clusterStagedUpdateStrategy not found" )
550550 })
551551
552- Context ("Test computeStagedStatus " , func () {
552+ Context ("Test computeRunStageStatus " , func () {
553553 Context ("Test validateAfterStageTask" , func () {
554554 It ("Should fail to initialize if any after stage task has 2 same tasks" , func () {
555555 By ("Creating a clusterStagedUpdateStrategy with 2 same after stage tasks" )
@@ -617,7 +617,50 @@ var _ = Describe("Updaterun initialization tests", func() {
617617 Expect (k8sClient .Create (ctx , updateRun )).To (Succeed ())
618618
619619 By ("Validating the initialization failed" )
620- validateFailedInitCondition (ctx , updateRun , "some clusters are not placed in any stage" )
620+ validateFailedInitCondition (ctx , updateRun , "some clusters are not placed in any stage: cluster-0, cluster-2, cluster-4, cluster-6, cluster-8" )
621+ })
622+
623+ It ("Should select all scheduled clusters if labelSelector is empty and select no clusters if labelSelector is nil" , func () {
624+ By ("Creating a clusterStagedUpdateStrategy with two stages, using empty labelSelector and nil labelSelector respectively" )
625+ updateStrategy .Spec .Stages [0 ].LabelSelector = nil // no clusters selected
626+ updateStrategy .Spec .Stages [1 ].LabelSelector = & metav1.LabelSelector {} // all clusters selected
627+ Expect (k8sClient .Create (ctx , updateStrategy )).To (Succeed ())
628+
629+ By ("Creating a new clusterStagedUpdateRun" )
630+ Expect (k8sClient .Create (ctx , updateRun )).To (Succeed ())
631+
632+ By ("Validating the clusterStagedUpdateRun status" )
633+ Eventually (func () error {
634+ if err := k8sClient .Get (ctx , updateRunNamespacedName , updateRun ); err != nil {
635+ return err
636+ }
637+
638+ want := generateSucceededInitializationStatus (crp , updateRun , policySnapshot , updateStrategy , clusterResourceOverride )
639+ // No clusters should be selected in the first stage.
640+ want .StagesStatus [0 ].Clusters = []placementv1beta1.ClusterUpdatingStatus {}
641+ // All clusters should be selected in the second stage and sorted by name.
642+ want .StagesStatus [1 ].Clusters = []placementv1beta1.ClusterUpdatingStatus {
643+ {ClusterName : "cluster-0" },
644+ {ClusterName : "cluster-1" },
645+ {ClusterName : "cluster-2" },
646+ {ClusterName : "cluster-3" },
647+ {ClusterName : "cluster-4" },
648+ {ClusterName : "cluster-5" },
649+ {ClusterName : "cluster-6" },
650+ {ClusterName : "cluster-7" },
651+ {ClusterName : "cluster-8" },
652+ {ClusterName : "cluster-9" },
653+ }
654+ // initialization should fail due to resourceSnapshot not found.
655+ want .Conditions = []metav1.Condition {
656+ generateFalseCondition (updateRun , placementv1beta1 .StagedUpdateRunConditionInitialized ),
657+ }
658+
659+ if diff := cmp .Diff (* want , updateRun .Status , cmpOptions ... ); diff != "" {
660+ return fmt .Errorf ("status mismatch: (-want +got):\n %s" , diff )
661+ }
662+ return nil
663+ }, timeout , interval ).Should (Succeed (), "failed to validate the clusterStagedUpdateRun status" )
621664 })
622665 })
623666
@@ -639,7 +682,7 @@ var _ = Describe("Updaterun initialization tests", func() {
639682 // Remove the CROs, as they are not added in this test.
640683 want .StagesStatus [0 ].Clusters [i ].ClusterResourceOverrideSnapshots = nil
641684 }
642- // initialization should fail.
685+ // initialization should fail due to resourceSnapshot not found .
643686 want .Conditions = []metav1.Condition {
644687 generateFalseCondition (updateRun , placementv1beta1 .StagedUpdateRunConditionInitialized ),
645688 }
@@ -648,7 +691,7 @@ var _ = Describe("Updaterun initialization tests", func() {
648691 return fmt .Errorf ("status mismatch: (-want +got):\n %s" , diff )
649692 }
650693 return nil
651- }, timeout , interval ).Should (Succeed (), "failed to validate the clusterStagedUpdateRun in the status" )
694+ }, timeout , interval ).Should (Succeed (), "failed to validate the clusterStagedUpdateRun status" )
652695 })
653696 })
654697
0 commit comments