Skip to content

Commit 6447771

Browse files
committed
invoke pre-delete hooks before checking blocking dependents/finalizers
1 parent f56cc78 commit 6447771

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

pkg/component/reconcile.go

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func (r *Reconciler[T]) Reconcile(ctx context.Context, req ctrl.Request) (result
273273
}
274274
}
275275
// TODO: should we move this behind the DeepEqual check below?
276-
// TODO: follow-up on missing events
276+
// note: it seems that no events will be written if the component's namespace is in deletion
277277
state, reason, message := status.GetState()
278278
if state == StateError {
279279
r.client.EventRecorder().Event(component, corev1.EventTypeWarning, reason, message)
@@ -360,33 +360,36 @@ func (r *Reconciler[T]) Reconcile(ctx context.Context, req ctrl.Request) (result
360360
}
361361
return ctrl.Result{RequeueAfter: r.backoff.Next(req, readyConditionReasonProcessing)}, nil
362362
}
363-
} else if allowed, msg, err := target.IsDeletionAllowed(ctx, component); err != nil || !allowed {
364-
// deletion is blocked because of existing managed CROs and so on
365-
// TODO: eliminate this msg logic
366-
if err != nil {
367-
log.V(1).Info("error while checking if deletion is allowed")
368-
return ctrl.Result{}, errors.Wrap(err, "error checking whether deletion is possible")
369-
}
370-
log.V(1).Info("deletion not allowed")
371-
// TODO: have an additional StateDeletionBlocked?
372-
status.SetState(StateDeleting, readyConditionReasonDeletionBlocked, "Deletion blocked: "+msg)
373-
r.client.EventRecorder().Event(component, corev1.EventTypeNormal, readyConditionReasonDeletionBlocked, "Deletion blocked: "+msg)
374-
return ctrl.Result{RequeueAfter: 1*time.Second + r.backoff.Next(req, readyConditionReasonDeletionBlocked)}, nil
375-
} else if len(slices.Remove(component.GetFinalizers(), r.name)) > 0 {
376-
// deletion is blocked because of foreign finalizers
377-
log.V(1).Info("deleted blocked due to existence of foreign finalizers")
378-
// TODO: have an additional StateDeletionBlocked?
379-
status.SetState(StateDeleting, readyConditionReasonDeletionBlocked, "Deletion blocked due to existing foreign finalizers")
380-
r.client.EventRecorder().Event(component, corev1.EventTypeNormal, readyConditionReasonDeletionBlocked, "Deletion blocked due to existing foreign finalizers")
381-
return ctrl.Result{RequeueAfter: 1*time.Second + r.backoff.Next(req, readyConditionReasonDeletionBlocked)}, nil
382363
} else {
383-
// deletion case
384-
log.V(2).Info("deleting dependent resources")
385364
for hookOrder, hook := range r.preDeleteHooks {
386365
if err := hook(hookCtx, r.client, component); err != nil {
387366
return ctrl.Result{}, errors.Wrapf(err, "error running pre-delete hook (%d)", hookOrder)
388367
}
389368
}
369+
allowed, msg, err := target.IsDeletionAllowed(ctx, component)
370+
if err != nil {
371+
log.V(1).Info("error while checking if deletion is allowed")
372+
return ctrl.Result{}, errors.Wrap(err, "error checking whether deletion is possible")
373+
}
374+
if !allowed {
375+
// deletion is blocked because of existing managed CROs and so on
376+
log.V(1).Info("deletion not allowed")
377+
// TODO: have an additional StateDeletionBlocked?
378+
// TODO: eliminate this msg logic
379+
status.SetState(StateDeleting, readyConditionReasonDeletionBlocked, "Deletion blocked: "+msg)
380+
r.client.EventRecorder().Event(component, corev1.EventTypeNormal, readyConditionReasonDeletionBlocked, "Deletion blocked: "+msg)
381+
return ctrl.Result{RequeueAfter: 1*time.Second + r.backoff.Next(req, readyConditionReasonDeletionBlocked)}, nil
382+
}
383+
if len(slices.Remove(component.GetFinalizers(), r.name)) > 0 {
384+
// deletion is blocked because of foreign finalizers
385+
log.V(1).Info("deleted blocked due to existence of foreign finalizers")
386+
// TODO: have an additional StateDeletionBlocked?
387+
status.SetState(StateDeleting, readyConditionReasonDeletionBlocked, "Deletion blocked due to existing foreign finalizers")
388+
r.client.EventRecorder().Event(component, corev1.EventTypeNormal, readyConditionReasonDeletionBlocked, "Deletion blocked due to existing foreign finalizers")
389+
return ctrl.Result{RequeueAfter: 1*time.Second + r.backoff.Next(req, readyConditionReasonDeletionBlocked)}, nil
390+
}
391+
// deletion case
392+
log.V(2).Info("deleting dependent resources")
390393
ok, err := target.Delete(ctx, component)
391394
if err != nil {
392395
log.V(1).Info("error while deleting dependent resources")

0 commit comments

Comments
 (0)