mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #125603 from mimowo/refactor-enact-finished-job
Refactor enactJobFinished util function for Job controller
This commit is contained in:
commit
bb95d084a2
@ -1178,7 +1178,7 @@ func (jm *Controller) trackJobStatusAndRemoveFinalizers(ctx context.Context, job
|
|||||||
if jobCtx.job, needsFlush, err = jm.flushUncountedAndRemoveFinalizers(ctx, jobCtx, podsToRemoveFinalizer, uidsWithFinalizer, &oldCounters, podFailureCountByPolicyAction, needsFlush); err != nil {
|
if jobCtx.job, needsFlush, err = jm.flushUncountedAndRemoveFinalizers(ctx, jobCtx, podsToRemoveFinalizer, uidsWithFinalizer, &oldCounters, podFailureCountByPolicyAction, needsFlush); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
jobFinished := !reachedMaxUncountedPods && jm.enactJobFinished(jobCtx.job, jobCtx.finishedCondition)
|
jobFinished := !reachedMaxUncountedPods && jm.enactJobFinished(logger, jobCtx)
|
||||||
if jobFinished {
|
if jobFinished {
|
||||||
needsFlush = true
|
needsFlush = true
|
||||||
}
|
}
|
||||||
@ -1353,15 +1353,18 @@ func (jm *Controller) removeTrackingFinalizerFromPods(ctx context.Context, jobKe
|
|||||||
|
|
||||||
// enactJobFinished adds the Complete or Failed condition and records events.
|
// enactJobFinished adds the Complete or Failed condition and records events.
|
||||||
// Returns whether the Job was considered finished.
|
// Returns whether the Job was considered finished.
|
||||||
func (jm *Controller) enactJobFinished(job *batch.Job, finishedCond *batch.JobCondition) bool {
|
func (jm *Controller) enactJobFinished(logger klog.Logger, jobCtx *syncJobCtx) bool {
|
||||||
if finishedCond == nil {
|
if jobCtx.finishedCondition == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
job := jobCtx.job
|
||||||
if uncounted := job.Status.UncountedTerminatedPods; uncounted != nil {
|
if uncounted := job.Status.UncountedTerminatedPods; uncounted != nil {
|
||||||
if len(uncounted.Succeeded) > 0 || len(uncounted.Failed) > 0 {
|
if count := len(uncounted.Succeeded) + len(uncounted.Failed); count > 0 {
|
||||||
|
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)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finishedCond := jobCtx.finishedCondition
|
||||||
job.Status.Conditions, _ = ensureJobConditionStatus(job.Status.Conditions, finishedCond.Type, finishedCond.Status, finishedCond.Reason, finishedCond.Message, jm.clock.Now())
|
job.Status.Conditions, _ = ensureJobConditionStatus(job.Status.Conditions, finishedCond.Type, finishedCond.Status, finishedCond.Reason, finishedCond.Message, jm.clock.Now())
|
||||||
if finishedCond.Type == batch.JobComplete {
|
if finishedCond.Type == batch.JobComplete {
|
||||||
job.Status.CompletionTime = &finishedCond.LastTransitionTime
|
job.Status.CompletionTime = &finishedCond.LastTransitionTime
|
||||||
|
Loading…
Reference in New Issue
Block a user