Skip to content

Commit

Permalink
M3DataTemplate: requeue if reconcileDelete did not clear finalizer
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Morin <[email protected]>
  • Loading branch information
tmmorin committed Sep 23, 2024
1 parent 348375c commit bd19a54
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions controllers/metal3datatemplate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (r *Metal3DataTemplateReconciler) Reconcile(ctx context.Context, req ctrl.R

// Handle deletion of Metal3DataTemplate
if !metal3DataTemplate.ObjectMeta.DeletionTimestamp.IsZero() {
return r.reconcileDelete(ctx, dataTemplateMgr)
return r.reconcileDelete(ctx, dataTemplateMgr, log)
}

// Handle non-deleted Metal3DataTemplate
Expand All @@ -151,18 +151,21 @@ func (r *Metal3DataTemplateReconciler) reconcileNormal(ctx context.Context,

func (r *Metal3DataTemplateReconciler) reconcileDelete(ctx context.Context,
dataTemplateMgr baremetal.DataTemplateManagerInterface,
log logr.Logger,
) (ctrl.Result, error) {
allocationsCount, err := dataTemplateMgr.UpdateDatas(ctx)
if err != nil {
return checkReconcileError(err, "Failed to recreate the status")
}

if allocationsCount == 0 {
// metal3datatemplate is marked for deletion and ready to be deleted,
// so remove the finalizer.
dataTemplateMgr.UnsetFinalizer()
if allocationsCount != 0 {
log.Info("some Metal3DataClaim remain, not unsetting finalizer yet, requeuing")
return ctrl.Result{Requeue: true, RequeueAfter: requeueAfter}, nil
}

// metal3datatemplate is marked for deletion and ready to be deleted,
// so remove the finalizer.
dataTemplateMgr.UnsetFinalizer()
return ctrl.Result{}, nil
}

Expand Down

0 comments on commit bd19a54

Please sign in to comment.