Skip to content

Commit bb95d08

Browse files
authored
Merge pull request kubernetes#125603 from mimowo/refactor-enact-finished-job
Refactor enactJobFinished util function for Job controller
2 parents bc3b8f6 + c12bcf4 commit bb95d08

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pkg/controller/job/job_controller.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ func (jm *Controller) trackJobStatusAndRemoveFinalizers(ctx context.Context, job
11781178
if jobCtx.job, needsFlush, err = jm.flushUncountedAndRemoveFinalizers(ctx, jobCtx, podsToRemoveFinalizer, uidsWithFinalizer, &oldCounters, podFailureCountByPolicyAction, needsFlush); err != nil {
11791179
return err
11801180
}
1181-
jobFinished := !reachedMaxUncountedPods && jm.enactJobFinished(jobCtx.job, jobCtx.finishedCondition)
1181+
jobFinished := !reachedMaxUncountedPods && jm.enactJobFinished(logger, jobCtx)
11821182
if jobFinished {
11831183
needsFlush = true
11841184
}
@@ -1353,15 +1353,18 @@ func (jm *Controller) removeTrackingFinalizerFromPods(ctx context.Context, jobKe
13531353

13541354
// enactJobFinished adds the Complete or Failed condition and records events.
13551355
// Returns whether the Job was considered finished.
1356-
func (jm *Controller) enactJobFinished(job *batch.Job, finishedCond *batch.JobCondition) bool {
1357-
if finishedCond == nil {
1356+
func (jm *Controller) enactJobFinished(logger klog.Logger, jobCtx *syncJobCtx) bool {
1357+
if jobCtx.finishedCondition == nil {
13581358
return false
13591359
}
1360+
job := jobCtx.job
13601361
if uncounted := job.Status.UncountedTerminatedPods; uncounted != nil {
1361-
if len(uncounted.Succeeded) > 0 || len(uncounted.Failed) > 0 {
1362+
if count := len(uncounted.Succeeded) + len(uncounted.Failed); count > 0 {
1363+
logger.V(4).Info("Delaying marking the Job as finished, because there are still uncounted pod(s)", "job", klog.KObj(job), "condition", jobCtx.finishedCondition.Type, "count", count)
13621364
return false
13631365
}
13641366
}
1367+
finishedCond := jobCtx.finishedCondition
13651368
job.Status.Conditions, _ = ensureJobConditionStatus(job.Status.Conditions, finishedCond.Type, finishedCond.Status, finishedCond.Reason, finishedCond.Message, jm.clock.Now())
13661369
if finishedCond.Type == batch.JobComplete {
13671370
job.Status.CompletionTime = &finishedCond.LastTransitionTime

0 commit comments

Comments
 (0)