Skip to content

Commit 619f90c

Browse files
mnenciaarmru
andcommitted
fix: enter deletion path immediately when cluster is being deleted (#9555)
When a cluster has DeletionTimestamp set, skip normal reconciliation and enter the deletion path immediately. This prevents accumulating exponential backoff from failed attempts to create resources in a terminating namespace. Additionally, handle optimistic locking conflicts during finalizer removal by requeueing after 1 second instead of returning an error, avoiding unnecessary backoff delays. Closes #9554 Signed-off-by: Marco Nenciarini <[email protected]> Signed-off-by: Armando Ruocco <[email protected]> Co-authored-by: Armando Ruocco <[email protected]> (cherry picked from commit 36b2304)
1 parent 1e8e907 commit 619f90c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎internal/controller/cluster_controller.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
156156
return ctrl.Result{}, err
157157
}
158158

159-
if cluster == nil {
159+
if cluster == nil || cluster.GetDeletionTimestamp() != nil {
160160
if err := r.deleteDanglingMonitoringQueries(ctx, req.Namespace); err != nil {
161161
contextLogger.Error(
162162
err,
@@ -167,6 +167,15 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
167167
return ctrl.Result{}, err
168168
}
169169
if err := r.notifyDeletionToOwnedResources(ctx, req.NamespacedName); err != nil {
170+
// Optimistic locking conflict is transient - requeue to retry
171+
if apierrs.IsConflict(err) {
172+
contextLogger.Info(
173+
"Optimistic locking conflict while removing finalizers, requeueing",
174+
"clusterName", req.Name,
175+
"namespace", req.Namespace,
176+
)
177+
return ctrl.Result{RequeueAfter: time.Second}, nil
178+
}
170179
contextLogger.Error(
171180
err,
172181
"error while deleting finalizers of objects on the cluster",

0 commit comments

Comments
 (0)