From fb9d41cba9fb1a634df5dcdaeffbb808f0a14c6e Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Wed, 5 Nov 2025 13:34:18 -0800 Subject: [PATCH 01/14] update stagedUpdateRun to use latest resource snapshot if resourceIndex is unset Signed-off-by: Britania Rodriguez Reyes --- apis/placement/v1beta1/stageupdate_types.go | 2 +- pkg/controllers/updaterun/initialization.go | 42 ++++++++++++------- .../initialization_integration_test.go | 25 ++++++++++- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/apis/placement/v1beta1/stageupdate_types.go b/apis/placement/v1beta1/stageupdate_types.go index 1f03fb625..9f26b779e 100644 --- a/apis/placement/v1beta1/stageupdate_types.go +++ b/apis/placement/v1beta1/stageupdate_types.go @@ -186,8 +186,8 @@ type UpdateRunSpec struct { // The resource snapshot index of the selected resources to be updated across clusters. // The index represents a group of resource snapshots that includes all the resources a ResourcePlacement selected. - // +kubebuilder:validation:Required // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="resourceSnapshotIndex is immutable" + // +kubebuilder:validation:Optional ResourceSnapshotIndex string `json:"resourceSnapshotIndex"` // The name of the update strategy that specifies the stages and the sequence diff --git a/pkg/controllers/updaterun/initialization.go b/pkg/controllers/updaterun/initialization.go index 45a4ba48a..36443e511 100644 --- a/pkg/controllers/updaterun/initialization.go +++ b/pkg/controllers/updaterun/initialization.go @@ -469,27 +469,39 @@ func validateAfterStageTask(tasks []placementv1beta1.StageTask) error { // recordOverrideSnapshots finds all the override snapshots that are associated with each cluster and record them in the UpdateRun status. func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey types.NamespacedName, updateRun placementv1beta1.UpdateRunObj) error { + var resourceSnapshotObjs []placementv1beta1.ResourceSnapshotObj + var snapshotIndex int updateRunRef := klog.KObj(updateRun) updateRunSpec := updateRun.GetUpdateRunSpec() placementName := placementKey.Name + if updateRunSpec.ResourceSnapshotIndex != "" { + snapshotIndex, err := strconv.Atoi(updateRunSpec.ResourceSnapshotIndex) + if err != nil || snapshotIndex < 0 { + err := controller.NewUserError(fmt.Errorf("invalid resource snapshot index `%s` provided, expected an integer >= 0", updateRunSpec.ResourceSnapshotIndex)) + klog.ErrorS(err, "Failed to parse the resource snapshot index", "updateRun", updateRunRef) + // no more retries here. + return fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) + } - snapshotIndex, err := strconv.Atoi(updateRunSpec.ResourceSnapshotIndex) - if err != nil || snapshotIndex < 0 { - err := controller.NewUserError(fmt.Errorf("invalid resource snapshot index `%s` provided, expected an integer >= 0", updateRunSpec.ResourceSnapshotIndex)) - klog.ErrorS(err, "Failed to parse the resource snapshot index", "updateRun", updateRunRef) - // no more retries here. - return fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) - } - - resourceSnapshotList, err := controller.ListAllResourceSnapshotWithAnIndex(ctx, r.Client, updateRunSpec.ResourceSnapshotIndex, placementName, placementKey.Namespace) - if err != nil { - klog.ErrorS(err, "Failed to list the resourceSnapshots associated with the placement", - "placement", placementKey, "resourceSnapshotIndex", snapshotIndex, "updateRun", updateRunRef) - // err can be retried. - return controller.NewAPIServerError(true, err) + resourceSnapshotList, err := controller.ListAllResourceSnapshotWithAnIndex(ctx, r.Client, updateRunSpec.ResourceSnapshotIndex, placementName, placementKey.Namespace) + if err != nil { + klog.ErrorS(err, "Failed to list the resourceSnapshots associated with the placement", + "placement", placementKey, "resourceSnapshotIndex", snapshotIndex, "updateRun", updateRunRef) + // err can be retried. + return controller.NewAPIServerError(true, err) + } + resourceSnapshotObjs = resourceSnapshotList.GetResourceSnapshotObjs() + } else { + latestResourceSnapshot, err := controller.ListLatestResourceSnapshots(ctx, r.Client, placementKey) + if err != nil { + klog.ErrorS(err, "Failed to list the latest resourceSnapshots associated with the placement", + "placement", placementKey, "updateRun", updateRunRef) + // err can be retried. + return controller.NewAPIServerError(true, err) + } + resourceSnapshotObjs = latestResourceSnapshot.GetResourceSnapshotObjs() } - resourceSnapshotObjs := resourceSnapshotList.GetResourceSnapshotObjs() if len(resourceSnapshotObjs) == 0 { err := controller.NewUserError(fmt.Errorf("no resourceSnapshots with index `%d` found for placement `%s`", snapshotIndex, placementKey)) klog.ErrorS(err, "No specified resourceSnapshots found", "updateRun", updateRunRef) diff --git a/pkg/controllers/updaterun/initialization_integration_test.go b/pkg/controllers/updaterun/initialization_integration_test.go index 8bfab157a..2406393de 100644 --- a/pkg/controllers/updaterun/initialization_integration_test.go +++ b/pkg/controllers/updaterun/initialization_integration_test.go @@ -748,7 +748,7 @@ var _ = Describe("Updaterun initialization tests", func() { Expect(k8sClient.Create(ctx, updateStrategy)).To(Succeed()) }) - It("Should fail to initialize if the specified resource snapshot index is invalid - not integer", func() { + FIt("Should fail to initialize if the specified resource snapshot index is invalid - not integer", func() { By("Creating a new clusterStagedUpdateRun with invalid resource snapshot index") updateRun.Spec.ResourceSnapshotIndex = "invalid-index" Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) @@ -828,6 +828,29 @@ var _ = Describe("Updaterun initialization tests", func() { validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) }) + It("Should put related ClusterResourceOverrides in the status with no resource index defined", func() { + By("Creating a new resource snapshot") + Expect(k8sClient.Create(ctx, resourceSnapshot)).To(Succeed()) + + By("Creating a new cluster resource override") + Expect(k8sClient.Create(ctx, clusterResourceOverride)).To(Succeed()) + + By("Creating a new clusterStagedUpdateRun") + updateRun.Spec.ResourceSnapshotIndex = "" + Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) + + By("Validating the clusterStagedUpdateRun stats") + initialized := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) + want := generateExecutionStartedStatus(updateRun, initialized) + validateClusterStagedUpdateRunStatus(ctx, updateRun, want, "") + + By("Validating the clusterStagedUpdateRun initialized consistently") + validateClusterStagedUpdateRunStatusConsistently(ctx, updateRun, want, "") + + By("Checking update run status metrics are emitted") + validateUpdateRunMetricsEmitted(generateProgressingMetric(updateRun)) + }) + It("Should put related ClusterResourceOverrides in the status", func() { By("Creating a new resource snapshot") Expect(k8sClient.Create(ctx, resourceSnapshot)).To(Succeed()) From 7d1ae1622473fd3932eab2204a8bff560910a9e4 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Wed, 5 Nov 2025 15:37:49 -0800 Subject: [PATCH 02/14] fix UT Signed-off-by: Britania Rodriguez Reyes --- pkg/controllers/updaterun/initialization_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controllers/updaterun/initialization_integration_test.go b/pkg/controllers/updaterun/initialization_integration_test.go index 2406393de..0aec57df9 100644 --- a/pkg/controllers/updaterun/initialization_integration_test.go +++ b/pkg/controllers/updaterun/initialization_integration_test.go @@ -748,7 +748,7 @@ var _ = Describe("Updaterun initialization tests", func() { Expect(k8sClient.Create(ctx, updateStrategy)).To(Succeed()) }) - FIt("Should fail to initialize if the specified resource snapshot index is invalid - not integer", func() { + It("Should fail to initialize if the specified resource snapshot index is invalid - not integer", func() { By("Creating a new clusterStagedUpdateRun with invalid resource snapshot index") updateRun.Spec.ResourceSnapshotIndex = "invalid-index" Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) From 8b4b5fdc1a544f6025fc2c65e82aefac5cfc2e75 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Thu, 6 Nov 2025 17:00:24 -0800 Subject: [PATCH 03/14] address comments Signed-off-by: Britania Rodriguez Reyes --- apis/placement/v1beta1/stageupdate_types.go | 4 + ...etes-fleet.io_clusterstagedupdateruns.yaml | 5 +- ....kubernetes-fleet.io_stagedupdateruns.yaml | 5 +- pkg/controllers/updaterun/execution.go | 6 +- pkg/controllers/updaterun/initialization.go | 76 +++++++++++-------- .../initialization_integration_test.go | 12 ++- 6 files changed, 66 insertions(+), 42 deletions(-) diff --git a/apis/placement/v1beta1/stageupdate_types.go b/apis/placement/v1beta1/stageupdate_types.go index 9f26b779e..73d815903 100644 --- a/apis/placement/v1beta1/stageupdate_types.go +++ b/apis/placement/v1beta1/stageupdate_types.go @@ -374,6 +374,10 @@ type UpdateRunStatus struct { // +kubebuilder:validation:Optional PolicyObservedClusterCount int `json:"policyObservedClusterCount,omitempty"` + // ResourceSnapshotName records the name of the resource snapshot that the update run is based on. + // +kubebuilder:validation:Optional + ResourceSnapshotName string `json:"resourceSnapshotName,omitempty"` + // ApplyStrategy is the apply strategy that the stagedUpdateRun is using. // It is the same as the apply strategy in the CRP when the staged update run starts. // The apply strategy is not updated during the update run even if it changes in the CRP. diff --git a/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml b/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml index bf75d613d..c36fbc525 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml @@ -1200,7 +1200,6 @@ spec: type: string required: - placementName - - resourceSnapshotIndex - stagedRolloutStrategyName type: object x-kubernetes-validations: @@ -1895,6 +1894,10 @@ spec: All clusters involved in the update run are selected from the list of clusters scheduled by the CRP according to the current policy. type: string + resourceSnapshotName: + description: ResourceSnapshotName records the name of the resource + snapshot that the update run is based on. + type: string stagedUpdateStrategySnapshot: description: |- UpdateStrategySnapshot is the snapshot of the UpdateStrategy used for the update run. diff --git a/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml b/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml index 10fe5f738..0c7a7e869 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml @@ -120,7 +120,6 @@ spec: type: string required: - placementName - - resourceSnapshotIndex - stagedRolloutStrategyName type: object x-kubernetes-validations: @@ -815,6 +814,10 @@ spec: All clusters involved in the update run are selected from the list of clusters scheduled by the CRP according to the current policy. type: string + resourceSnapshotName: + description: ResourceSnapshotName records the name of the resource + snapshot that the update run is based on. + type: string stagedUpdateStrategySnapshot: description: |- UpdateStrategySnapshot is the snapshot of the UpdateStrategy used for the update run. diff --git a/pkg/controllers/updaterun/execution.go b/pkg/controllers/updaterun/execution.go index c69e34f11..948f93654 100644 --- a/pkg/controllers/updaterun/execution.go +++ b/pkg/controllers/updaterun/execution.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "reflect" - "strconv" "time" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -93,11 +92,8 @@ func (r *Reconciler) executeUpdatingStage( toBeUpdatedBindings []placementv1beta1.BindingObj, ) (time.Duration, error) { updateRunStatus := updateRun.GetUpdateRunStatus() - updateRunSpec := updateRun.GetUpdateRunSpec() updatingStageStatus := &updateRunStatus.StagesStatus[updatingStageIndex] - // The parse error is ignored because the initialization should have caught it. - resourceIndex, _ := strconv.Atoi(updateRunSpec.ResourceSnapshotIndex) - resourceSnapshotName := fmt.Sprintf(placementv1beta1.ResourceSnapshotNameFmt, updateRunSpec.PlacementName, resourceIndex) + resourceSnapshotName := updateRunStatus.ResourceSnapshotName updateRunRef := klog.KObj(updateRun) // Create the map of the toBeUpdatedBindings. toBeUpdatedBindingsMap := make(map[string]placementv1beta1.BindingObj, len(toBeUpdatedBindings)) diff --git a/pkg/controllers/updaterun/initialization.go b/pkg/controllers/updaterun/initialization.go index 36443e511..756dc27ab 100644 --- a/pkg/controllers/updaterun/initialization.go +++ b/pkg/controllers/updaterun/initialization.go @@ -469,42 +469,18 @@ func validateAfterStageTask(tasks []placementv1beta1.StageTask) error { // recordOverrideSnapshots finds all the override snapshots that are associated with each cluster and record them in the UpdateRun status. func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey types.NamespacedName, updateRun placementv1beta1.UpdateRunObj) error { - var resourceSnapshotObjs []placementv1beta1.ResourceSnapshotObj - var snapshotIndex int updateRunRef := klog.KObj(updateRun) updateRunSpec := updateRun.GetUpdateRunSpec() placementName := placementKey.Name - if updateRunSpec.ResourceSnapshotIndex != "" { - snapshotIndex, err := strconv.Atoi(updateRunSpec.ResourceSnapshotIndex) - if err != nil || snapshotIndex < 0 { - err := controller.NewUserError(fmt.Errorf("invalid resource snapshot index `%s` provided, expected an integer >= 0", updateRunSpec.ResourceSnapshotIndex)) - klog.ErrorS(err, "Failed to parse the resource snapshot index", "updateRun", updateRunRef) - // no more retries here. - return fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) - } - resourceSnapshotList, err := controller.ListAllResourceSnapshotWithAnIndex(ctx, r.Client, updateRunSpec.ResourceSnapshotIndex, placementName, placementKey.Namespace) - if err != nil { - klog.ErrorS(err, "Failed to list the resourceSnapshots associated with the placement", - "placement", placementKey, "resourceSnapshotIndex", snapshotIndex, "updateRun", updateRunRef) - // err can be retried. - return controller.NewAPIServerError(true, err) - } - resourceSnapshotObjs = resourceSnapshotList.GetResourceSnapshotObjs() - } else { - latestResourceSnapshot, err := controller.ListLatestResourceSnapshots(ctx, r.Client, placementKey) - if err != nil { - klog.ErrorS(err, "Failed to list the latest resourceSnapshots associated with the placement", - "placement", placementKey, "updateRun", updateRunRef) - // err can be retried. - return controller.NewAPIServerError(true, err) - } - resourceSnapshotObjs = latestResourceSnapshot.GetResourceSnapshotObjs() + resourceSnapshotObjs, err := r.getResourceSnapshotObjs(ctx, updateRunSpec, placementName, placementKey, updateRunRef) + if err != nil { + return err } if len(resourceSnapshotObjs) == 0 { - err := controller.NewUserError(fmt.Errorf("no resourceSnapshots with index `%d` found for placement `%s`", snapshotIndex, placementKey)) - klog.ErrorS(err, "No specified resourceSnapshots found", "updateRun", updateRunRef) + err := controller.NewUserError(fmt.Errorf("no resourceSnapshots found for placement `%s`", placementKey)) + klog.ErrorS(err, "No resourceSnapshots found", "updateRun", updateRunRef) // no more retries here. return fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) } @@ -518,15 +494,23 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t break } } - // No masterResourceSnapshot found. if masterResourceSnapshot == nil { - err := controller.NewUnexpectedBehaviorError(fmt.Errorf("no master resourceSnapshot found for placement `%s` with index `%d`", placementKey, snapshotIndex)) + err := controller.NewUnexpectedBehaviorError(fmt.Errorf("no master resourceSnapshot found for placement %s", placementKey)) klog.ErrorS(err, "Failed to find master resourceSnapshot", "updateRun", updateRunRef) // no more retries here. return fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) } - klog.V(2).InfoS("Found master resourceSnapshot", "placement", placementKey, "index", snapshotIndex, "updateRun", updateRunRef) + + klog.InfoS("Found master resourceSnapshot", "placement", placementKey, "index", updateRun.GetUpdateRunSpec().ResourceSnapshotIndex, "updateRun", updateRunRef) + + // Update the resource snapshot name in the UpdateRun status. + updateRun.GetUpdateRunStatus().ResourceSnapshotName = masterResourceSnapshot.GetName() + if updateErr := r.Client.Status().Update(ctx, updateRun); updateErr != nil { + klog.ErrorS(updateErr, "Failed to update the UpdateRun status with resource snapshot name", "updateRun", klog.KObj(updateRun), "resourceSnapshot", klog.KObj(masterResourceSnapshot)) + // updateErr can be retried. + return controller.NewUpdateIgnoreConflictError(updateErr) + } resourceSnapshotRef := klog.KObj(masterResourceSnapshot) // Fetch all the matching overrides. @@ -555,6 +539,34 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t return nil } +// getResourceSnapshotObjs retrieves the resource snapshot objects either by index or latest snapshots. +func (r *Reconciler) getResourceSnapshotObjs(ctx context.Context, updateRunSpec *placementv1beta1.UpdateRunSpec, placementName string, placementKey types.NamespacedName, updateRunRef klog.ObjectRef) ([]placementv1beta1.ResourceSnapshotObj, error) { + if updateRunSpec.ResourceSnapshotIndex != "" { + snapshotIndex, err := strconv.Atoi(updateRunSpec.ResourceSnapshotIndex) + if err != nil || snapshotIndex < 0 { + err := controller.NewUserError(fmt.Errorf("invalid resource snapshot index `%s` provided, expected an integer >= 0", updateRunSpec.ResourceSnapshotIndex)) + klog.ErrorS(err, "Failed to parse the resource snapshot index", "updateRun", updateRunRef) + return nil, fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) + } + + resourceSnapshotList, err := controller.ListAllResourceSnapshotWithAnIndex(ctx, r.Client, updateRunSpec.ResourceSnapshotIndex, placementName, placementKey.Namespace) + if err != nil { + klog.ErrorS(err, "Failed to list the resourceSnapshots associated with the placement", + "placement", placementKey, "resourceSnapshotIndex", snapshotIndex, "updateRun", updateRunRef) + return nil, controller.NewAPIServerError(true, err) + } + return resourceSnapshotList.GetResourceSnapshotObjs(), nil + } + + latestResourceSnapshots, err := controller.ListLatestResourceSnapshots(ctx, r.Client, placementKey) + if err != nil { + klog.ErrorS(err, "Failed to list the latest resourceSnapshots associated with the placement", + "placement", placementKey, "updateRun", updateRunRef) + return nil, controller.NewAPIServerError(true, err) + } + return latestResourceSnapshots.GetResourceSnapshotObjs(), nil +} + // recordInitializationSucceeded records the successful initialization condition in the UpdateRun status. func (r *Reconciler) recordInitializationSucceeded(ctx context.Context, updateRun placementv1beta1.UpdateRunObj) error { updateRunStatus := updateRun.GetUpdateRunStatus() diff --git a/pkg/controllers/updaterun/initialization_integration_test.go b/pkg/controllers/updaterun/initialization_integration_test.go index 0aec57df9..b38a80443 100644 --- a/pkg/controllers/updaterun/initialization_integration_test.go +++ b/pkg/controllers/updaterun/initialization_integration_test.go @@ -655,6 +655,7 @@ var _ = Describe("Updaterun initialization tests", func() { } want := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) + want.ResourceSnapshotName = "" // resourceSnapshot not created in this test // No clusters should be selected in the first stage. want.StagesStatus[0].Clusters = []placementv1beta1.ClusterUpdatingStatus{} // All clusters should be selected in the second stage and sorted by name. @@ -697,6 +698,7 @@ var _ = Describe("Updaterun initialization tests", func() { } want := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) + want.ResourceSnapshotName = "" // resourceSnapshot not created in this test for i := range want.StagesStatus[0].Clusters { // Remove the CROs, as they are not added in this test. want.StagesStatus[0].Clusters[i].ClusterResourceOverrideSnapshots = nil @@ -777,7 +779,7 @@ var _ = Describe("Updaterun initialization tests", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization failed") - validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots with index `0` found") + validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots found for placement") By("Checking update run status metrics are emitted") validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) @@ -792,7 +794,7 @@ var _ = Describe("Updaterun initialization tests", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization failed") - validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots with index `0` found") + validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots found for placement") By("Checking update run status metrics are emitted") validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) @@ -807,7 +809,7 @@ var _ = Describe("Updaterun initialization tests", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization failed") - validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots with index `0` found") + validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots found for placement") By("Checking update run status metrics are emitted") validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) @@ -841,6 +843,7 @@ var _ = Describe("Updaterun initialization tests", func() { By("Validating the clusterStagedUpdateRun stats") initialized := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) + initialized.ResourceSnapshotName = testResourceSnapshotName want := generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, want, "") @@ -863,6 +866,7 @@ var _ = Describe("Updaterun initialization tests", func() { By("Validating the clusterStagedUpdateRun stats") initialized := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) + initialized.ResourceSnapshotName = testResourceSnapshotName want := generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, want, "") @@ -902,6 +906,7 @@ func generateSucceededInitializationStatus( status := &placementv1beta1.UpdateRunStatus{ PolicySnapshotIndexUsed: policySnapshot.Labels[placementv1beta1.PolicyIndexLabel], PolicyObservedClusterCount: 10, + ResourceSnapshotName: testResourceSnapshotName, ApplyStrategy: crp.Spec.Strategy.ApplyStrategy.DeepCopy(), UpdateStrategySnapshot: &updateStrategy.Spec, StagesStatus: []placementv1beta1.StageUpdatingStatus{ @@ -962,6 +967,7 @@ func generateSucceededInitializationStatusForSmallClusters( status := &placementv1beta1.UpdateRunStatus{ PolicySnapshotIndexUsed: policySnapshot.Labels[placementv1beta1.PolicyIndexLabel], PolicyObservedClusterCount: 3, + ResourceSnapshotName: testResourceSnapshotName, ApplyStrategy: crp.Spec.Strategy.ApplyStrategy.DeepCopy(), UpdateStrategySnapshot: &updateStrategy.Spec, StagesStatus: []placementv1beta1.StageUpdatingStatus{ From edc85552d4ea00a092c68dd06fcdc820d438a1ff Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Mon, 10 Nov 2025 12:18:51 -0800 Subject: [PATCH 04/14] fix some e2es Signed-off-by: Britania Rodriguez Reyes --- test/e2e/actuals_test.go | 5 ++- test/e2e/cluster_staged_updaterun_test.go | 40 ++++++++++++----------- test/e2e/staged_updaterun_test.go | 26 +++++++-------- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/test/e2e/actuals_test.go b/test/e2e/actuals_test.go index 889f1abe3..51ee76a9e 100644 --- a/test/e2e/actuals_test.go +++ b/test/e2e/actuals_test.go @@ -2092,6 +2092,7 @@ func updateRunSucceedConditions(generation int64) []metav1.Condition { func clusterStagedUpdateRunStatusSucceededActual( updateRunName string, + wantResourceSnapshotName string, wantPolicyIndex string, wantClusterCount int, wantApplyStrategy *placementv1beta1.ApplyStrategy, @@ -2109,6 +2110,7 @@ func clusterStagedUpdateRunStatusSucceededActual( wantStatus := placementv1beta1.UpdateRunStatus{ PolicySnapshotIndexUsed: wantPolicyIndex, + ResourceSnapshotName: wantResourceSnapshotName, PolicyObservedClusterCount: wantClusterCount, ApplyStrategy: wantApplyStrategy.DeepCopy(), UpdateStrategySnapshot: wantStrategySpec, @@ -2125,7 +2127,7 @@ func clusterStagedUpdateRunStatusSucceededActual( } func stagedUpdateRunStatusSucceededActual( - updateRunName, namespace string, + updateRunName, namespace, wantResourceSnapshotName string, wantPolicyIndex string, wantClusterCount int, wantApplyStrategy *placementv1beta1.ApplyStrategy, @@ -2143,6 +2145,7 @@ func stagedUpdateRunStatusSucceededActual( wantStatus := placementv1beta1.UpdateRunStatus{ PolicySnapshotIndexUsed: wantPolicyIndex, + ResourceSnapshotName: wantResourceSnapshotName, PolicyObservedClusterCount: wantClusterCount, ApplyStrategy: wantApplyStrategy.DeepCopy(), UpdateStrategySnapshot: wantStrategySpec, diff --git a/test/e2e/cluster_staged_updaterun_test.go b/test/e2e/cluster_staged_updaterun_test.go index 9880c2eef..da1c05001 100644 --- a/test/e2e/cluster_staged_updaterun_test.go +++ b/test/e2e/cluster_staged_updaterun_test.go @@ -46,6 +46,8 @@ const ( policySnapshotIndex3rd = "2" testConfigMapDataValue = "new" + + testResourceSnapshotNameTmpl = "%s-%s-snapshot" ) var ( @@ -149,7 +151,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to all the members and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -214,7 +216,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-1 and member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) By("Verify that new the configmap is updated on all member clusters") for idx := range allMemberClusters { @@ -252,7 +254,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollback resources to member-cluster-1 and member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], "", policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) for idx := range allMemberClusters { configMapActual := configMapPlacedOnClusterActual(allMemberClusters[idx], &oldConfigMap) @@ -348,7 +350,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-1 too but not member-cluster-3 and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) checkIfRemovedWorkResourcesFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[2]}) @@ -398,7 +400,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -445,7 +447,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { It("Should remove resources on member-cluster-1 and member-cluster-2 and complete the cluster staged update run successfully", func() { // need to go through two stages - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], "", policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) Eventually(csurSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[2]) checkIfRemovedWorkResourcesFromMemberClusters([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[2]}) @@ -537,7 +539,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-3 and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], policySnapshotIndex1st, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[2]}) checkIfRemovedWorkResourcesFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) @@ -586,7 +588,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-1 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -632,7 +634,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should remove resources on member-cluster-1 and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], "", policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) Eventually(csurSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[2]) checkIfRemovedWorkResourcesFromMemberClusters([]*framework.Cluster{allMemberClusters[0]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[1], allMemberClusters[2]}) @@ -804,7 +806,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-1 and member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, wantCROs, wantROs) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, wantCROs, wantROs) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -904,7 +906,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should report diff for member-cluster-1 and member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, policySnapshotIndex1st, len(allMemberClusters), applyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), applyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunName) }) @@ -1015,7 +1017,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { validateAndApproveClusterApprovalRequests(updateRunName, envCanary) // Verify complete rollout - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunName) // Verify new configmap is on all member clusters @@ -1141,7 +1143,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should complete the staged update run after approval", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -1214,7 +1216,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { validateAndApproveClusterApprovalRequests(updateRunName, envCanary) - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) @@ -1340,7 +1342,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label createClusterStagedUpdateRunSucceed(updateRunNames[0], crpName, resourceSnapshotIndex1st, strategyName) By("Validating staged update run has succeeded") - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) By("Validating CRP status as completed") @@ -1392,7 +1394,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the second staged update run and complete the CRP", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1], allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1], allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex1st, true, allMemberClusterNames[1:], @@ -1440,7 +1442,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the staged update run, complete CRP, and rollout resources to all member clusters", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex1st, true, allMemberClusterNames, @@ -1483,7 +1485,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the staged update run, complete CRP, and rollout updated resources to all member clusters", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex2nd, true, allMemberClusterNames, @@ -1522,7 +1524,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the staged update run, complete CRP, and re-place resources to all member clusters", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex1st, true, allMemberClusterNames, diff --git a/test/e2e/staged_updaterun_test.go b/test/e2e/staged_updaterun_test.go index b5a5428b1..8d0a17d98 100644 --- a/test/e2e/staged_updaterun_test.go +++ b/test/e2e/staged_updaterun_test.go @@ -142,7 +142,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to all the members and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -207,7 +207,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[1]) By("Verify that new the configmap is updated on all member clusters") for idx := range allMemberClusters { @@ -245,7 +245,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollback resources to member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, "", policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) for idx := range allMemberClusters { configMapActual := configMapPlacedOnClusterActual(allMemberClusters[idx], &oldConfigMap) @@ -339,7 +339,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 too but not member-cluster-3 and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) checkIfRemovedConfigMapFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[2]}) @@ -389,7 +389,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, "", policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -436,7 +436,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem It("Should remove resources on member-cluster-1 and member-cluster-2 and complete the staged update run successfully", func() { // need to go through two stages - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, "", policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) Eventually(surSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[2]) checkIfRemovedConfigMapFromMemberClusters([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[2]}) @@ -526,7 +526,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-3 and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, policySnapshotIndex1st, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[2]}) checkIfRemovedConfigMapFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) @@ -575,7 +575,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, "", policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -621,7 +621,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should remove resources on member-cluster-1 and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, "", policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) Eventually(surSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[2]) checkIfRemovedConfigMapFromMemberClusters([]*framework.Cluster{allMemberClusters[0]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[1], allMemberClusters[2]}) @@ -766,7 +766,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, wantROs) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, "", policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, wantROs) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -860,7 +860,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should report diff for member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, policySnapshotIndex1st, len(allMemberClusters), applyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), applyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) }) @@ -969,7 +969,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem validateAndApproveNamespacedApprovalRequests(updateRunName, testNamespace, envCanary) // Verify complete rollout. - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) // Verify new configmap is on all member clusters. @@ -1045,7 +1045,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem validateAndApproveNamespacedApprovalRequests(updateRunName, testNamespace, envCanary) - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) From 7607c58029bc2581b2795b46e6f5bfdd3f786b40 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Mon, 10 Nov 2025 15:06:38 -0800 Subject: [PATCH 05/14] fix the rest of the e2es Signed-off-by: Britania Rodriguez Reyes --- test/e2e/cluster_staged_updaterun_test.go | 16 +++++++------- test/e2e/staged_updaterun_test.go | 26 +++++++++++------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/test/e2e/cluster_staged_updaterun_test.go b/test/e2e/cluster_staged_updaterun_test.go index da1c05001..c6b529c49 100644 --- a/test/e2e/cluster_staged_updaterun_test.go +++ b/test/e2e/cluster_staged_updaterun_test.go @@ -216,7 +216,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-1 and member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) By("Verify that new the configmap is updated on all member clusters") for idx := range allMemberClusters { @@ -254,7 +254,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollback resources to member-cluster-1 and member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], "", policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) for idx := range allMemberClusters { configMapActual := configMapPlacedOnClusterActual(allMemberClusters[idx], &oldConfigMap) @@ -400,7 +400,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -447,7 +447,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { It("Should remove resources on member-cluster-1 and member-cluster-2 and complete the cluster staged update run successfully", func() { // need to go through two stages - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], "", policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) Eventually(csurSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[2]) checkIfRemovedWorkResourcesFromMemberClusters([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[2]}) @@ -588,7 +588,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-1 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -634,7 +634,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should remove resources on member-cluster-1 and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], "", policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) Eventually(csurSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[2]) checkIfRemovedWorkResourcesFromMemberClusters([]*framework.Cluster{allMemberClusters[0]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[1], allMemberClusters[2]}) @@ -1394,7 +1394,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the second staged update run and complete the CRP", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1], allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1], allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex1st, true, allMemberClusterNames[1:], @@ -1442,7 +1442,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the staged update run, complete CRP, and rollout resources to all member clusters", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex1st, true, allMemberClusterNames, diff --git a/test/e2e/staged_updaterun_test.go b/test/e2e/staged_updaterun_test.go index 8d0a17d98..8a0227cd3 100644 --- a/test/e2e/staged_updaterun_test.go +++ b/test/e2e/staged_updaterun_test.go @@ -142,7 +142,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to all the members and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -207,7 +207,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[1]) By("Verify that new the configmap is updated on all member clusters") for idx := range allMemberClusters { @@ -245,7 +245,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollback resources to member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, "", policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) for idx := range allMemberClusters { configMapActual := configMapPlacedOnClusterActual(allMemberClusters[idx], &oldConfigMap) @@ -339,7 +339,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 too but not member-cluster-3 and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) checkIfRemovedConfigMapFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[2]}) @@ -389,7 +389,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, "", policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -436,7 +436,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem It("Should remove resources on member-cluster-1 and member-cluster-2 and complete the staged update run successfully", func() { // need to go through two stages - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, "", policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) Eventually(surSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[2]) checkIfRemovedConfigMapFromMemberClusters([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[2]}) @@ -526,7 +526,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-3 and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[2]}) checkIfRemovedConfigMapFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) @@ -575,7 +575,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, "", policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -621,7 +621,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should remove resources on member-cluster-1 and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, "", policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) Eventually(surSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[2]) checkIfRemovedConfigMapFromMemberClusters([]*framework.Cluster{allMemberClusters[0]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[1], allMemberClusters[2]}) @@ -766,7 +766,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, "", policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, wantROs) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, wantROs) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -860,7 +860,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should report diff for member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), applyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), applyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) }) @@ -969,7 +969,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem validateAndApproveNamespacedApprovalRequests(updateRunName, testNamespace, envCanary) // Verify complete rollout. - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) // Verify new configmap is on all member clusters. @@ -1045,7 +1045,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem validateAndApproveNamespacedApprovalRequests(updateRunName, testNamespace, envCanary) - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) From 734d82c48309da81b7bc8cc72943d4786e066fa5 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Mon, 10 Nov 2025 15:25:34 -0800 Subject: [PATCH 06/14] minor fix Signed-off-by: Britania Rodriguez Reyes --- test/e2e/cluster_staged_updaterun_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/cluster_staged_updaterun_test.go b/test/e2e/cluster_staged_updaterun_test.go index c6b529c49..c1a7ae7c4 100644 --- a/test/e2e/cluster_staged_updaterun_test.go +++ b/test/e2e/cluster_staged_updaterun_test.go @@ -1485,7 +1485,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the staged update run, complete CRP, and rollout updated resources to all member clusters", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex2nd, true, allMemberClusterNames, @@ -1524,7 +1524,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the staged update run, complete CRP, and re-place resources to all member clusters", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], "", policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex1st, true, allMemberClusterNames, From 1b86e4306699bb537722558ac18924a4ccd3d442 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Mon, 10 Nov 2025 20:46:50 -0800 Subject: [PATCH 07/14] address comments Signed-off-by: Britania Rodriguez Reyes --- apis/placement/v1beta1/stageupdate_types.go | 2 +- .../v1beta1/zz_generated.deepcopy.go | 2 +- ...etes-fleet.io_clusterstagedupdateruns.yaml | 2 +- ....kubernetes-fleet.io_stagedupdateruns.yaml | 2 +- pkg/controllers/updaterun/initialization.go | 39 ++++++---- .../initialization_integration_test.go | 74 +++++++++++++++++++ 6 files changed, 104 insertions(+), 17 deletions(-) diff --git a/apis/placement/v1beta1/stageupdate_types.go b/apis/placement/v1beta1/stageupdate_types.go index 73d815903..0831027a7 100644 --- a/apis/placement/v1beta1/stageupdate_types.go +++ b/apis/placement/v1beta1/stageupdate_types.go @@ -374,7 +374,7 @@ type UpdateRunStatus struct { // +kubebuilder:validation:Optional PolicyObservedClusterCount int `json:"policyObservedClusterCount,omitempty"` - // ResourceSnapshotName records the name of the resource snapshot that the update run is based on. + // ResourceSnapshotName records the name of the master resource snapshot that the update run is based on. // +kubebuilder:validation:Optional ResourceSnapshotName string `json:"resourceSnapshotName,omitempty"` diff --git a/apis/placement/v1beta1/zz_generated.deepcopy.go b/apis/placement/v1beta1/zz_generated.deepcopy.go index b9ff2e710..73d66c8fa 100644 --- a/apis/placement/v1beta1/zz_generated.deepcopy.go +++ b/apis/placement/v1beta1/zz_generated.deepcopy.go @@ -21,7 +21,7 @@ limitations under the License. package v1beta1 import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml b/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml index c36fbc525..37324c1ce 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml @@ -1895,7 +1895,7 @@ spec: to the current policy. type: string resourceSnapshotName: - description: ResourceSnapshotName records the name of the resource + description: ResourceSnapshotName records the name of the master resource snapshot that the update run is based on. type: string stagedUpdateStrategySnapshot: diff --git a/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml b/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml index 0c7a7e869..809ae55df 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml @@ -815,7 +815,7 @@ spec: to the current policy. type: string resourceSnapshotName: - description: ResourceSnapshotName records the name of the resource + description: ResourceSnapshotName records the name of the master resource snapshot that the update run is based on. type: string stagedUpdateStrategySnapshot: diff --git a/pkg/controllers/updaterun/initialization.go b/pkg/controllers/updaterun/initialization.go index 756dc27ab..29ba03ef0 100644 --- a/pkg/controllers/updaterun/initialization.go +++ b/pkg/controllers/updaterun/initialization.go @@ -478,19 +478,13 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t return err } - if len(resourceSnapshotObjs) == 0 { - err := controller.NewUserError(fmt.Errorf("no resourceSnapshots found for placement `%s`", placementKey)) - klog.ErrorS(err, "No resourceSnapshots found", "updateRun", updateRunRef) - // no more retries here. - return fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) - } - // Look for the master resourceSnapshot. var masterResourceSnapshot placementv1beta1.ResourceSnapshotObj for _, resourceSnapshot := range resourceSnapshotObjs { // only master has this annotation. if len(resourceSnapshot.GetAnnotations()[placementv1beta1.ResourceGroupHashAnnotation]) != 0 { masterResourceSnapshot = resourceSnapshot + break } } @@ -502,10 +496,12 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t return fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) } - klog.InfoS("Found master resourceSnapshot", "placement", placementKey, "index", updateRun.GetUpdateRunSpec().ResourceSnapshotIndex, "updateRun", updateRunRef) + klog.InfoS("Found master resourceSnapshot", "placement", placementKey, "masterResourceSnapshot", masterResourceSnapshot.GetName(), "updateRun", updateRunRef) // Update the resource snapshot name in the UpdateRun status. - updateRun.GetUpdateRunStatus().ResourceSnapshotName = masterResourceSnapshot.GetName() + updateRunStatus := updateRun.GetUpdateRunStatus() + updateRunStatus.ResourceSnapshotName = masterResourceSnapshot.GetName() + updateRun.SetUpdateRunStatus(*updateRunStatus) if updateErr := r.Client.Status().Update(ctx, updateRun); updateErr != nil { klog.ErrorS(updateErr, "Failed to update the UpdateRun status with resource snapshot name", "updateRun", klog.KObj(updateRun), "resourceSnapshot", klog.KObj(masterResourceSnapshot)) // updateErr can be retried. @@ -522,7 +518,6 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t } // Pick the overrides associated with each target cluster. - updateRunStatus := updateRun.GetUpdateRunStatus() for _, stageStatus := range updateRunStatus.StagesStatus { for i := range stageStatus.Clusters { clusterStatus := &stageStatus.Clusters[i] @@ -539,8 +534,10 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t return nil } -// getResourceSnapshotObjs retrieves the resource snapshot objects either by index or latest snapshots. +// getResourceSnapshotObjs retrieves the list of resource snapshot objects from the specified ResourceSnapshotIndex. +// If ResourceSnapshotIndex is unspecified, it returns the list of latest resource snapshots. func (r *Reconciler) getResourceSnapshotObjs(ctx context.Context, updateRunSpec *placementv1beta1.UpdateRunSpec, placementName string, placementKey types.NamespacedName, updateRunRef klog.ObjectRef) ([]placementv1beta1.ResourceSnapshotObj, error) { + var resourceSnapshotObjs []placementv1beta1.ResourceSnapshotObj if updateRunSpec.ResourceSnapshotIndex != "" { snapshotIndex, err := strconv.Atoi(updateRunSpec.ResourceSnapshotIndex) if err != nil || snapshotIndex < 0 { @@ -555,7 +552,15 @@ func (r *Reconciler) getResourceSnapshotObjs(ctx context.Context, updateRunSpec "placement", placementKey, "resourceSnapshotIndex", snapshotIndex, "updateRun", updateRunRef) return nil, controller.NewAPIServerError(true, err) } - return resourceSnapshotList.GetResourceSnapshotObjs(), nil + + resourceSnapshotObjs = resourceSnapshotList.GetResourceSnapshotObjs() + if len(resourceSnapshotObjs) == 0 { + err := controller.NewUserError(fmt.Errorf("no resourceSnapshots with index `%d` found for placement `%s`", snapshotIndex, placementKey)) + klog.ErrorS(err, "No specified resourceSnapshots found", "updateRun", updateRunRef) + // no more retries here. + return resourceSnapshotObjs, fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) + } + return resourceSnapshotObjs, nil } latestResourceSnapshots, err := controller.ListLatestResourceSnapshots(ctx, r.Client, placementKey) @@ -564,7 +569,15 @@ func (r *Reconciler) getResourceSnapshotObjs(ctx context.Context, updateRunSpec "placement", placementKey, "updateRun", updateRunRef) return nil, controller.NewAPIServerError(true, err) } - return latestResourceSnapshots.GetResourceSnapshotObjs(), nil + + resourceSnapshotObjs = latestResourceSnapshots.GetResourceSnapshotObjs() + if len(resourceSnapshotObjs) == 0 { + err := controller.NewUserError(fmt.Errorf("no resourceSnapshots found for placement `%s`", placementKey)) + klog.ErrorS(err, "No resourceSnapshots found", "updateRun", updateRunRef) + // no more retries here. + return resourceSnapshotObjs, fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) + } + return resourceSnapshotObjs, nil } // recordInitializationSucceeded records the successful initialization condition in the UpdateRun status. diff --git a/pkg/controllers/updaterun/initialization_integration_test.go b/pkg/controllers/updaterun/initialization_integration_test.go index b38a80443..c2d9a6095 100644 --- a/pkg/controllers/updaterun/initialization_integration_test.go +++ b/pkg/controllers/updaterun/initialization_integration_test.go @@ -877,6 +877,80 @@ var _ = Describe("Updaterun initialization tests", func() { validateUpdateRunMetricsEmitted(generateProgressingMetric(updateRun)) }) }) + + Context("Test multiple resource snapshots", func() { + var resourceSnapshot2, resourceSnapshot3 *placementv1beta1.ClusterResourceSnapshot + BeforeEach(func() { + By("Creating a new clusterResourcePlacement") + Expect(k8sClient.Create(ctx, crp)).To(Succeed()) + + By("Creating scheduling policy snapshot") + Expect(k8sClient.Create(ctx, policySnapshot)).To(Succeed()) + + By("Setting the latest policy snapshot condition as fully scheduled") + meta.SetStatusCondition(&policySnapshot.Status.Conditions, metav1.Condition{ + Type: string(placementv1beta1.PolicySnapshotScheduled), + Status: metav1.ConditionTrue, + ObservedGeneration: policySnapshot.Generation, + Reason: "scheduled", + }) + Expect(k8sClient.Status().Update(ctx, policySnapshot)).Should(Succeed(), "failed to update the policy snapshot condition") + + By("Creating a new resource snapshot") + resourceSnapshot.Labels[placementv1beta1.IsLatestSnapshotLabel] = "false" + Expect(k8sClient.Create(ctx, resourceSnapshot)).To(Succeed()) + + By("Creating a another new resource snapshot") + resourceSnapshot2 = generateTestClusterResourceSnapshot() + resourceSnapshot2.Name = testCRPName + "-1-snapshot" + resourceSnapshot2.Labels[placementv1beta1.IsLatestSnapshotLabel] = "false" + resourceSnapshot2.Labels[placementv1beta1.ResourceIndexLabel] = "1" + Expect(k8sClient.Create(ctx, resourceSnapshot2)).To(Succeed()) + + By("Creating a latest master resource snapshot") + resourceSnapshot3 = generateTestClusterResourceSnapshot() + resourceSnapshot3.Name = testCRPName + "-2-snapshot" + resourceSnapshot3.Labels[placementv1beta1.ResourceIndexLabel] = "2" + Expect(k8sClient.Create(ctx, resourceSnapshot3)).To(Succeed()) + + By("Creating the member clusters") + for _, cluster := range targetClusters { + Expect(k8sClient.Create(ctx, cluster)).To(Succeed()) + } + for _, cluster := range unscheduledClusters { + Expect(k8sClient.Create(ctx, cluster)).To(Succeed()) + } + + By("Creating a bunch of ClusterResourceBindings") + for _, binding := range resourceBindings { + Expect(k8sClient.Create(ctx, binding)).To(Succeed()) + } + + By("Creating a clusterStagedUpdateStrategy") + Expect(k8sClient.Create(ctx, updateStrategy)).To(Succeed()) + }) + + It("Should pick latest master resource snapshot", func() { + By("Creating a new cluster resource override") + Expect(k8sClient.Create(ctx, clusterResourceOverride)).To(Succeed()) + + By("Creating a new clusterStagedUpdateRun") + updateRun.Spec.ResourceSnapshotIndex = "" + Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) + + By("Validating the clusterStagedUpdateRun stats") + initialized := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) + initialized.ResourceSnapshotName = resourceSnapshot3.Name + want := generateExecutionStartedStatus(updateRun, initialized) + validateClusterStagedUpdateRunStatus(ctx, updateRun, want, "") + + By("Validating the clusterStagedUpdateRun initialized consistently") + validateClusterStagedUpdateRunStatusConsistently(ctx, updateRun, want, "") + + By("Checking update run status metrics are emitted") + validateUpdateRunMetricsEmitted(generateProgressingMetric(updateRun)) + }) + }) }) func validateFailedInitCondition(ctx context.Context, updateRun *placementv1beta1.ClusterStagedUpdateRun, message string) { From a2a4a704e383e1eea2b3d0cadadadbe092606147 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Tue, 11 Nov 2025 10:22:15 -0800 Subject: [PATCH 08/14] fix UT Signed-off-by: Britania Rodriguez Reyes --- pkg/controllers/updaterun/initialization.go | 1 - .../updaterun/initialization_integration_test.go | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/controllers/updaterun/initialization.go b/pkg/controllers/updaterun/initialization.go index 29ba03ef0..c6e5460a8 100644 --- a/pkg/controllers/updaterun/initialization.go +++ b/pkg/controllers/updaterun/initialization.go @@ -484,7 +484,6 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t // only master has this annotation. if len(resourceSnapshot.GetAnnotations()[placementv1beta1.ResourceGroupHashAnnotation]) != 0 { masterResourceSnapshot = resourceSnapshot - break } } diff --git a/pkg/controllers/updaterun/initialization_integration_test.go b/pkg/controllers/updaterun/initialization_integration_test.go index c2d9a6095..581feba16 100644 --- a/pkg/controllers/updaterun/initialization_integration_test.go +++ b/pkg/controllers/updaterun/initialization_integration_test.go @@ -774,18 +774,18 @@ var _ = Describe("Updaterun initialization tests", func() { validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) }) - It("Should fail to initialize if the specified resource snapshot is not found - no resourceSnapshots at all", func() { + FIt("Should fail to initialize if the specified resource snapshot is not found - no resourceSnapshots at all", func() { By("Creating a new clusterStagedUpdateRun") Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization failed") - validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots found for placement") + validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots with index `0` found") By("Checking update run status metrics are emitted") validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) }) - It("Should fail to initialize if the specified resource snapshot is not found - no CRP label found", func() { + FIt("Should fail to initialize if the specified resource snapshot is not found - no CRP label found", func() { By("Creating a new resource snapshot associated with another CRP") resourceSnapshot.Labels[placementv1beta1.PlacementTrackingLabel] = "not-exist-crp" Expect(k8sClient.Create(ctx, resourceSnapshot)).To(Succeed()) @@ -794,13 +794,13 @@ var _ = Describe("Updaterun initialization tests", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization failed") - validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots found for placement") + validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots with index `0` found") By("Checking update run status metrics are emitted") validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) }) - It("Should fail to initialize if the specified resource snapshot is not found - no resource index label found", func() { + FIt("Should fail to initialize if the specified resource snapshot is not found - no resource index label found", func() { By("Creating a new resource snapshot with a different index label") resourceSnapshot.Labels[placementv1beta1.ResourceIndexLabel] = testResourceSnapshotIndex + "1" Expect(k8sClient.Create(ctx, resourceSnapshot)).To(Succeed()) @@ -809,7 +809,7 @@ var _ = Describe("Updaterun initialization tests", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization failed") - validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots found for placement") + validateFailedInitCondition(ctx, updateRun, "no resourceSnapshots with index `0` found") By("Checking update run status metrics are emitted") validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) From 04e5467eced03d63ed8b3afb1251d25ff20da297 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Tue, 11 Nov 2025 10:35:12 -0800 Subject: [PATCH 09/14] fix Signed-off-by: Britania Rodriguez Reyes --- .../updaterun/initialization_integration_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/controllers/updaterun/initialization_integration_test.go b/pkg/controllers/updaterun/initialization_integration_test.go index 581feba16..95ffdfcac 100644 --- a/pkg/controllers/updaterun/initialization_integration_test.go +++ b/pkg/controllers/updaterun/initialization_integration_test.go @@ -774,7 +774,7 @@ var _ = Describe("Updaterun initialization tests", func() { validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) }) - FIt("Should fail to initialize if the specified resource snapshot is not found - no resourceSnapshots at all", func() { + It("Should fail to initialize if the specified resource snapshot is not found - no resourceSnapshots at all", func() { By("Creating a new clusterStagedUpdateRun") Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) @@ -785,7 +785,7 @@ var _ = Describe("Updaterun initialization tests", func() { validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) }) - FIt("Should fail to initialize if the specified resource snapshot is not found - no CRP label found", func() { + It("Should fail to initialize if the specified resource snapshot is not found - no CRP label found", func() { By("Creating a new resource snapshot associated with another CRP") resourceSnapshot.Labels[placementv1beta1.PlacementTrackingLabel] = "not-exist-crp" Expect(k8sClient.Create(ctx, resourceSnapshot)).To(Succeed()) @@ -800,7 +800,7 @@ var _ = Describe("Updaterun initialization tests", func() { validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) }) - FIt("Should fail to initialize if the specified resource snapshot is not found - no resource index label found", func() { + It("Should fail to initialize if the specified resource snapshot is not found - no resource index label found", func() { By("Creating a new resource snapshot with a different index label") resourceSnapshot.Labels[placementv1beta1.ResourceIndexLabel] = testResourceSnapshotIndex + "1" Expect(k8sClient.Create(ctx, resourceSnapshot)).To(Succeed()) From e6f6a52a0580dff0d64f39ceb7d83e1e745d615b Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Tue, 11 Nov 2025 14:50:57 -0800 Subject: [PATCH 10/14] address comments Signed-off-by: Britania Rodriguez Reyes --- pkg/controllers/updaterun/initialization.go | 3 +- .../initialization_integration_test.go | 10 + .../updaterun/initialization_test.go | 194 +++++++++++++++++- 3 files changed, 204 insertions(+), 3 deletions(-) diff --git a/pkg/controllers/updaterun/initialization.go b/pkg/controllers/updaterun/initialization.go index c6e5460a8..c770185bb 100644 --- a/pkg/controllers/updaterun/initialization.go +++ b/pkg/controllers/updaterun/initialization.go @@ -495,12 +495,11 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t return fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) } - klog.InfoS("Found master resourceSnapshot", "placement", placementKey, "masterResourceSnapshot", masterResourceSnapshot.GetName(), "updateRun", updateRunRef) + klog.V(2).InfoS("Found master resourceSnapshot", "placement", placementKey, "masterResourceSnapshot", masterResourceSnapshot.GetName(), "updateRun", updateRunRef) // Update the resource snapshot name in the UpdateRun status. updateRunStatus := updateRun.GetUpdateRunStatus() updateRunStatus.ResourceSnapshotName = masterResourceSnapshot.GetName() - updateRun.SetUpdateRunStatus(*updateRunStatus) if updateErr := r.Client.Status().Update(ctx, updateRun); updateErr != nil { klog.ErrorS(updateErr, "Failed to update the UpdateRun status with resource snapshot name", "updateRun", klog.KObj(updateRun), "resourceSnapshot", klog.KObj(masterResourceSnapshot)) // updateErr can be retried. diff --git a/pkg/controllers/updaterun/initialization_integration_test.go b/pkg/controllers/updaterun/initialization_integration_test.go index 95ffdfcac..039893b30 100644 --- a/pkg/controllers/updaterun/initialization_integration_test.go +++ b/pkg/controllers/updaterun/initialization_integration_test.go @@ -930,6 +930,16 @@ var _ = Describe("Updaterun initialization tests", func() { Expect(k8sClient.Create(ctx, updateStrategy)).To(Succeed()) }) + AfterEach(func() { + By("Deleting the second clusterResourceSnapshot") + Expect(k8sClient.Delete(ctx, resourceSnapshot2)).To(Succeed()) + + By("Deleting the third clusterResourceSnapshot") + Expect(k8sClient.Delete(ctx, resourceSnapshot3)).To(Succeed()) + + // Everything else should be deleted by the outer AfterEach + }) + It("Should pick latest master resource snapshot", func() { By("Creating a new cluster resource override") Expect(k8sClient.Create(ctx, clusterResourceOverride)).To(Succeed()) diff --git a/pkg/controllers/updaterun/initialization_test.go b/pkg/controllers/updaterun/initialization_test.go index 0c470d38e..3e5515a71 100644 --- a/pkg/controllers/updaterun/initialization_test.go +++ b/pkg/controllers/updaterun/initialization_test.go @@ -1,13 +1,22 @@ package updaterun import ( + "context" + "fmt" + "strings" "testing" "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/klog/v2" "k8s.io/utils/ptr" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/fake" - "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1" + v1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1" ) func TestValidateAfterStageTask(t *testing.T) { @@ -85,3 +94,186 @@ func TestValidateAfterStageTask(t *testing.T) { }) } } + +func TestGetResourceSnapshotObjs(t *testing.T) { + ctx := context.Background() + placementName := "test-placement" + placementKey := types.NamespacedName{Name: placementName, Namespace: "test-namespace"} + updateRunRef := klog.ObjectRef{ + Name: "test-updaterun", + Namespace: "test-namespace", + } + + // Create test resource snapshots + masterResourceSnapshot := &v1beta1.ClusterResourceSnapshot{ + ObjectMeta: metav1.ObjectMeta{ + Name: placementName + "-1-snapshot", + Namespace: placementKey.Namespace, + Labels: map[string]string{ + v1beta1.PlacementTrackingLabel: placementName, + v1beta1.ResourceIndexLabel: "1", + v1beta1.IsLatestSnapshotLabel: "false", + v1beta1.ResourceGroupHashAnnotation: "hash123", + }, + Annotations: map[string]string{ + v1beta1.ResourceGroupHashAnnotation: "hash123", + }, + }, + } + + tests := []struct { + name string + updateRunSpec *v1beta1.UpdateRunSpec + resourceSnapshots []runtime.Object + wantSnapshotCount int + wantErr bool + wantErrMsg string + }{ + // negative cases only + { + name: "invalid resource snapshot index - non-numeric", + updateRunSpec: &v1beta1.UpdateRunSpec{ + ResourceSnapshotIndex: "invalid", + }, + resourceSnapshots: []runtime.Object{}, + wantSnapshotCount: 0, + wantErr: true, + wantErrMsg: "invalid resource snapshot index `invalid` provided, expected an integer >= 0", + }, + { + name: "invalid resource snapshot index - negative", + updateRunSpec: &v1beta1.UpdateRunSpec{ + ResourceSnapshotIndex: "-1", + }, + resourceSnapshots: []runtime.Object{}, + wantSnapshotCount: 0, + wantErr: true, + wantErrMsg: "invalid resource snapshot index `-1` provided, expected an integer >= 0", + }, + { + name: "no resource snapshots found for specific index", + updateRunSpec: &v1beta1.UpdateRunSpec{ + ResourceSnapshotIndex: "999", + }, + resourceSnapshots: []runtime.Object{ + masterResourceSnapshot, // has index "1", not "999" + }, + wantSnapshotCount: 0, + wantErr: true, + wantErrMsg: fmt.Sprintf("no resourceSnapshots with index `999` found for placement `%s`", placementKey), + }, + { + name: "no latest resource snapshots found", + updateRunSpec: &v1beta1.UpdateRunSpec{ + ResourceSnapshotIndex: "", + }, + resourceSnapshots: []runtime.Object{}, // no snapshots + wantSnapshotCount: 0, + wantErr: true, + wantErrMsg: fmt.Sprintf("no resourceSnapshots found for placement `%s`", placementKey), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Create a fake client with the test objects + s := runtime.NewScheme() + _ = v1beta1.AddToScheme(s) + _ = scheme.AddToScheme(s) + + fakeClient := fake.NewClientBuilder(). + WithScheme(s). + WithRuntimeObjects(tt.resourceSnapshots...). + Build() + + // Create reconciler with fake client + r := &Reconciler{ + Client: fakeClient, + } + + // Call the function + result, err := r.getResourceSnapshotObjs(ctx, tt.updateRunSpec, placementName, placementKey, updateRunRef) + + // Verify error expectations + if tt.wantErr { + if err == nil { + t.Errorf("getResourceSnapshotObjs() error = nil, wantErr %v", tt.wantErr) + return + } + // Check if the error message contains the expected substring + if !strings.Contains(err.Error(), tt.wantErrMsg) { + t.Errorf("getResourceSnapshotObjs() error = %v, want error containing %v", err, tt.wantErrMsg) + } + return + } + + // Verify no error when not expected + if err != nil { + t.Errorf("getResourceSnapshotObjs() unexpected error = %v", err) + return + } + + // Verify result count + if len(result) != tt.wantSnapshotCount { + t.Errorf("getResourceSnapshotObjs() returned %d snapshots, want %d", len(result), tt.wantSnapshotCount) + return + } + }) + } +} + +// fakeListErrorClient wraps a client and always returns an error on List. +type fakeListErrorClient struct { + client.Client +} + +func (f *fakeListErrorClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error { + return fmt.Errorf("simulated list error") +} + +func TestGetResourceSnapshotObjs_ListError(t *testing.T) { + tests := []struct { + name string + spec *v1beta1.UpdateRunSpec + wantErrMsg string + }{ + { + name: "list error simulation with resource index", + spec: &v1beta1.UpdateRunSpec{ + ResourceSnapshotIndex: "1", + }, + wantErrMsg: "Failed to list the resourceSnapshots associated with the placement for the given index", + }, + { + name: "list error simulation without resource index", + spec: &v1beta1.UpdateRunSpec{ + ResourceSnapshotIndex: "", + }, + wantErrMsg: "Failed to list the resourceSnapshots associated with the placement", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ctx := context.Background() + placementName := "test-placement" + placementKey := types.NamespacedName{Name: placementName, Namespace: "test-namespace"} + updateRunRef := klog.ObjectRef{ + Name: "test-updaterun", + Namespace: "test-namespace", + } + + s := runtime.NewScheme() + _ = v1beta1.AddToScheme(s) + _ = scheme.AddToScheme(s) + + fakeClient := &fakeListErrorClient{Client: fake.NewClientBuilder().WithScheme(s).Build()} + r := &Reconciler{Client: fakeClient} + + _, err := r.getResourceSnapshotObjs(ctx, tt.spec, placementName, placementKey, updateRunRef) + if err == nil || !strings.Contains(err.Error(), "simulated list error") { + t.Errorf("expected simulated list error, got: %v", err) + } + }) + } +} From e65e33f33c2b9582f3ed166a606ea38c4d1a37de Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Wed, 12 Nov 2025 11:37:19 -0800 Subject: [PATCH 11/14] address comments Signed-off-by: Britania Rodriguez Reyes --- .../updaterun/initialization_test.go | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/pkg/controllers/updaterun/initialization_test.go b/pkg/controllers/updaterun/initialization_test.go index 3e5515a71..e6d0300e7 100644 --- a/pkg/controllers/updaterun/initialization_test.go +++ b/pkg/controllers/updaterun/initialization_test.go @@ -2,6 +2,7 @@ package updaterun import ( "context" + "errors" "fmt" "strings" "testing" @@ -10,30 +11,30 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - "k8s.io/client-go/kubernetes/scheme" "k8s.io/klog/v2" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" + "sigs.k8s.io/controller-runtime/pkg/client/interceptor" - v1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1" + placementv1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1" ) func TestValidateAfterStageTask(t *testing.T) { tests := []struct { name string - task []v1beta1.StageTask + task []placementv1beta1.StageTask wantErr bool errMsg string }{ { name: "valid AfterTasks", - task: []v1beta1.StageTask{ + task: []placementv1beta1.StageTask{ { - Type: v1beta1.StageTaskTypeApproval, + Type: placementv1beta1.StageTaskTypeApproval, }, { - Type: v1beta1.StageTaskTypeTimedWait, + Type: placementv1beta1.StageTaskTypeTimedWait, WaitTime: ptr.To(metav1.Duration{Duration: 5 * time.Minute}), }, }, @@ -41,13 +42,13 @@ func TestValidateAfterStageTask(t *testing.T) { }, { name: "invalid AfterTasks, same type of tasks", - task: []v1beta1.StageTask{ + task: []placementv1beta1.StageTask{ { - Type: v1beta1.StageTaskTypeTimedWait, + Type: placementv1beta1.StageTaskTypeTimedWait, WaitTime: ptr.To(metav1.Duration{Duration: 1 * time.Minute}), }, { - Type: v1beta1.StageTaskTypeTimedWait, + Type: placementv1beta1.StageTaskTypeTimedWait, WaitTime: ptr.To(metav1.Duration{Duration: 5 * time.Minute}), }, }, @@ -56,9 +57,9 @@ func TestValidateAfterStageTask(t *testing.T) { }, { name: "invalid AfterTasks, with nil duration for TimedWait", - task: []v1beta1.StageTask{ + task: []placementv1beta1.StageTask{ { - Type: v1beta1.StageTaskTypeTimedWait, + Type: placementv1beta1.StageTaskTypeTimedWait, }, }, wantErr: true, @@ -66,9 +67,9 @@ func TestValidateAfterStageTask(t *testing.T) { }, { name: "invalid AfterTasks, with zero duration for TimedWait", - task: []v1beta1.StageTask{ + task: []placementv1beta1.StageTask{ { - Type: v1beta1.StageTaskTypeTimedWait, + Type: placementv1beta1.StageTaskTypeTimedWait, WaitTime: ptr.To(metav1.Duration{Duration: 0 * time.Minute}), }, }, @@ -105,25 +106,25 @@ func TestGetResourceSnapshotObjs(t *testing.T) { } // Create test resource snapshots - masterResourceSnapshot := &v1beta1.ClusterResourceSnapshot{ + masterResourceSnapshot := &placementv1beta1.ClusterResourceSnapshot{ ObjectMeta: metav1.ObjectMeta{ Name: placementName + "-1-snapshot", Namespace: placementKey.Namespace, Labels: map[string]string{ - v1beta1.PlacementTrackingLabel: placementName, - v1beta1.ResourceIndexLabel: "1", - v1beta1.IsLatestSnapshotLabel: "false", - v1beta1.ResourceGroupHashAnnotation: "hash123", + placementv1beta1.PlacementTrackingLabel: placementName, + placementv1beta1.ResourceIndexLabel: "1", + placementv1beta1.IsLatestSnapshotLabel: "false", + placementv1beta1.ResourceGroupHashAnnotation: "hash123", }, Annotations: map[string]string{ - v1beta1.ResourceGroupHashAnnotation: "hash123", + placementv1beta1.ResourceGroupHashAnnotation: "hash123", }, }, } tests := []struct { name string - updateRunSpec *v1beta1.UpdateRunSpec + updateRunSpec *placementv1beta1.UpdateRunSpec resourceSnapshots []runtime.Object wantSnapshotCount int wantErr bool @@ -132,7 +133,7 @@ func TestGetResourceSnapshotObjs(t *testing.T) { // negative cases only { name: "invalid resource snapshot index - non-numeric", - updateRunSpec: &v1beta1.UpdateRunSpec{ + updateRunSpec: &placementv1beta1.UpdateRunSpec{ ResourceSnapshotIndex: "invalid", }, resourceSnapshots: []runtime.Object{}, @@ -142,7 +143,7 @@ func TestGetResourceSnapshotObjs(t *testing.T) { }, { name: "invalid resource snapshot index - negative", - updateRunSpec: &v1beta1.UpdateRunSpec{ + updateRunSpec: &placementv1beta1.UpdateRunSpec{ ResourceSnapshotIndex: "-1", }, resourceSnapshots: []runtime.Object{}, @@ -152,7 +153,7 @@ func TestGetResourceSnapshotObjs(t *testing.T) { }, { name: "no resource snapshots found for specific index", - updateRunSpec: &v1beta1.UpdateRunSpec{ + updateRunSpec: &placementv1beta1.UpdateRunSpec{ ResourceSnapshotIndex: "999", }, resourceSnapshots: []runtime.Object{ @@ -164,7 +165,7 @@ func TestGetResourceSnapshotObjs(t *testing.T) { }, { name: "no latest resource snapshots found", - updateRunSpec: &v1beta1.UpdateRunSpec{ + updateRunSpec: &placementv1beta1.UpdateRunSpec{ ResourceSnapshotIndex: "", }, resourceSnapshots: []runtime.Object{}, // no snapshots @@ -177,12 +178,8 @@ func TestGetResourceSnapshotObjs(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // Create a fake client with the test objects - s := runtime.NewScheme() - _ = v1beta1.AddToScheme(s) - _ = scheme.AddToScheme(s) - fakeClient := fake.NewClientBuilder(). - WithScheme(s). + WithScheme(serviceScheme(t)). WithRuntimeObjects(tt.resourceSnapshots...). Build() @@ -222,31 +219,22 @@ func TestGetResourceSnapshotObjs(t *testing.T) { } } -// fakeListErrorClient wraps a client and always returns an error on List. -type fakeListErrorClient struct { - client.Client -} - -func (f *fakeListErrorClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error { - return fmt.Errorf("simulated list error") -} - func TestGetResourceSnapshotObjs_ListError(t *testing.T) { tests := []struct { name string - spec *v1beta1.UpdateRunSpec + spec *placementv1beta1.UpdateRunSpec wantErrMsg string }{ { name: "list error simulation with resource index", - spec: &v1beta1.UpdateRunSpec{ + spec: &placementv1beta1.UpdateRunSpec{ ResourceSnapshotIndex: "1", }, wantErrMsg: "Failed to list the resourceSnapshots associated with the placement for the given index", }, { name: "list error simulation without resource index", - spec: &v1beta1.UpdateRunSpec{ + spec: &placementv1beta1.UpdateRunSpec{ ResourceSnapshotIndex: "", }, wantErrMsg: "Failed to list the resourceSnapshots associated with the placement", @@ -263,17 +251,29 @@ func TestGetResourceSnapshotObjs_ListError(t *testing.T) { Namespace: "test-namespace", } - s := runtime.NewScheme() - _ = v1beta1.AddToScheme(s) - _ = scheme.AddToScheme(s) - - fakeClient := &fakeListErrorClient{Client: fake.NewClientBuilder().WithScheme(s).Build()} + // Use interceptor to make Get calls fail. + fakeClient := interceptor.NewClient( + fake.NewClientBuilder().WithScheme(serviceScheme(t)).Build(), + interceptor.Funcs{ + List: func(ctx context.Context, client client.WithWatch, list client.ObjectList, opts ...client.ListOption) error { + return errors.New(tt.wantErrMsg) + }, + }, + ) r := &Reconciler{Client: fakeClient} _, err := r.getResourceSnapshotObjs(ctx, tt.spec, placementName, placementKey, updateRunRef) - if err == nil || !strings.Contains(err.Error(), "simulated list error") { + if err == nil || !strings.Contains(err.Error(), tt.wantErrMsg) { t.Errorf("expected simulated list error, got: %v", err) } }) } } + +func serviceScheme(t *testing.T) *runtime.Scheme { + scheme := runtime.NewScheme() + if err := placementv1beta1.AddToScheme(scheme); err != nil { + t.Fatalf("Failed to add placement v1beta1 scheme: %v", err) + } + return scheme +} From e5164ea73d324c713542ed5f4bcc65d4a3108643 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Thu, 13 Nov 2025 11:35:20 -0800 Subject: [PATCH 12/14] address comments Signed-off-by: Britania Rodriguez Reyes --- apis/placement/v1beta1/stageupdate_types.go | 7 +- ...etes-fleet.io_clusterstagedupdateruns.yaml | 7 +- ....kubernetes-fleet.io_stagedupdateruns.yaml | 7 +- pkg/controllers/updaterun/execution.go | 6 +- .../updaterun/execution_integration_test.go | 16 +- pkg/controllers/updaterun/initialization.go | 30 +-- .../initialization_integration_test.go | 166 +++++++------- .../updaterun/initialization_test.go | 216 +----------------- .../updaterun/validation_integration_test.go | 4 +- test/e2e/actuals_test.go | 10 +- test/e2e/cluster_staged_updaterun_test.go | 34 +-- test/e2e/staged_updaterun_test.go | 12 +- 12 files changed, 166 insertions(+), 349 deletions(-) diff --git a/apis/placement/v1beta1/stageupdate_types.go b/apis/placement/v1beta1/stageupdate_types.go index 0831027a7..fa92786d2 100644 --- a/apis/placement/v1beta1/stageupdate_types.go +++ b/apis/placement/v1beta1/stageupdate_types.go @@ -374,9 +374,10 @@ type UpdateRunStatus struct { // +kubebuilder:validation:Optional PolicyObservedClusterCount int `json:"policyObservedClusterCount,omitempty"` - // ResourceSnapshotName records the name of the master resource snapshot that the update run is based on. - // +kubebuilder:validation:Optional - ResourceSnapshotName string `json:"resourceSnapshotName,omitempty"` + // ResourceSnapshotIndexUsed records the resource snapshot index that the update run is based on. + // The index represents the same resource snapshots as specified in the spec field, or the latest. + // +kubbebuilder:validation:Optional + ResourceSnapshotIndexUsed string `json:"resourceSnapshotIndexUsed,omitempty"` // ApplyStrategy is the apply strategy that the stagedUpdateRun is using. // It is the same as the apply strategy in the CRP when the staged update run starts. diff --git a/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml b/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml index 37324c1ce..a2ddf03ec 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_clusterstagedupdateruns.yaml @@ -1894,9 +1894,10 @@ spec: All clusters involved in the update run are selected from the list of clusters scheduled by the CRP according to the current policy. type: string - resourceSnapshotName: - description: ResourceSnapshotName records the name of the master resource - snapshot that the update run is based on. + resourceSnapshotIndexUsed: + description: |- + ResourceSnapshotIndexUsed records the resource snapshot index that the update run is based on. + The index represents the same resource snapshots as specified in the spec field, or the latest. type: string stagedUpdateStrategySnapshot: description: |- diff --git a/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml b/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml index 809ae55df..0db56cd16 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_stagedupdateruns.yaml @@ -814,9 +814,10 @@ spec: All clusters involved in the update run are selected from the list of clusters scheduled by the CRP according to the current policy. type: string - resourceSnapshotName: - description: ResourceSnapshotName records the name of the master resource - snapshot that the update run is based on. + resourceSnapshotIndexUsed: + description: |- + ResourceSnapshotIndexUsed records the resource snapshot index that the update run is based on. + The index represents the same resource snapshots as specified in the spec field, or the latest. type: string stagedUpdateStrategySnapshot: description: |- diff --git a/pkg/controllers/updaterun/execution.go b/pkg/controllers/updaterun/execution.go index 948f93654..87f5eaf4b 100644 --- a/pkg/controllers/updaterun/execution.go +++ b/pkg/controllers/updaterun/execution.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "reflect" + "strconv" "time" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -92,8 +93,11 @@ func (r *Reconciler) executeUpdatingStage( toBeUpdatedBindings []placementv1beta1.BindingObj, ) (time.Duration, error) { updateRunStatus := updateRun.GetUpdateRunStatus() + updateRunSpec := updateRun.GetUpdateRunSpec() updatingStageStatus := &updateRunStatus.StagesStatus[updatingStageIndex] - resourceSnapshotName := updateRunStatus.ResourceSnapshotName + // The parse error is ignored because the initialization should have caught it. + resourceIndex, _ := strconv.Atoi(updateRunStatus.ResourceSnapshotIndexUsed) + resourceSnapshotName := fmt.Sprintf(placementv1beta1.ResourceSnapshotNameFmt, updateRunSpec.PlacementName, resourceIndex) updateRunRef := klog.KObj(updateRun) // Create the map of the toBeUpdatedBindings. toBeUpdatedBindingsMap := make(map[string]placementv1beta1.BindingObj, len(toBeUpdatedBindings)) diff --git a/pkg/controllers/updaterun/execution_integration_test.go b/pkg/controllers/updaterun/execution_integration_test.go index 9b3e06833..980283497 100644 --- a/pkg/controllers/updaterun/execution_integration_test.go +++ b/pkg/controllers/updaterun/execution_integration_test.go @@ -160,7 +160,7 @@ var _ = Describe("UpdateRun execution tests - double stages", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization succeeded and the execution started") - initialized := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) + initialized := generateSucceededInitializationStatus(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, clusterResourceOverride) wantStatus = generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "") @@ -521,7 +521,7 @@ var _ = Describe("UpdateRun execution tests - double stages", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization succeeded and the execution started") - initialized := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) + initialized := generateSucceededInitializationStatus(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, clusterResourceOverride) wantStatus = generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "") @@ -680,7 +680,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization succeeded and the execution started") - initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, policySnapshot, updateStrategy) + initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy) wantStatus = generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "") @@ -774,7 +774,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization succeeded and the execution started") - initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, policySnapshot, updateStrategy) + initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy) wantStatus = generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "") @@ -883,7 +883,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization succeeded and the execution started") - initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, policySnapshot, updateStrategy) + initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy) wantStatus = generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "") @@ -1014,7 +1014,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization succeeded and the execution started") - initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, policySnapshot, updateStrategy) + initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy) wantStatus = generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "") @@ -1106,7 +1106,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization succeeded and the execution started") - initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, policySnapshot, updateStrategy) + initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy) wantStatus = generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "") @@ -1163,7 +1163,7 @@ var _ = Describe("UpdateRun execution tests - single stage", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization succeeded and the execution started") - initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, policySnapshot, updateStrategy) + initialized := generateSucceededInitializationStatusForSmallClusters(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy) wantStatus = generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "") }) diff --git a/pkg/controllers/updaterun/initialization.go b/pkg/controllers/updaterun/initialization.go index c770185bb..f8ff0682e 100644 --- a/pkg/controllers/updaterun/initialization.go +++ b/pkg/controllers/updaterun/initialization.go @@ -471,9 +471,8 @@ func validateAfterStageTask(tasks []placementv1beta1.StageTask) error { func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey types.NamespacedName, updateRun placementv1beta1.UpdateRunObj) error { updateRunRef := klog.KObj(updateRun) updateRunSpec := updateRun.GetUpdateRunSpec() - placementName := placementKey.Name - resourceSnapshotObjs, err := r.getResourceSnapshotObjs(ctx, updateRunSpec, placementName, placementKey, updateRunRef) + resourceSnapshotObjs, err := r.getResourceSnapshotObjs(ctx, placementKey, updateRun) if err != nil { return err } @@ -487,6 +486,7 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t break } } + // No masterResourceSnapshot found. if masterResourceSnapshot == nil { err := controller.NewUnexpectedBehaviorError(fmt.Errorf("no master resourceSnapshot found for placement %s", placementKey)) @@ -497,14 +497,10 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t klog.V(2).InfoS("Found master resourceSnapshot", "placement", placementKey, "masterResourceSnapshot", masterResourceSnapshot.GetName(), "updateRun", updateRunRef) - // Update the resource snapshot name in the UpdateRun status. + // Record the resource snapshot index used. updateRunStatus := updateRun.GetUpdateRunStatus() - updateRunStatus.ResourceSnapshotName = masterResourceSnapshot.GetName() - if updateErr := r.Client.Status().Update(ctx, updateRun); updateErr != nil { - klog.ErrorS(updateErr, "Failed to update the UpdateRun status with resource snapshot name", "updateRun", klog.KObj(updateRun), "resourceSnapshot", klog.KObj(masterResourceSnapshot)) - // updateErr can be retried. - return controller.NewUpdateIgnoreConflictError(updateErr) - } + updateRunStatus.ResourceSnapshotIndexUsed = masterResourceSnapshot.GetLabels()[placementv1beta1.ResourceIndexLabel] + updateRun.SetUpdateRunStatus(*updateRunStatus) resourceSnapshotRef := klog.KObj(masterResourceSnapshot) // Fetch all the matching overrides. @@ -534,20 +530,24 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t // getResourceSnapshotObjs retrieves the list of resource snapshot objects from the specified ResourceSnapshotIndex. // If ResourceSnapshotIndex is unspecified, it returns the list of latest resource snapshots. -func (r *Reconciler) getResourceSnapshotObjs(ctx context.Context, updateRunSpec *placementv1beta1.UpdateRunSpec, placementName string, placementKey types.NamespacedName, updateRunRef klog.ObjectRef) ([]placementv1beta1.ResourceSnapshotObj, error) { +func (r *Reconciler) getResourceSnapshotObjs(ctx context.Context, placementKey types.NamespacedName, updateRun placementv1beta1.UpdateRunObj) ([]placementv1beta1.ResourceSnapshotObj, error) { + updateRunRef := klog.KObj(updateRun) + updateRunSpec := updateRun.GetUpdateRunSpec() var resourceSnapshotObjs []placementv1beta1.ResourceSnapshotObj if updateRunSpec.ResourceSnapshotIndex != "" { snapshotIndex, err := strconv.Atoi(updateRunSpec.ResourceSnapshotIndex) if err != nil || snapshotIndex < 0 { err := controller.NewUserError(fmt.Errorf("invalid resource snapshot index `%s` provided, expected an integer >= 0", updateRunSpec.ResourceSnapshotIndex)) klog.ErrorS(err, "Failed to parse the resource snapshot index", "updateRun", updateRunRef) + // no more retries here. return nil, fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) } - resourceSnapshotList, err := controller.ListAllResourceSnapshotWithAnIndex(ctx, r.Client, updateRunSpec.ResourceSnapshotIndex, placementName, placementKey.Namespace) + resourceSnapshotList, err := controller.ListAllResourceSnapshotWithAnIndex(ctx, r.Client, updateRunSpec.ResourceSnapshotIndex, placementKey.Name, placementKey.Namespace) if err != nil { klog.ErrorS(err, "Failed to list the resourceSnapshots associated with the placement", "placement", placementKey, "resourceSnapshotIndex", snapshotIndex, "updateRun", updateRunRef) + // list err can be retried. return nil, controller.NewAPIServerError(true, err) } @@ -561,18 +561,20 @@ func (r *Reconciler) getResourceSnapshotObjs(ctx context.Context, updateRunSpec return resourceSnapshotObjs, nil } + klog.V(2).InfoS("No resource snapshot index specified, fetching latest resource snapshots", "placement", placementKey, "updateRun", updateRunRef) latestResourceSnapshots, err := controller.ListLatestResourceSnapshots(ctx, r.Client, placementKey) if err != nil { klog.ErrorS(err, "Failed to list the latest resourceSnapshots associated with the placement", "placement", placementKey, "updateRun", updateRunRef) + // list err can be retried. return nil, controller.NewAPIServerError(true, err) } resourceSnapshotObjs = latestResourceSnapshots.GetResourceSnapshotObjs() if len(resourceSnapshotObjs) == 0 { - err := controller.NewUserError(fmt.Errorf("no resourceSnapshots found for placement `%s`", placementKey)) - klog.ErrorS(err, "No resourceSnapshots found", "updateRun", updateRunRef) - // no more retries here. + err := fmt.Errorf("no latest resourceSnapshots found for placement `%s`. This might be a transient state, need retry", placementKey) + klog.ErrorS(err, "No latest resourceSnapshots found for placement. This might be transient, need retry", "placement", placementKey, "updateRun", updateRunRef) + // retryable error. return resourceSnapshotObjs, fmt.Errorf("%w: %s", errInitializedFailed, err.Error()) } return resourceSnapshotObjs, nil diff --git a/pkg/controllers/updaterun/initialization_integration_test.go b/pkg/controllers/updaterun/initialization_integration_test.go index 039893b30..f70103b6b 100644 --- a/pkg/controllers/updaterun/initialization_integration_test.go +++ b/pkg/controllers/updaterun/initialization_integration_test.go @@ -57,7 +57,7 @@ var _ = Describe("Updaterun initialization tests", func() { var resourceBindings []*placementv1beta1.ClusterResourceBinding var targetClusters []*clusterv1beta1.MemberCluster var unscheduledClusters []*clusterv1beta1.MemberCluster - var resourceSnapshot *placementv1beta1.ClusterResourceSnapshot + var resourceSnapshot, resourceSnapshot2, resourceSnapshot3 *placementv1beta1.ClusterResourceSnapshot var clusterResourceOverride *placementv1beta1.ClusterResourceOverrideSnapshot BeforeEach(func() { @@ -75,6 +75,8 @@ var _ = Describe("Updaterun initialization tests", func() { resourceBindings, targetClusters, unscheduledClusters = generateTestClusterResourceBindingsAndClusters(1) policySnapshot = generateTestClusterSchedulingPolicySnapshot(1, len(targetClusters)) resourceSnapshot = generateTestClusterResourceSnapshot() + resourceSnapshot2 = generateTestClusterResourceSnapshot() + resourceSnapshot3 = generateTestClusterResourceSnapshot() // Set smaller wait time for testing stageUpdatingWaitTime = time.Second * 3 @@ -113,9 +115,13 @@ var _ = Describe("Updaterun initialization tests", func() { Expect(k8sClient.Delete(ctx, updateStrategy)).Should(SatisfyAny(Succeed(), utils.NotFoundMatcher{})) updateStrategy = nil - By("Deleting the clusterResourceSnapshot") + By("Deleting the clusterResourceSnapshots") Expect(k8sClient.Delete(ctx, resourceSnapshot)).Should(SatisfyAny(Succeed(), utils.NotFoundMatcher{})) resourceSnapshot = nil + Expect(k8sClient.Delete(ctx, resourceSnapshot2)).Should(SatisfyAny(Succeed(), utils.NotFoundMatcher{})) + resourceSnapshot2 = nil + Expect(k8sClient.Delete(ctx, resourceSnapshot3)).Should(SatisfyAny(Succeed(), utils.NotFoundMatcher{})) + resourceSnapshot3 = nil By("Deleting the clusterResourceOverride") Expect(k8sClient.Delete(ctx, clusterResourceOverride)).Should(SatisfyAny(Succeed(), utils.NotFoundMatcher{})) @@ -654,8 +660,8 @@ var _ = Describe("Updaterun initialization tests", func() { return err } - want := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) - want.ResourceSnapshotName = "" // resourceSnapshot not created in this test + // no resource snapshot created in this test + want := generateSucceededInitializationStatus(crp, updateRun, "", policySnapshot, updateStrategy, clusterResourceOverride) // No clusters should be selected in the first stage. want.StagesStatus[0].Clusters = []placementv1beta1.ClusterUpdatingStatus{} // All clusters should be selected in the second stage and sorted by name. @@ -697,8 +703,8 @@ var _ = Describe("Updaterun initialization tests", func() { return err } - want := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) - want.ResourceSnapshotName = "" // resourceSnapshot not created in this test + // no resource snapshot created in this test + want := generateSucceededInitializationStatus(crp, updateRun, "", policySnapshot, updateStrategy, clusterResourceOverride) for i := range want.StagesStatus[0].Clusters { // Remove the CROs, as they are not added in this test. want.StagesStatus[0].Clusters[i].ClusterResourceOverrideSnapshots = nil @@ -785,6 +791,18 @@ var _ = Describe("Updaterun initialization tests", func() { validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) }) + It("Should fail to initialize if the specified resource snapshot is not found when no resource index specified - no resourceSnapshots at all", func() { + By("Creating a new clusterStagedUpdateRun without specifying resourceSnapshotIndex") + updateRun.Spec.ResourceSnapshotIndex = "" + Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) + + By("Validating the initialization failed") + validateFailedInitCondition(ctx, updateRun, "no latest resourceSnapshots found for placement") + + By("Checking update run status metrics are emitted") + validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) + }) + It("Should fail to initialize if the specified resource snapshot is not found - no CRP label found", func() { By("Creating a new resource snapshot associated with another CRP") resourceSnapshot.Labels[placementv1beta1.PlacementTrackingLabel] = "not-exist-crp" @@ -830,20 +848,19 @@ var _ = Describe("Updaterun initialization tests", func() { validateUpdateRunMetricsEmitted(generateInitializationFailedMetric(updateRun)) }) - It("Should put related ClusterResourceOverrides in the status with no resource index defined", func() { + It("Should select latest resource snapshot in the status when no resource index defined", func() { By("Creating a new resource snapshot") Expect(k8sClient.Create(ctx, resourceSnapshot)).To(Succeed()) By("Creating a new cluster resource override") Expect(k8sClient.Create(ctx, clusterResourceOverride)).To(Succeed()) - By("Creating a new clusterStagedUpdateRun") + By("Creating a new clusterStagedUpdateRun without specifying resourceSnapshotIndex") updateRun.Spec.ResourceSnapshotIndex = "" Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the clusterStagedUpdateRun stats") - initialized := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) - initialized.ResourceSnapshotName = testResourceSnapshotName + initialized := generateSucceededInitializationStatus(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, clusterResourceOverride) want := generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, want, "") @@ -865,8 +882,7 @@ var _ = Describe("Updaterun initialization tests", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the clusterStagedUpdateRun stats") - initialized := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) - initialized.ResourceSnapshotName = testResourceSnapshotName + initialized := generateSucceededInitializationStatus(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, clusterResourceOverride) want := generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, want, "") @@ -878,88 +894,70 @@ var _ = Describe("Updaterun initialization tests", func() { }) }) - Context("Test multiple resource snapshots", func() { - var resourceSnapshot2, resourceSnapshot3 *placementv1beta1.ClusterResourceSnapshot - BeforeEach(func() { - By("Creating a new clusterResourcePlacement") - Expect(k8sClient.Create(ctx, crp)).To(Succeed()) + It("Should pick latest master resource snapshot if multiple snapshots", func() { + By("Creating a new clusterResourcePlacement") + Expect(k8sClient.Create(ctx, crp)).To(Succeed()) - By("Creating scheduling policy snapshot") - Expect(k8sClient.Create(ctx, policySnapshot)).To(Succeed()) + By("Creating scheduling policy snapshot") + Expect(k8sClient.Create(ctx, policySnapshot)).To(Succeed()) - By("Setting the latest policy snapshot condition as fully scheduled") - meta.SetStatusCondition(&policySnapshot.Status.Conditions, metav1.Condition{ - Type: string(placementv1beta1.PolicySnapshotScheduled), - Status: metav1.ConditionTrue, - ObservedGeneration: policySnapshot.Generation, - Reason: "scheduled", - }) - Expect(k8sClient.Status().Update(ctx, policySnapshot)).Should(Succeed(), "failed to update the policy snapshot condition") - - By("Creating a new resource snapshot") - resourceSnapshot.Labels[placementv1beta1.IsLatestSnapshotLabel] = "false" - Expect(k8sClient.Create(ctx, resourceSnapshot)).To(Succeed()) - - By("Creating a another new resource snapshot") - resourceSnapshot2 = generateTestClusterResourceSnapshot() - resourceSnapshot2.Name = testCRPName + "-1-snapshot" - resourceSnapshot2.Labels[placementv1beta1.IsLatestSnapshotLabel] = "false" - resourceSnapshot2.Labels[placementv1beta1.ResourceIndexLabel] = "1" - Expect(k8sClient.Create(ctx, resourceSnapshot2)).To(Succeed()) - - By("Creating a latest master resource snapshot") - resourceSnapshot3 = generateTestClusterResourceSnapshot() - resourceSnapshot3.Name = testCRPName + "-2-snapshot" - resourceSnapshot3.Labels[placementv1beta1.ResourceIndexLabel] = "2" - Expect(k8sClient.Create(ctx, resourceSnapshot3)).To(Succeed()) + By("Setting the latest policy snapshot condition as fully scheduled") + meta.SetStatusCondition(&policySnapshot.Status.Conditions, metav1.Condition{ + Type: string(placementv1beta1.PolicySnapshotScheduled), + Status: metav1.ConditionTrue, + ObservedGeneration: policySnapshot.Generation, + Reason: "scheduled", + }) + Expect(k8sClient.Status().Update(ctx, policySnapshot)).Should(Succeed(), "failed to update the policy snapshot condition") - By("Creating the member clusters") - for _, cluster := range targetClusters { - Expect(k8sClient.Create(ctx, cluster)).To(Succeed()) - } - for _, cluster := range unscheduledClusters { - Expect(k8sClient.Create(ctx, cluster)).To(Succeed()) - } + By("Creating the member clusters") + for _, cluster := range targetClusters { + Expect(k8sClient.Create(ctx, cluster)).To(Succeed()) + } + for _, cluster := range unscheduledClusters { + Expect(k8sClient.Create(ctx, cluster)).To(Succeed()) + } - By("Creating a bunch of ClusterResourceBindings") - for _, binding := range resourceBindings { - Expect(k8sClient.Create(ctx, binding)).To(Succeed()) - } + By("Creating a bunch of ClusterResourceBindings") + for _, binding := range resourceBindings { + Expect(k8sClient.Create(ctx, binding)).To(Succeed()) + } - By("Creating a clusterStagedUpdateStrategy") - Expect(k8sClient.Create(ctx, updateStrategy)).To(Succeed()) - }) + By("Creating a clusterStagedUpdateStrategy") + Expect(k8sClient.Create(ctx, updateStrategy)).To(Succeed()) - AfterEach(func() { - By("Deleting the second clusterResourceSnapshot") - Expect(k8sClient.Delete(ctx, resourceSnapshot2)).To(Succeed()) + By("Creating a new resource snapshot") + resourceSnapshot.Labels[placementv1beta1.IsLatestSnapshotLabel] = "false" + Expect(k8sClient.Create(ctx, resourceSnapshot)).To(Succeed()) - By("Deleting the third clusterResourceSnapshot") - Expect(k8sClient.Delete(ctx, resourceSnapshot3)).To(Succeed()) + By("Creating a another new resource snapshot") + resourceSnapshot2.Name = testCRPName + "-1-snapshot" + resourceSnapshot2.Labels[placementv1beta1.IsLatestSnapshotLabel] = "false" + resourceSnapshot2.Labels[placementv1beta1.ResourceIndexLabel] = "1" + Expect(k8sClient.Create(ctx, resourceSnapshot2)).To(Succeed()) - // Everything else should be deleted by the outer AfterEach - }) + By("Creating a latest master resource snapshot") + resourceSnapshot3.Name = testCRPName + "-2-snapshot" + resourceSnapshot3.Labels[placementv1beta1.ResourceIndexLabel] = "2" + Expect(k8sClient.Create(ctx, resourceSnapshot3)).To(Succeed()) - It("Should pick latest master resource snapshot", func() { - By("Creating a new cluster resource override") - Expect(k8sClient.Create(ctx, clusterResourceOverride)).To(Succeed()) + By("Creating a new cluster resource override") + Expect(k8sClient.Create(ctx, clusterResourceOverride)).To(Succeed()) - By("Creating a new clusterStagedUpdateRun") - updateRun.Spec.ResourceSnapshotIndex = "" - Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) + By("Creating a new clusterStagedUpdateRun without specifying resourceSnapshotIndex") + updateRun.Spec.ResourceSnapshotIndex = "" + Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) - By("Validating the clusterStagedUpdateRun stats") - initialized := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) - initialized.ResourceSnapshotName = resourceSnapshot3.Name - want := generateExecutionStartedStatus(updateRun, initialized) - validateClusterStagedUpdateRunStatus(ctx, updateRun, want, "") + By("Validating the clusterStagedUpdateRun status") + initialized := generateSucceededInitializationStatus(crp, updateRun, "2", policySnapshot, updateStrategy, clusterResourceOverride) + want := generateExecutionStartedStatus(updateRun, initialized) + validateClusterStagedUpdateRunStatus(ctx, updateRun, want, "") - By("Validating the clusterStagedUpdateRun initialized consistently") - validateClusterStagedUpdateRunStatusConsistently(ctx, updateRun, want, "") + By("Validating the clusterStagedUpdateRun initialized consistently") + validateClusterStagedUpdateRunStatusConsistently(ctx, updateRun, want, "") - By("Checking update run status metrics are emitted") - validateUpdateRunMetricsEmitted(generateProgressingMetric(updateRun)) - }) + By("Checking update run status metrics are emitted") + validateUpdateRunMetricsEmitted(generateProgressingMetric(updateRun)) }) }) @@ -983,6 +981,7 @@ func validateFailedInitCondition(ctx context.Context, updateRun *placementv1beta func generateSucceededInitializationStatus( crp *placementv1beta1.ClusterResourcePlacement, updateRun *placementv1beta1.ClusterStagedUpdateRun, + resourceSnapshotIndex string, policySnapshot *placementv1beta1.ClusterSchedulingPolicySnapshot, updateStrategy *placementv1beta1.ClusterStagedUpdateStrategy, clusterResourceOverride *placementv1beta1.ClusterResourceOverrideSnapshot, @@ -990,7 +989,7 @@ func generateSucceededInitializationStatus( status := &placementv1beta1.UpdateRunStatus{ PolicySnapshotIndexUsed: policySnapshot.Labels[placementv1beta1.PolicyIndexLabel], PolicyObservedClusterCount: 10, - ResourceSnapshotName: testResourceSnapshotName, + ResourceSnapshotIndexUsed: resourceSnapshotIndex, ApplyStrategy: crp.Spec.Strategy.ApplyStrategy.DeepCopy(), UpdateStrategySnapshot: &updateStrategy.Spec, StagesStatus: []placementv1beta1.StageUpdatingStatus{ @@ -1045,13 +1044,14 @@ func generateSucceededInitializationStatus( func generateSucceededInitializationStatusForSmallClusters( crp *placementv1beta1.ClusterResourcePlacement, updateRun *placementv1beta1.ClusterStagedUpdateRun, + resourceSnapshotIndex string, policySnapshot *placementv1beta1.ClusterSchedulingPolicySnapshot, updateStrategy *placementv1beta1.ClusterStagedUpdateStrategy, ) *placementv1beta1.UpdateRunStatus { status := &placementv1beta1.UpdateRunStatus{ PolicySnapshotIndexUsed: policySnapshot.Labels[placementv1beta1.PolicyIndexLabel], PolicyObservedClusterCount: 3, - ResourceSnapshotName: testResourceSnapshotName, + ResourceSnapshotIndexUsed: resourceSnapshotIndex, ApplyStrategy: crp.Spec.Strategy.ApplyStrategy.DeepCopy(), UpdateStrategySnapshot: &updateStrategy.Spec, StagesStatus: []placementv1beta1.StageUpdatingStatus{ diff --git a/pkg/controllers/updaterun/initialization_test.go b/pkg/controllers/updaterun/initialization_test.go index e6d0300e7..0c470d38e 100644 --- a/pkg/controllers/updaterun/initialization_test.go +++ b/pkg/controllers/updaterun/initialization_test.go @@ -1,40 +1,30 @@ package updaterun import ( - "context" - "errors" - "fmt" - "strings" "testing" "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - "k8s.io/klog/v2" "k8s.io/utils/ptr" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/client/fake" - "sigs.k8s.io/controller-runtime/pkg/client/interceptor" - placementv1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1" + "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1" ) func TestValidateAfterStageTask(t *testing.T) { tests := []struct { name string - task []placementv1beta1.StageTask + task []v1beta1.StageTask wantErr bool errMsg string }{ { name: "valid AfterTasks", - task: []placementv1beta1.StageTask{ + task: []v1beta1.StageTask{ { - Type: placementv1beta1.StageTaskTypeApproval, + Type: v1beta1.StageTaskTypeApproval, }, { - Type: placementv1beta1.StageTaskTypeTimedWait, + Type: v1beta1.StageTaskTypeTimedWait, WaitTime: ptr.To(metav1.Duration{Duration: 5 * time.Minute}), }, }, @@ -42,13 +32,13 @@ func TestValidateAfterStageTask(t *testing.T) { }, { name: "invalid AfterTasks, same type of tasks", - task: []placementv1beta1.StageTask{ + task: []v1beta1.StageTask{ { - Type: placementv1beta1.StageTaskTypeTimedWait, + Type: v1beta1.StageTaskTypeTimedWait, WaitTime: ptr.To(metav1.Duration{Duration: 1 * time.Minute}), }, { - Type: placementv1beta1.StageTaskTypeTimedWait, + Type: v1beta1.StageTaskTypeTimedWait, WaitTime: ptr.To(metav1.Duration{Duration: 5 * time.Minute}), }, }, @@ -57,9 +47,9 @@ func TestValidateAfterStageTask(t *testing.T) { }, { name: "invalid AfterTasks, with nil duration for TimedWait", - task: []placementv1beta1.StageTask{ + task: []v1beta1.StageTask{ { - Type: placementv1beta1.StageTaskTypeTimedWait, + Type: v1beta1.StageTaskTypeTimedWait, }, }, wantErr: true, @@ -67,9 +57,9 @@ func TestValidateAfterStageTask(t *testing.T) { }, { name: "invalid AfterTasks, with zero duration for TimedWait", - task: []placementv1beta1.StageTask{ + task: []v1beta1.StageTask{ { - Type: placementv1beta1.StageTaskTypeTimedWait, + Type: v1beta1.StageTaskTypeTimedWait, WaitTime: ptr.To(metav1.Duration{Duration: 0 * time.Minute}), }, }, @@ -95,185 +85,3 @@ func TestValidateAfterStageTask(t *testing.T) { }) } } - -func TestGetResourceSnapshotObjs(t *testing.T) { - ctx := context.Background() - placementName := "test-placement" - placementKey := types.NamespacedName{Name: placementName, Namespace: "test-namespace"} - updateRunRef := klog.ObjectRef{ - Name: "test-updaterun", - Namespace: "test-namespace", - } - - // Create test resource snapshots - masterResourceSnapshot := &placementv1beta1.ClusterResourceSnapshot{ - ObjectMeta: metav1.ObjectMeta{ - Name: placementName + "-1-snapshot", - Namespace: placementKey.Namespace, - Labels: map[string]string{ - placementv1beta1.PlacementTrackingLabel: placementName, - placementv1beta1.ResourceIndexLabel: "1", - placementv1beta1.IsLatestSnapshotLabel: "false", - placementv1beta1.ResourceGroupHashAnnotation: "hash123", - }, - Annotations: map[string]string{ - placementv1beta1.ResourceGroupHashAnnotation: "hash123", - }, - }, - } - - tests := []struct { - name string - updateRunSpec *placementv1beta1.UpdateRunSpec - resourceSnapshots []runtime.Object - wantSnapshotCount int - wantErr bool - wantErrMsg string - }{ - // negative cases only - { - name: "invalid resource snapshot index - non-numeric", - updateRunSpec: &placementv1beta1.UpdateRunSpec{ - ResourceSnapshotIndex: "invalid", - }, - resourceSnapshots: []runtime.Object{}, - wantSnapshotCount: 0, - wantErr: true, - wantErrMsg: "invalid resource snapshot index `invalid` provided, expected an integer >= 0", - }, - { - name: "invalid resource snapshot index - negative", - updateRunSpec: &placementv1beta1.UpdateRunSpec{ - ResourceSnapshotIndex: "-1", - }, - resourceSnapshots: []runtime.Object{}, - wantSnapshotCount: 0, - wantErr: true, - wantErrMsg: "invalid resource snapshot index `-1` provided, expected an integer >= 0", - }, - { - name: "no resource snapshots found for specific index", - updateRunSpec: &placementv1beta1.UpdateRunSpec{ - ResourceSnapshotIndex: "999", - }, - resourceSnapshots: []runtime.Object{ - masterResourceSnapshot, // has index "1", not "999" - }, - wantSnapshotCount: 0, - wantErr: true, - wantErrMsg: fmt.Sprintf("no resourceSnapshots with index `999` found for placement `%s`", placementKey), - }, - { - name: "no latest resource snapshots found", - updateRunSpec: &placementv1beta1.UpdateRunSpec{ - ResourceSnapshotIndex: "", - }, - resourceSnapshots: []runtime.Object{}, // no snapshots - wantSnapshotCount: 0, - wantErr: true, - wantErrMsg: fmt.Sprintf("no resourceSnapshots found for placement `%s`", placementKey), - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - // Create a fake client with the test objects - fakeClient := fake.NewClientBuilder(). - WithScheme(serviceScheme(t)). - WithRuntimeObjects(tt.resourceSnapshots...). - Build() - - // Create reconciler with fake client - r := &Reconciler{ - Client: fakeClient, - } - - // Call the function - result, err := r.getResourceSnapshotObjs(ctx, tt.updateRunSpec, placementName, placementKey, updateRunRef) - - // Verify error expectations - if tt.wantErr { - if err == nil { - t.Errorf("getResourceSnapshotObjs() error = nil, wantErr %v", tt.wantErr) - return - } - // Check if the error message contains the expected substring - if !strings.Contains(err.Error(), tt.wantErrMsg) { - t.Errorf("getResourceSnapshotObjs() error = %v, want error containing %v", err, tt.wantErrMsg) - } - return - } - - // Verify no error when not expected - if err != nil { - t.Errorf("getResourceSnapshotObjs() unexpected error = %v", err) - return - } - - // Verify result count - if len(result) != tt.wantSnapshotCount { - t.Errorf("getResourceSnapshotObjs() returned %d snapshots, want %d", len(result), tt.wantSnapshotCount) - return - } - }) - } -} - -func TestGetResourceSnapshotObjs_ListError(t *testing.T) { - tests := []struct { - name string - spec *placementv1beta1.UpdateRunSpec - wantErrMsg string - }{ - { - name: "list error simulation with resource index", - spec: &placementv1beta1.UpdateRunSpec{ - ResourceSnapshotIndex: "1", - }, - wantErrMsg: "Failed to list the resourceSnapshots associated with the placement for the given index", - }, - { - name: "list error simulation without resource index", - spec: &placementv1beta1.UpdateRunSpec{ - ResourceSnapshotIndex: "", - }, - wantErrMsg: "Failed to list the resourceSnapshots associated with the placement", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ctx := context.Background() - placementName := "test-placement" - placementKey := types.NamespacedName{Name: placementName, Namespace: "test-namespace"} - updateRunRef := klog.ObjectRef{ - Name: "test-updaterun", - Namespace: "test-namespace", - } - - // Use interceptor to make Get calls fail. - fakeClient := interceptor.NewClient( - fake.NewClientBuilder().WithScheme(serviceScheme(t)).Build(), - interceptor.Funcs{ - List: func(ctx context.Context, client client.WithWatch, list client.ObjectList, opts ...client.ListOption) error { - return errors.New(tt.wantErrMsg) - }, - }, - ) - r := &Reconciler{Client: fakeClient} - - _, err := r.getResourceSnapshotObjs(ctx, tt.spec, placementName, placementKey, updateRunRef) - if err == nil || !strings.Contains(err.Error(), tt.wantErrMsg) { - t.Errorf("expected simulated list error, got: %v", err) - } - }) - } -} - -func serviceScheme(t *testing.T) *runtime.Scheme { - scheme := runtime.NewScheme() - if err := placementv1beta1.AddToScheme(scheme); err != nil { - t.Fatalf("Failed to add placement v1beta1 scheme: %v", err) - } - return scheme -} diff --git a/pkg/controllers/updaterun/validation_integration_test.go b/pkg/controllers/updaterun/validation_integration_test.go index de1cd71e8..bcc255473 100644 --- a/pkg/controllers/updaterun/validation_integration_test.go +++ b/pkg/controllers/updaterun/validation_integration_test.go @@ -110,7 +110,7 @@ var _ = Describe("UpdateRun validation tests", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization succeeded") - initialized := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) + initialized := generateSucceededInitializationStatus(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, clusterResourceOverride) wantStatus = generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "") }) @@ -442,7 +442,7 @@ var _ = Describe("UpdateRun validation tests", func() { Expect(k8sClient.Create(ctx, updateRun)).To(Succeed()) By("Validating the initialization succeeded") - initialized := generateSucceededInitializationStatus(crp, updateRun, policySnapshot, updateStrategy, clusterResourceOverride) + initialized := generateSucceededInitializationStatus(crp, updateRun, testResourceSnapshotIndex, policySnapshot, updateStrategy, clusterResourceOverride) wantStatus = generateExecutionStartedStatus(updateRun, initialized) validateClusterStagedUpdateRunStatus(ctx, updateRun, wantStatus, "") }) diff --git a/test/e2e/actuals_test.go b/test/e2e/actuals_test.go index 51ee76a9e..344faf6f4 100644 --- a/test/e2e/actuals_test.go +++ b/test/e2e/actuals_test.go @@ -2092,7 +2092,7 @@ func updateRunSucceedConditions(generation int64) []metav1.Condition { func clusterStagedUpdateRunStatusSucceededActual( updateRunName string, - wantResourceSnapshotName string, + wantResourceIndex string, wantPolicyIndex string, wantClusterCount int, wantApplyStrategy *placementv1beta1.ApplyStrategy, @@ -2110,7 +2110,7 @@ func clusterStagedUpdateRunStatusSucceededActual( wantStatus := placementv1beta1.UpdateRunStatus{ PolicySnapshotIndexUsed: wantPolicyIndex, - ResourceSnapshotName: wantResourceSnapshotName, + ResourceSnapshotIndexUsed: wantResourceIndex, PolicyObservedClusterCount: wantClusterCount, ApplyStrategy: wantApplyStrategy.DeepCopy(), UpdateStrategySnapshot: wantStrategySpec, @@ -2127,8 +2127,8 @@ func clusterStagedUpdateRunStatusSucceededActual( } func stagedUpdateRunStatusSucceededActual( - updateRunName, namespace, wantResourceSnapshotName string, - wantPolicyIndex string, + updateRunName, namespace string, + wantResourceIndex, wantPolicyIndex string, wantClusterCount int, wantApplyStrategy *placementv1beta1.ApplyStrategy, wantStrategySpec *placementv1beta1.UpdateStrategySpec, @@ -2145,7 +2145,7 @@ func stagedUpdateRunStatusSucceededActual( wantStatus := placementv1beta1.UpdateRunStatus{ PolicySnapshotIndexUsed: wantPolicyIndex, - ResourceSnapshotName: wantResourceSnapshotName, + ResourceSnapshotIndexUsed: wantResourceIndex, PolicyObservedClusterCount: wantClusterCount, ApplyStrategy: wantApplyStrategy.DeepCopy(), UpdateStrategySnapshot: wantStrategySpec, diff --git a/test/e2e/cluster_staged_updaterun_test.go b/test/e2e/cluster_staged_updaterun_test.go index c1a7ae7c4..1e900a4e7 100644 --- a/test/e2e/cluster_staged_updaterun_test.go +++ b/test/e2e/cluster_staged_updaterun_test.go @@ -151,7 +151,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to all the members and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -216,7 +216,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-1 and member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], resourceSnapshotIndex2nd, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) By("Verify that new the configmap is updated on all member clusters") for idx := range allMemberClusters { @@ -254,7 +254,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollback resources to member-cluster-1 and member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) for idx := range allMemberClusters { configMapActual := configMapPlacedOnClusterActual(allMemberClusters[idx], &oldConfigMap) @@ -350,7 +350,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-1 too but not member-cluster-3 and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], resourceSnapshotIndex1st, policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) checkIfRemovedWorkResourcesFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[2]}) @@ -400,7 +400,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], resourceSnapshotIndex1st, policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -447,7 +447,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { It("Should remove resources on member-cluster-1 and member-cluster-2 and complete the cluster staged update run successfully", func() { // need to go through two stages - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], resourceSnapshotIndex1st, policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) Eventually(csurSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[2]) checkIfRemovedWorkResourcesFromMemberClusters([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[2]}) @@ -539,7 +539,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-3 and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], resourceSnapshotIndex1st, policySnapshotIndex1st, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[2]}) checkIfRemovedWorkResourcesFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) @@ -588,7 +588,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-1 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], resourceSnapshotIndex1st, policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -634,7 +634,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should remove resources on member-cluster-1 and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[2], resourceSnapshotIndex1st, policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) Eventually(csurSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[2]) checkIfRemovedWorkResourcesFromMemberClusters([]*framework.Cluster{allMemberClusters[0]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[1], allMemberClusters[2]}) @@ -806,7 +806,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should rollout resources to member-cluster-1 and member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, wantCROs, wantROs) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, wantCROs, wantROs) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -906,7 +906,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should report diff for member-cluster-1 and member-cluster-3 too and complete the cluster staged update run successfully", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), applyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), applyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunName) }) @@ -1017,7 +1017,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { validateAndApproveClusterApprovalRequests(updateRunName, envCanary) // Verify complete rollout - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, resourceSnapshotIndex2nd, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunName) // Verify new configmap is on all member clusters @@ -1143,7 +1143,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { }) It("Should complete the staged update run after approval", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -1216,7 +1216,7 @@ var _ = Describe("test CRP rollout with staged update run", func() { validateAndApproveClusterApprovalRequests(updateRunName, envCanary) - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunName, resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) @@ -1342,7 +1342,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label createClusterStagedUpdateRunSucceed(updateRunNames[0], crpName, resourceSnapshotIndex1st, strategyName) By("Validating staged update run has succeeded") - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[0], resourceSnapshotIndex1st, policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) By("Validating CRP status as completed") @@ -1394,7 +1394,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the second staged update run and complete the CRP", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1], allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], resourceSnapshotIndex1st, policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1], allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex1st, true, allMemberClusterNames[1:], @@ -1442,7 +1442,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the staged update run, complete CRP, and rollout resources to all member clusters", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], resourceSnapshotIndex1st, policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex1st, true, allMemberClusterNames, diff --git a/test/e2e/staged_updaterun_test.go b/test/e2e/staged_updaterun_test.go index 8a0227cd3..4c8ea6c3b 100644 --- a/test/e2e/staged_updaterun_test.go +++ b/test/e2e/staged_updaterun_test.go @@ -142,7 +142,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to all the members and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -207,7 +207,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, resourceSnapshotIndex2nd, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[1]) By("Verify that new the configmap is updated on all member clusters") for idx := range allMemberClusters { @@ -245,7 +245,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollback resources to member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) for idx := range allMemberClusters { configMapActual := configMapPlacedOnClusterActual(allMemberClusters[idx], &oldConfigMap) @@ -339,7 +339,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 too but not member-cluster-3 and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, resourceSnapshotIndex1st, policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) checkIfRemovedConfigMapFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[2]}) @@ -389,7 +389,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, resourceSnapshotIndex1st, policySnapshotIndex2nd, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -436,7 +436,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem It("Should remove resources on member-cluster-1 and member-cluster-2 and complete the staged update run successfully", func() { // need to go through two stages - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, resourceSnapshotIndex1st, policySnapshotIndex3rd, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0], allMemberClusterNames[1]}, nil, nil) Eventually(surSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[2]) checkIfRemovedConfigMapFromMemberClusters([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[2]}) From 32bd9185c61355fd1eb05956effe7b072042e356 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Thu, 13 Nov 2025 11:43:38 -0800 Subject: [PATCH 13/14] fix e2es Signed-off-by: Britania Rodriguez Reyes --- test/e2e/cluster_staged_updaterun_test.go | 6 ++---- test/e2e/staged_updaterun_test.go | 14 +++++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/test/e2e/cluster_staged_updaterun_test.go b/test/e2e/cluster_staged_updaterun_test.go index 1e900a4e7..b11fe9ccd 100644 --- a/test/e2e/cluster_staged_updaterun_test.go +++ b/test/e2e/cluster_staged_updaterun_test.go @@ -46,8 +46,6 @@ const ( policySnapshotIndex3rd = "2" testConfigMapDataValue = "new" - - testResourceSnapshotNameTmpl = "%s-%s-snapshot" ) var ( @@ -1485,7 +1483,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the staged update run, complete CRP, and rollout updated resources to all member clusters", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], resourceSnapshotIndex2nd, policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex2nd, true, allMemberClusterNames, @@ -1524,7 +1522,7 @@ var _ = Describe("Test member cluster join and leave flow with updateRun", Label }) It("Should complete the staged update run, complete CRP, and re-place resources to all member clusters", func() { - csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], fmt.Sprintf(testResourceSnapshotNameTmpl, crpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) + csurSucceededActual := clusterStagedUpdateRunStatusSucceededActual(updateRunNames[1], resourceSnapshotIndex1st, policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[0], allMemberClusterNames[1], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(csurSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s succeeded", updateRunNames[1]) crpStatusUpdatedActual := crpStatusWithExternalStrategyActual(workResourceIdentifiers(), resourceSnapshotIndex1st, true, allMemberClusterNames, diff --git a/test/e2e/staged_updaterun_test.go b/test/e2e/staged_updaterun_test.go index 4c8ea6c3b..133b7d9a8 100644 --- a/test/e2e/staged_updaterun_test.go +++ b/test/e2e/staged_updaterun_test.go @@ -526,7 +526,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-3 and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[0], testNamespace, resourceSnapshotIndex1st, policySnapshotIndex1st, 1, defaultApplyStrategy, &strategy.Spec, [][]string{{}, {allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[0]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun([]*framework.Cluster{allMemberClusters[2]}) checkIfRemovedConfigMapFromMemberClustersConsistently([]*framework.Cluster{allMemberClusters[0], allMemberClusters[1]}) @@ -575,7 +575,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[1], testNamespace, resourceSnapshotIndex1st, policySnapshotIndex1st, 3, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[1]) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -621,7 +621,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should remove resources on member-cluster-1 and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunNames[2], testNamespace, resourceSnapshotIndex1st, policySnapshotIndex1st, 2, defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[2]}}, []string{allMemberClusterNames[0]}, nil, nil) Eventually(surSucceededActual, 2*updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunNames[2]) checkIfRemovedConfigMapFromMemberClusters([]*framework.Cluster{allMemberClusters[0]}) checkIfPlacedWorkResourcesOnMemberClustersConsistently([]*framework.Cluster{allMemberClusters[1], allMemberClusters[2]}) @@ -766,7 +766,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should rollout resources to member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, wantROs) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, wantROs) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) }) @@ -860,7 +860,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem }) It("Should report diff for member-cluster-1 and member-cluster-3 too and complete the staged update run successfully", func() { - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), applyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), applyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) }) @@ -969,7 +969,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem validateAndApproveNamespacedApprovalRequests(updateRunName, testNamespace, envCanary) // Verify complete rollout. - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex2nd), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, resourceSnapshotIndex2nd, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) // Verify new configmap is on all member clusters. @@ -1045,7 +1045,7 @@ var _ = Describe("test RP rollout with staged update run", Label("resourceplacem validateAndApproveNamespacedApprovalRequests(updateRunName, testNamespace, envCanary) - surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, fmt.Sprintf(testResourceSnapshotNameTmpl, rpName, resourceSnapshotIndex1st), policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) + surSucceededActual := stagedUpdateRunStatusSucceededActual(updateRunName, testNamespace, resourceSnapshotIndex1st, policySnapshotIndex1st, len(allMemberClusters), defaultApplyStrategy, &strategy.Spec, [][]string{{allMemberClusterNames[1]}, {allMemberClusterNames[0], allMemberClusterNames[2]}}, nil, nil, nil) Eventually(surSucceededActual, updateRunEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to validate updateRun %s/%s succeeded", testNamespace, updateRunName) checkIfPlacedWorkResourcesOnMemberClustersInUpdateRun(allMemberClusters) From 9a7b744faaa192cb88eb9ef9ffac887315cda3b6 Mon Sep 17 00:00:00 2001 From: Britania Rodriguez Reyes Date: Thu, 13 Nov 2025 11:49:43 -0800 Subject: [PATCH 14/14] restore unrelated change Signed-off-by: Britania Rodriguez Reyes --- apis/placement/v1beta1/zz_generated.deepcopy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apis/placement/v1beta1/zz_generated.deepcopy.go b/apis/placement/v1beta1/zz_generated.deepcopy.go index 73d66c8fa..b9ff2e710 100644 --- a/apis/placement/v1beta1/zz_generated.deepcopy.go +++ b/apis/placement/v1beta1/zz_generated.deepcopy.go @@ -21,7 +21,7 @@ limitations under the License. package v1beta1 import ( - "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" )