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 25, 2024
1 parent 348375c commit 5ada41d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 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,22 @@ 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")
_, err := checkReconcileError(err, "Failed to recreate the status, requeuing")
return ctrl.Result{Requeue: true, RequeueAfter: requeueAfter}, err
}

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
8 changes: 4 additions & 4 deletions controllers/metal3datatemplate_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ var _ = Describe("Metal3DataTemplate manager", func() {
m.EXPECT().UpdateDatas(context.TODO()).Return(0, errors.New(""))
}

res, err := r.reconcileDelete(context.TODO(), m)
res, err := r.reconcileDelete(context.TODO(), m, logr.Discard())
gomockCtrl.Finish()

if tc.ExpectError {
Expand All @@ -307,14 +307,14 @@ var _ = Describe("Metal3DataTemplate manager", func() {
}

},
Entry("No error", reconcileDeleteTestCase{
Entry("No error, not ready", reconcileDeleteTestCase{
ExpectError: false,
ExpectRequeue: false,
ExpectRequeue: true,
}),
Entry("Delete error", reconcileDeleteTestCase{
DeleteError: true,
ExpectError: true,
ExpectRequeue: false,
ExpectRequeue: true,
}),
Entry("Delete ready", reconcileDeleteTestCase{
ExpectError: false,
Expand Down

0 comments on commit 5ada41d

Please sign in to comment.