@@ -478,19 +478,13 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t
478478 return err
479479 }
480480
481- if len (resourceSnapshotObjs ) == 0 {
482- err := controller .NewUserError (fmt .Errorf ("no resourceSnapshots found for placement `%s`" , placementKey ))
483- klog .ErrorS (err , "No resourceSnapshots found" , "updateRun" , updateRunRef )
484- // no more retries here.
485- return fmt .Errorf ("%w: %s" , errInitializedFailed , err .Error ())
486- }
487-
488481 // Look for the master resourceSnapshot.
489482 var masterResourceSnapshot placementv1beta1.ResourceSnapshotObj
490483 for _ , resourceSnapshot := range resourceSnapshotObjs {
491484 // only master has this annotation.
492485 if len (resourceSnapshot .GetAnnotations ()[placementv1beta1 .ResourceGroupHashAnnotation ]) != 0 {
493486 masterResourceSnapshot = resourceSnapshot
487+
494488 break
495489 }
496490 }
@@ -502,10 +496,12 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t
502496 return fmt .Errorf ("%w: %s" , errInitializedFailed , err .Error ())
503497 }
504498
505- klog .InfoS ("Found master resourceSnapshot" , "placement" , placementKey , "index " , updateRun . GetUpdateRunSpec (). ResourceSnapshotIndex , "updateRun" , updateRunRef )
499+ klog .InfoS ("Found master resourceSnapshot" , "placement" , placementKey , "masterResourceSnapshot " , masterResourceSnapshot . GetName () , "updateRun" , updateRunRef )
506500
507501 // Update the resource snapshot name in the UpdateRun status.
508- updateRun .GetUpdateRunStatus ().ResourceSnapshotName = masterResourceSnapshot .GetName ()
502+ updateRunStatus := updateRun .GetUpdateRunStatus ()
503+ updateRunStatus .ResourceSnapshotName = masterResourceSnapshot .GetName ()
504+ updateRun .SetUpdateRunStatus (* updateRunStatus )
509505 if updateErr := r .Client .Status ().Update (ctx , updateRun ); updateErr != nil {
510506 klog .ErrorS (updateErr , "Failed to update the UpdateRun status with resource snapshot name" , "updateRun" , klog .KObj (updateRun ), "resourceSnapshot" , klog .KObj (masterResourceSnapshot ))
511507 // updateErr can be retried.
@@ -522,7 +518,6 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t
522518 }
523519
524520 // Pick the overrides associated with each target cluster.
525- updateRunStatus := updateRun .GetUpdateRunStatus ()
526521 for _ , stageStatus := range updateRunStatus .StagesStatus {
527522 for i := range stageStatus .Clusters {
528523 clusterStatus := & stageStatus .Clusters [i ]
@@ -539,8 +534,10 @@ func (r *Reconciler) recordOverrideSnapshots(ctx context.Context, placementKey t
539534 return nil
540535}
541536
542- // getResourceSnapshotObjs retrieves the resource snapshot objects either by index or latest snapshots.
537+ // getResourceSnapshotObjs retrieves the list of resource snapshot objects from the specified ResourceSnapshotIndex.
538+ // If ResourceSnapshotIndex is unspecified, it returns the list of latest resource snapshots.
543539func (r * Reconciler ) getResourceSnapshotObjs (ctx context.Context , updateRunSpec * placementv1beta1.UpdateRunSpec , placementName string , placementKey types.NamespacedName , updateRunRef klog.ObjectRef ) ([]placementv1beta1.ResourceSnapshotObj , error ) {
540+ var resourceSnapshotObjs []placementv1beta1.ResourceSnapshotObj
544541 if updateRunSpec .ResourceSnapshotIndex != "" {
545542 snapshotIndex , err := strconv .Atoi (updateRunSpec .ResourceSnapshotIndex )
546543 if err != nil || snapshotIndex < 0 {
@@ -555,7 +552,15 @@ func (r *Reconciler) getResourceSnapshotObjs(ctx context.Context, updateRunSpec
555552 "placement" , placementKey , "resourceSnapshotIndex" , snapshotIndex , "updateRun" , updateRunRef )
556553 return nil , controller .NewAPIServerError (true , err )
557554 }
558- return resourceSnapshotList .GetResourceSnapshotObjs (), nil
555+
556+ resourceSnapshotObjs = resourceSnapshotList .GetResourceSnapshotObjs ()
557+ if len (resourceSnapshotObjs ) == 0 {
558+ err := controller .NewUserError (fmt .Errorf ("no resourceSnapshots with index `%d` found for placement `%s`" , snapshotIndex , placementKey ))
559+ klog .ErrorS (err , "No specified resourceSnapshots found" , "updateRun" , updateRunRef )
560+ // no more retries here.
561+ return resourceSnapshotObjs , fmt .Errorf ("%w: %s" , errInitializedFailed , err .Error ())
562+ }
563+ return resourceSnapshotObjs , nil
559564 }
560565
561566 latestResourceSnapshots , err := controller .ListLatestResourceSnapshots (ctx , r .Client , placementKey )
@@ -564,7 +569,15 @@ func (r *Reconciler) getResourceSnapshotObjs(ctx context.Context, updateRunSpec
564569 "placement" , placementKey , "updateRun" , updateRunRef )
565570 return nil , controller .NewAPIServerError (true , err )
566571 }
567- return latestResourceSnapshots .GetResourceSnapshotObjs (), nil
572+
573+ resourceSnapshotObjs = latestResourceSnapshots .GetResourceSnapshotObjs ()
574+ if len (resourceSnapshotObjs ) == 0 {
575+ err := controller .NewUserError (fmt .Errorf ("no resourceSnapshots found for placement `%s`" , placementKey ))
576+ klog .ErrorS (err , "No resourceSnapshots found" , "updateRun" , updateRunRef )
577+ // no more retries here.
578+ return resourceSnapshotObjs , fmt .Errorf ("%w: %s" , errInitializedFailed , err .Error ())
579+ }
580+ return resourceSnapshotObjs , nil
568581}
569582
570583// recordInitializationSucceeded records the successful initialization condition in the UpdateRun status.
0 commit comments