@@ -252,52 +252,81 @@ func (r *Reconciler) updateStatefulSet(ctx context.Context, host *api.Host, regi
252252
253253 action := common .ErrCRUDRecreate
254254 if k8s .IsStatefulSetReady (curStatefulSet ) {
255- action = r .doUpdateStatefulSet (ctx , curStatefulSet , newStatefulSet , host , opts )
255+ if action = r .doUpdateStatefulSet (ctx , curStatefulSet , newStatefulSet , host , opts ); action == nil {
256+ // Straightforward success
257+ if register {
258+ host .GetCR ().IEnsureStatus ().HostUpdated ()
259+ _ = r .cr .StatusUpdate (ctx , host .GetCR (), types.UpdateStatusOptions {
260+ CopyStatusOptions : types.CopyStatusOptions {
261+ CopyStatusFieldGroup : types.CopyStatusFieldGroup {
262+ FieldGroupMain : true ,
263+ },
264+ },
265+ })
266+ }
267+ r .a .V (1 ).
268+ WithEvent (host .GetCR (), a .EventActionUpdate , a .EventReasonUpdateCompleted ).
269+ WithAction (host .GetCR ()).
270+ M (host ).F ().
271+ Info ("Update StatefulSet(%s/%s) - completed" , namespace , name )
272+
273+ // All is done here
274+ return nil
275+ }
256276 }
257277
278+ // Something is incorrect, need to decide next moves
279+
258280 switch action {
259- case nil :
260- if register {
261- host .GetCR ().IEnsureStatus ().HostUpdated ()
262- _ = r .cr .StatusUpdate (ctx , host .GetCR (), types.UpdateStatusOptions {
263- CopyStatusOptions : types.CopyStatusOptions {
264- CopyStatusFieldGroup : types.CopyStatusFieldGroup {
265- FieldGroupMain : true ,
266- },
267- },
268- })
269- }
270- r .a .V (1 ).
271- WithEvent (host .GetCR (), a .EventActionUpdate , a .EventReasonUpdateCompleted ).
272- WithAction (host .GetCR ()).
273- M (host ).F ().
274- Info ("Update StatefulSet(%s/%s) - completed" , namespace , name )
275- return nil
276- case common .ErrCRUDAbort :
277- r .a .V (1 ).M (host ).Info ("Update StatefulSet(%s/%s) - got abort. Abort" , namespace , name )
278- return common .ErrCRUDAbort
279- case common .ErrCRUDIgnore :
280- r .a .V (1 ).M (host ).Info ("Update StatefulSet(%s/%s) - got ignore. Ignore" , namespace , name )
281- return nil
282281 case common .ErrCRUDRecreate :
282+ // Second attempt requested
283+
283284 onUpdateFailure := host .GetCluster ().GetReconcile ().StatefulSet .Recreate .OnUpdateFailure
284285 if onUpdateFailure == api .OnStatefulSetRecreateOnUpdateFailureActionAbort {
285286 r .a .V (1 ).M (host ).Warning ("Update StatefulSet(%s/%s) - would need recreate but aborting as configured (onUpdateFailure: abort)" , namespace , name )
286287 return common .ErrCRUDAbort
287288 }
289+
290+ // Continue second attempt
288291 r .a .WithEvent (host .GetCR (), a .EventActionUpdate , a .EventReasonUpdateInProgress ).
289292 WithAction (host .GetCR ()).
290293 M (host ).F ().
291294 Info ("Update StatefulSet(%s/%s) switch from Update to Recreate" , namespace , name )
292295 common .DumpStatefulSetDiff (host , curStatefulSet , newStatefulSet )
293296 return r .recreateStatefulSet (ctx , host , register , opts )
297+
298+ default :
299+ // Decide on other non-successful cases
300+ return r .shouldAbortOrContinueUpdateStatefulSet (action , host )
301+ }
302+ }
303+
304+ func (r * Reconciler ) shouldAbortOrContinueUpdateStatefulSet (action error , host * api.Host ) error {
305+ newStatefulSet := host .Runtime .DesiredStatefulSet
306+ namespace := newStatefulSet .Namespace
307+ name := newStatefulSet .Name
308+
309+ switch action {
310+ case common .ErrCRUDAbort :
311+ // Abort
312+ r .a .V (1 ).M (host ).Info ("Update StatefulSet(%s/%s) - got abort. Abort" , namespace , name )
313+ return common .ErrCRUDAbort
314+
315+ case common .ErrCRUDIgnore :
316+ // Continue
317+ r .a .V (1 ).M (host ).Info ("Update StatefulSet(%s/%s) - got ignore. Ignore" , namespace , name )
318+ return nil
319+
294320 case common .ErrCRUDUnexpectedFlow :
321+ // Continue
295322 r .a .V (1 ).M (host ).Warning ("Got unexpected flow action. Ignore and continue for now" )
296323 return nil
297- }
298324
299- r .a .V (1 ).M (host ).Warning ("Got unexpected flow. This is strange. Ignore and continue for now" )
300- return nil
325+ default :
326+ // Continue
327+ r .a .V (1 ).M (host ).Warning ("Got unexpected flow. This is strange. Ignore and continue for now" )
328+ return nil
329+ }
301330}
302331
303332// createStatefulSet
0 commit comments