@@ -176,23 +176,23 @@ func (r *Reconciler) Reconcile(ctx context.Context, req runtime.Request) (runtim
176176 return runtime.Result {}, r .recordUpdateRunSucceeded (ctx , updateRun )
177177 }
178178
179- // The execution is not finished yet or it encounters a retriable error.
180- // We need to record the status and requeue.
181- if updateErr := r .recordUpdateRunStatus (ctx , updateRun ); updateErr != nil {
182- return runtime.Result {}, updateErr
183- }
184- klog .V (2 ).InfoS ("The updateRun is not finished yet" , "requeueWaitTime" , waitTime , "execErr" , execErr , "updateRun" , runObjRef )
185- if execErr != nil {
186- return runtime.Result {}, execErr
187- }
188- return runtime.Result {Requeue : true , RequeueAfter : waitTime }, nil
179+ return r .handleIncompleteUpdateRun (ctx , updateRun , waitTime , execErr , state , runObjRef )
189180 case placementv1beta1 .StateStop :
190181 // Stop the updateRun.
191- klog .InfoS ("Stopping the updateRun" , "state" , state , "updatingStageIndex" , updatingStageIndex , "updateRun" , runObjRef )
192- // TODO(britaniar): Implement the stopping logic for in-progress stages.
182+ klog .V (2 ).InfoS ("Stopping the updateRun" , "state" , state , "updatingStageIndex" , updatingStageIndex , "updateRun" , runObjRef )
183+ finished , waitTime , stopErr := r .stop (updateRun , updatingStageIndex , toBeUpdatedBindings , toBeDeletedBindings )
184+ if errors .Is (stopErr , errStagedUpdatedAborted ) {
185+ // errStagedUpdatedAborted cannot be retried.
186+ return runtime.Result {}, r .recordUpdateRunFailed (ctx , updateRun , stopErr .Error ())
187+ }
188+
189+ if finished {
190+ klog .V (2 ).InfoS ("The updateRun is stopped" , "updateRun" , runObjRef )
191+ return runtime.Result {}, r .recordUpdateRunStopped (ctx , updateRun )
192+ }
193+
194+ return r .handleIncompleteUpdateRun (ctx , updateRun , waitTime , stopErr , state , runObjRef )
193195
194- klog .V (2 ).InfoS ("The updateRun is stopped" , "updateRun" , runObjRef )
195- return runtime.Result {}, r .recordUpdateRunStopped (ctx , updateRun )
196196 default :
197197 // Initialize, Run, or Stop are the only supported states.
198198 unexpectedErr := controller .NewUnexpectedBehaviorError (fmt .Errorf ("found unsupported updateRun state: %s" , state ))
@@ -202,6 +202,21 @@ func (r *Reconciler) Reconcile(ctx context.Context, req runtime.Request) (runtim
202202 return runtime.Result {}, nil
203203}
204204
205+ func (r * Reconciler ) handleIncompleteUpdateRun (ctx context.Context , updateRun placementv1beta1.UpdateRunObj , waitTime time.Duration , err error , state placementv1beta1.State , runObjRef klog.ObjectRef ) (runtime.Result , error ) {
206+ // The execution or stopping is not finished yet or it encounters a retriable error.
207+ // We need to record the status and requeue.
208+ if updateErr := r .recordUpdateRunStatus (ctx , updateRun ); updateErr != nil {
209+ return runtime.Result {}, updateErr
210+ }
211+
212+ klog .V (2 ).InfoS ("The updateRun is not finished yet" , "state" , state , "requeueWaitTime" , waitTime , "err" , err , "updateRun" , runObjRef )
213+
214+ if err != nil {
215+ return runtime.Result {}, err
216+ }
217+ return runtime.Result {Requeue : true , RequeueAfter : waitTime }, nil
218+ }
219+
205220// handleDelete handles the deletion of the updateRun object.
206221// We delete all the dependent resources, including approvalRequest objects, of the updateRun object.
207222func (r * Reconciler ) handleDelete (ctx context.Context , updateRun placementv1beta1.UpdateRunObj ) (bool , time.Duration , error ) {
0 commit comments