Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Metal3DataTemplate: requeue if reconcileDelete did not clear finalizer #1997

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 5 additions & 4 deletions controllers/metal3datatemplate_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ var _ = Describe("Metal3DataTemplate manager", func() {
expectManager: true,
reconcileDeleteError: true,
expectError: true,
expectRequeue: true,
}),
Entry("Paused cluster", testCaseReconcile{
m3dt: &infrav1.Metal3DataTemplate{
Expand Down Expand Up @@ -292,7 +293,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 +308,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
Loading