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

[1.25] pkg/controller/job: re-honor exponential backoff #115022

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions pkg/controller/job/job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,10 @@ func (jm *Controller) updatePod(old, cur interface{}) {
return
}

// the only time we want the backoff to kick-in, is when the pod failed
immediate := curPod.Status.Phase != v1.PodFailed
// the only time we want the backoff to kick-in, is when the pod failed for the first time.
// we don't want to re-calculate backoff for an update event when the tracking finalizer
// for a failed pod is removed.
immediate := !(curPod.Status.Phase == v1.PodFailed && oldPod.Status.Phase != v1.PodFailed)

// Don't check if oldPod has the finalizer, as during ownership transfer
// finalizers might be re-added and removed again in behalf of the new owner.
Expand Down Expand Up @@ -498,7 +500,9 @@ func (jm *Controller) enqueueControllerDelayed(obj interface{}, immediate bool,

backoff := delay
if !immediate {
backoff = getBackoff(jm.queue, key)
if calculatedBackoff := getBackoff(jm.queue, key); calculatedBackoff > 0 {
backoff = calculatedBackoff
}
}

// TODO: Handle overlapping controllers better. Either disallow them at admission time or
Expand Down Expand Up @@ -879,14 +883,22 @@ func (jm *Controller) syncJob(ctx context.Context, key string) (forget bool, rEr
job.Status.Ready = ready
err = jm.trackJobStatusAndRemoveFinalizers(ctx, &job, pods, prevSucceededIndexes, *uncounted, expectedRmFinalizers, finishedCondition, needsStatusUpdate)
if err != nil {
if apierrors.IsConflict(err) {
// we probably have a stale informer cache
// so don't return an error to avoid backoff
jm.enqueueController(&job, false)
return false, nil
}
return false, fmt.Errorf("tracking status: %w", err)
}
jobFinished := IsJobFinished(&job)
if jobHasNewFailure && !jobFinished {
// returning an error will re-enqueue Job after the backoff period
return forget, fmt.Errorf("failed pod(s) detected for job key %q", key)
}
forget = true
if suspendCondChanged {
forget = true
}
return forget, manageJobErr
}
// Legacy path: tracking without finalizers.
Expand Down Expand Up @@ -917,7 +929,9 @@ func (jm *Controller) syncJob(ctx context.Context, key string) (forget bool, rEr
return forget, fmt.Errorf("failed pod(s) detected for job key %q", key)
}

forget = true
if suspendCondChanged {
forget = true
}
}

return forget, manageJobErr
Expand Down