@@ -469,27 +469,39 @@ func validateAfterStageTask(tasks []placementv1beta1.StageTask) error {
469469
470470// recordOverrideSnapshots finds all the override snapshots that are associated with each cluster and record them in the UpdateRun status.
471471func (r * Reconciler ) recordOverrideSnapshots (ctx context.Context , placementKey types.NamespacedName , updateRun placementv1beta1.UpdateRunObj ) error {
472+ var resourceSnapshotObjs []placementv1beta1.ResourceSnapshotObj
473+ var snapshotIndex int
472474 updateRunRef := klog .KObj (updateRun )
473475 updateRunSpec := updateRun .GetUpdateRunSpec ()
474476 placementName := placementKey .Name
477+ if updateRunSpec .ResourceSnapshotIndex != "" {
478+ snapshotIndex , err := strconv .Atoi (updateRunSpec .ResourceSnapshotIndex )
479+ if err != nil || snapshotIndex < 0 {
480+ err := controller .NewUserError (fmt .Errorf ("invalid resource snapshot index `%s` provided, expected an integer >= 0" , updateRunSpec .ResourceSnapshotIndex ))
481+ klog .ErrorS (err , "Failed to parse the resource snapshot index" , "updateRun" , updateRunRef )
482+ // no more retries here.
483+ return fmt .Errorf ("%w: %s" , errInitializedFailed , err .Error ())
484+ }
475485
476- snapshotIndex , err := strconv .Atoi (updateRunSpec .ResourceSnapshotIndex )
477- if err != nil || snapshotIndex < 0 {
478- err := controller .NewUserError (fmt .Errorf ("invalid resource snapshot index `%s` provided, expected an integer >= 0" , updateRunSpec .ResourceSnapshotIndex ))
479- klog .ErrorS (err , "Failed to parse the resource snapshot index" , "updateRun" , updateRunRef )
480- // no more retries here.
481- return fmt .Errorf ("%w: %s" , errInitializedFailed , err .Error ())
482- }
483-
484- resourceSnapshotList , err := controller .ListAllResourceSnapshotWithAnIndex (ctx , r .Client , updateRunSpec .ResourceSnapshotIndex , placementName , placementKey .Namespace )
485- if err != nil {
486- klog .ErrorS (err , "Failed to list the resourceSnapshots associated with the placement" ,
487- "placement" , placementKey , "resourceSnapshotIndex" , snapshotIndex , "updateRun" , updateRunRef )
488- // err can be retried.
489- return controller .NewAPIServerError (true , err )
486+ resourceSnapshotList , err := controller .ListAllResourceSnapshotWithAnIndex (ctx , r .Client , updateRunSpec .ResourceSnapshotIndex , placementName , placementKey .Namespace )
487+ if err != nil {
488+ klog .ErrorS (err , "Failed to list the resourceSnapshots associated with the placement" ,
489+ "placement" , placementKey , "resourceSnapshotIndex" , snapshotIndex , "updateRun" , updateRunRef )
490+ // err can be retried.
491+ return controller .NewAPIServerError (true , err )
492+ }
493+ resourceSnapshotObjs = resourceSnapshotList .GetResourceSnapshotObjs ()
494+ } else {
495+ latestResourceSnapshot , err := controller .ListLatestResourceSnapshots (ctx , r .Client , placementKey )
496+ if err != nil {
497+ klog .ErrorS (err , "Failed to list the latest resourceSnapshots associated with the placement" ,
498+ "placement" , placementKey , "updateRun" , updateRunRef )
499+ // err can be retried.
500+ return controller .NewAPIServerError (true , err )
501+ }
502+ resourceSnapshotObjs = latestResourceSnapshot .GetResourceSnapshotObjs ()
490503 }
491504
492- resourceSnapshotObjs := resourceSnapshotList .GetResourceSnapshotObjs ()
493505 if len (resourceSnapshotObjs ) == 0 {
494506 err := controller .NewUserError (fmt .Errorf ("no resourceSnapshots with index `%d` found for placement `%s`" , snapshotIndex , placementKey ))
495507 klog .ErrorS (err , "No specified resourceSnapshots found" , "updateRun" , updateRunRef )
0 commit comments