Skip to content

Commit 5fde2e4

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 9d5bc29 commit 5fde2e4

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
@@ -162,7 +162,7 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
162162
return ctrl.Result{}, err
163163
}
164164

165-
if cluster == nil {
165+
if cluster == nil || cluster.GetDeletionTimestamp() != nil {
166166
if err := r.deleteDanglingMonitoringQueries(ctx, req.Namespace); err != nil {
167167
contextLogger.Error(
168168
err,
@@ -173,6 +173,15 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
173173
return ctrl.Result{}, err
174174
}
175175
if err := r.notifyDeletionToOwnedResources(ctx, req.NamespacedName); err != nil {
176+
// Optimistic locking conflict is transient - requeue to retry
177+
if apierrs.IsConflict(err) {
178+
contextLogger.Info(
179+
"Optimistic locking conflict while removing finalizers, requeueing",
180+
"clusterName", req.Name,
181+
"namespace", req.Namespace,
182+
)
183+
return ctrl.Result{RequeueAfter: time.Second}, nil
184+
}
176185
contextLogger.Error(
177186
err,
178187
"error while deleting finalizers of objects on the cluster",

0 commit comments

Comments
 (0)