Skip to content

Commit be3ea4f

Browse files
committed
fix: requeue immediately on conflict when removing finalizer
1 parent ff5ad68 commit be3ea4f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

internal/controller/job_controller.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,17 @@ func (r *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
7777
return ctrl.Result{}, err
7878
}
7979

80-
// If the job status is `done`, we have nothing to do
80+
// If the job status is `done`, we have nothing to do, should remove finalizer if set
8181
if sfs.Annotations[iamProbeStatus] == iamProbeDone {
82+
if controllerutil.RemoveFinalizer(&job, finalizerName) {
83+
if err := r.Update(ctx, &job); err != nil {
84+
if apierrors.IsConflict(err) {
85+
return ctrl.Result{Requeue: true}, nil
86+
}
87+
log.Error(err, "failed to remove finalizer")
88+
return ctrl.Result{}, err
89+
}
90+
}
8291
return ctrl.Result{}, nil
8392
}
8493

@@ -152,6 +161,9 @@ func (r *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
152161

153162
if controllerutil.RemoveFinalizer(&job, finalizerName) {
154163
if err := r.Update(ctx, &job); err != nil {
164+
if apierrors.IsConflict(err) {
165+
return ctrl.Result{Requeue: true}, nil
166+
}
155167
log.Error(err, "failed to remove finalizer")
156168
return ctrl.Result{}, err
157169
}

0 commit comments

Comments
 (0)