@@ -653,6 +653,7 @@ func crpStatusWithOverrideUpdatedFailedActual(
653653 return nil
654654 }
655655}
656+
656657func crpStatusWithWorkSynchronizedUpdatedFailedActual (
657658 wantSelectedResourceIdentifiers []placementv1beta1.ResourceIdentifier ,
658659 wantSelectedClusters []string ,
@@ -949,3 +950,184 @@ func validateCRPSnapshotRevisions(crpName string, wantPolicySnapshotRevision, wa
949950 }
950951 return nil
951952}
953+
954+ func updateRunClusterRolloutSucceedConditions (generation int64 ) []metav1.Condition {
955+ return []metav1.Condition {
956+ {
957+ Type : string (placementv1beta1 .ClusterUpdatingConditionStarted ),
958+ Status : metav1 .ConditionTrue ,
959+ Reason : condition .ClusterUpdatingStartedReason ,
960+ ObservedGeneration : generation ,
961+ },
962+ {
963+ Type : string (placementv1beta1 .ClusterUpdatingConditionSucceeded ),
964+ Status : metav1 .ConditionTrue ,
965+ Reason : condition .ClusterUpdatingSucceededReason ,
966+ ObservedGeneration : generation ,
967+ },
968+ }
969+ }
970+
971+ func updateRunStageRolloutSucceedConditions (generation int64 , wait bool ) []metav1.Condition {
972+ startedCond := metav1.Condition {
973+ Type : string (placementv1beta1 .StageUpdatingConditionProgressing ),
974+ Status : metav1 .ConditionTrue ,
975+ Reason : condition .StageUpdatingStartedReason ,
976+ ObservedGeneration : generation ,
977+ }
978+ if wait {
979+ startedCond .Status = metav1 .ConditionFalse
980+ startedCond .Reason = condition .StageUpdatingWaitingReason
981+ }
982+ return []metav1.Condition {
983+ startedCond ,
984+ {
985+ Type : string (placementv1beta1 .StageUpdatingConditionSucceeded ),
986+ Status : metav1 .ConditionTrue ,
987+ Reason : condition .StageUpdatingSucceededReason ,
988+ ObservedGeneration : generation ,
989+ },
990+ }
991+ }
992+
993+ func updateRunAfterStageTaskSucceedConditions (generation int64 , taskType placementv1beta1.AfterStageTaskType ) []metav1.Condition {
994+ if taskType == placementv1beta1 .AfterStageTaskTypeApproval {
995+ return []metav1.Condition {
996+ {
997+ Type : string (placementv1beta1 .AfterStageTaskConditionApprovalRequestCreated ),
998+ Status : metav1 .ConditionTrue ,
999+ Reason : condition .AfterStageTaskApprovalRequestCreatedReason ,
1000+ ObservedGeneration : generation ,
1001+ },
1002+ {
1003+ Type : string (placementv1beta1 .AfterStageTaskConditionApprovalRequestApproved ),
1004+ Status : metav1 .ConditionTrue ,
1005+ Reason : condition .AfterStageTaskApprovalRequestApprovedReason ,
1006+ ObservedGeneration : generation ,
1007+ },
1008+ }
1009+ }
1010+ return []metav1.Condition {
1011+ {
1012+ Type : string (placementv1beta1 .AfterStageTaskConditionWaitTimeElapsed ),
1013+ Status : metav1 .ConditionTrue ,
1014+ Reason : condition .AfterStageTaskWaitTimeElapsedReason ,
1015+ ObservedGeneration : generation ,
1016+ },
1017+ }
1018+ }
1019+
1020+ func updateRunSucceedConditions (generation int64 ) []metav1.Condition {
1021+ return []metav1.Condition {
1022+ {
1023+ Type : string (placementv1beta1 .StagedUpdateRunConditionInitialized ),
1024+ Status : metav1 .ConditionTrue ,
1025+ Reason : condition .UpdateRunInitializeSucceededReason ,
1026+ ObservedGeneration : generation ,
1027+ },
1028+ {
1029+ Type : string (placementv1beta1 .StagedUpdateRunConditionProgressing ),
1030+ Status : metav1 .ConditionTrue ,
1031+ Reason : condition .UpdateRunStartedReason ,
1032+ ObservedGeneration : generation ,
1033+ },
1034+ {
1035+ Type : string (placementv1beta1 .StagedUpdateRunConditionSucceeded ),
1036+ Status : metav1 .ConditionTrue ,
1037+ Reason : condition .UpdateRunSucceededReason ,
1038+ ObservedGeneration : generation ,
1039+ },
1040+ }
1041+ }
1042+
1043+ func updateRunStatusSucceededActual (
1044+ updateRunName string ,
1045+ wantPolicyIndex string ,
1046+ wantClusterCount int ,
1047+ wantApplyStrategy * placementv1beta1.ApplyStrategy ,
1048+ wantStrategySpec * placementv1beta1.StagedUpdateStrategySpec ,
1049+ wantSelectedClusters [][]string ,
1050+ wantUnscheduledClusters []string ,
1051+ wantCROs map [string ][]string ,
1052+ wantROs map [string ][]placementv1beta1.NamespacedName ,
1053+ ) func () error {
1054+ return func () error {
1055+ updateRun := & placementv1beta1.ClusterStagedUpdateRun {}
1056+ if err := hubClient .Get (ctx , types.NamespacedName {Name : updateRunName }, updateRun ); err != nil {
1057+ return err
1058+ }
1059+
1060+ wantStatus := placementv1beta1.StagedUpdateRunStatus {
1061+ PolicySnapshotIndexUsed : wantPolicyIndex ,
1062+ PolicyObservedClusterCount : wantClusterCount ,
1063+ ApplyStrategy : wantApplyStrategy .DeepCopy (),
1064+ StagedUpdateStrategySnapshot : wantStrategySpec ,
1065+ }
1066+ stagesStatus := make ([]placementv1beta1.StageUpdatingStatus , len (wantStrategySpec .Stages ))
1067+ for i , stage := range wantStrategySpec .Stages {
1068+ stagesStatus [i ].StageName = stage .Name
1069+ stagesStatus [i ].Clusters = make ([]placementv1beta1.ClusterUpdatingStatus , len (wantSelectedClusters [i ]))
1070+ for j := range stagesStatus [i ].Clusters {
1071+ stagesStatus [i ].Clusters [j ].ClusterName = wantSelectedClusters [i ][j ]
1072+ stagesStatus [i ].Clusters [j ].ClusterResourceOverrideSnapshots = wantCROs [wantSelectedClusters [i ][j ]]
1073+ stagesStatus [i ].Clusters [j ].ResourceOverrideSnapshots = wantROs [wantSelectedClusters [i ][j ]]
1074+ stagesStatus [i ].Clusters [j ].Conditions = updateRunClusterRolloutSucceedConditions (updateRun .Generation )
1075+ }
1076+ stagesStatus [i ].AfterStageTaskStatus = make ([]placementv1beta1.AfterStageTaskStatus , len (stage .AfterStageTasks ))
1077+ for j , task := range stage .AfterStageTasks {
1078+ stagesStatus [i ].AfterStageTaskStatus [j ].Type = task .Type
1079+ if task .Type == placementv1beta1 .AfterStageTaskTypeApproval {
1080+ stagesStatus [i ].AfterStageTaskStatus [j ].ApprovalRequestName = fmt .Sprintf (placementv1beta1 .ApprovalTaskNameFmt , updateRun .Name , stage .Name )
1081+ }
1082+ stagesStatus [i ].AfterStageTaskStatus [j ].Conditions = updateRunAfterStageTaskSucceedConditions (updateRun .Generation , task .Type )
1083+ }
1084+ stagesStatus [i ].Conditions = updateRunStageRolloutSucceedConditions (updateRun .Generation , true )
1085+ }
1086+
1087+ deleteStageStatus := & placementv1beta1.StageUpdatingStatus {
1088+ StageName : "kubernetes-fleet.io/deleteStage" ,
1089+ }
1090+ deleteStageStatus .Clusters = make ([]placementv1beta1.ClusterUpdatingStatus , len (wantUnscheduledClusters ))
1091+ for i := range deleteStageStatus .Clusters {
1092+ deleteStageStatus .Clusters [i ].ClusterName = wantUnscheduledClusters [i ]
1093+ deleteStageStatus .Clusters [i ].Conditions = updateRunClusterRolloutSucceedConditions (updateRun .Generation )
1094+ }
1095+ deleteStageStatus .Conditions = updateRunStageRolloutSucceedConditions (updateRun .Generation , false )
1096+
1097+ wantStatus .StagesStatus = stagesStatus
1098+ wantStatus .DeletionStageStatus = deleteStageStatus
1099+ wantStatus .Conditions = updateRunSucceedConditions (updateRun .Generation )
1100+ if diff := cmp .Diff (updateRun .Status , wantStatus , updateRunStatusCmpOption ... ); diff != "" {
1101+ return fmt .Errorf ("CRP status diff (-got, +want): %s" , diff )
1102+ }
1103+ return nil
1104+ }
1105+ }
1106+
1107+ func updateRunAndApprovalRequestsRemovedActual (updateRunName string ) func () error {
1108+ return func () error {
1109+ if err := hubClient .Get (ctx , types.NamespacedName {Name : updateRunName }, & placementv1beta1.ClusterStagedUpdateRun {}); ! errors .IsNotFound (err ) {
1110+ return fmt .Errorf ("UpdateRun still exists or an unexpected error occurred: %w" , err )
1111+ }
1112+
1113+ appReqList := & placementv1beta1.ClusterApprovalRequestList {}
1114+ if err := hubClient .List (ctx , appReqList , client.MatchingLabels {
1115+ placementv1beta1 .TargetUpdateRunLabel : updateRunName ,
1116+ }); err != nil {
1117+ return fmt .Errorf ("failed to list ClusterApprovalRequests: %w" , err )
1118+ }
1119+ if len (appReqList .Items ) > 0 {
1120+ return fmt .Errorf ("ClusterApprovalRequests still exist: %v" , appReqList .Items )
1121+ }
1122+ return nil
1123+ }
1124+ }
1125+
1126+ func updateRunStrategyRemovedActual (strategyName string ) func () error {
1127+ return func () error {
1128+ if err := hubClient .Get (ctx , types.NamespacedName {Name : strategyName }, & placementv1beta1.ClusterStagedUpdateStrategy {}); ! errors .IsNotFound (err ) {
1129+ return fmt .Errorf ("ClusterStagedUpdateStrategy still exists or an unexpected error occurred: %w" , err )
1130+ }
1131+ return nil
1132+ }
1133+ }
0 commit comments