mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #99963 from alculquicondor/job_complete_active
Remove active pods past completions
This commit is contained in:
commit
0172cbf56c
@ -568,11 +568,8 @@ func (jm *Controller) syncJob(key string) (bool, error) {
|
||||
// success by having that number of successes. Since we do not
|
||||
// start more pods than there are remaining completions, there should
|
||||
// not be any remaining active pods once this count is reached.
|
||||
if completions >= *job.Spec.Completions {
|
||||
if completions >= *job.Spec.Completions && active == 0 {
|
||||
complete = true
|
||||
if active > 0 {
|
||||
jm.recorder.Event(&job, v1.EventTypeWarning, "TooManyActivePods", "Too many active pods running after completion count reached")
|
||||
}
|
||||
if completions > *job.Spec.Completions {
|
||||
jm.recorder.Event(&job, v1.EventTypeWarning, "TooManySucceededPods", "Too many succeeded pods running after completion count reached")
|
||||
}
|
||||
@ -762,22 +759,6 @@ func (jm *Controller) manageJob(job *batch.Job, activePods []*v1.Pod, succeeded
|
||||
return active, err
|
||||
}
|
||||
|
||||
rmAtLeast := active - parallelism
|
||||
if rmAtLeast < 0 {
|
||||
rmAtLeast = 0
|
||||
}
|
||||
podsToDelete := activePodsForRemoval(job, activePods, int(rmAtLeast))
|
||||
if len(podsToDelete) > 0 {
|
||||
jm.expectations.ExpectDeletions(jobKey, len(podsToDelete))
|
||||
klog.V(4).InfoS("Too many pods running for job", "job", klog.KObj(job), "deleted", rmAtLeast, "target", parallelism)
|
||||
removed, err := jm.deleteJobPods(job, jobKey, podsToDelete)
|
||||
active -= removed
|
||||
if err != nil {
|
||||
return active, err
|
||||
}
|
||||
}
|
||||
|
||||
if active < parallelism {
|
||||
wantActive := int32(0)
|
||||
if job.Spec.Completions == nil {
|
||||
// Job does not specify a number of completions. Therefore, number active
|
||||
@ -796,6 +777,23 @@ func (jm *Controller) manageJob(job *batch.Job, activePods []*v1.Pod, succeeded
|
||||
wantActive = parallelism
|
||||
}
|
||||
}
|
||||
|
||||
rmAtLeast := active - wantActive
|
||||
if rmAtLeast < 0 {
|
||||
rmAtLeast = 0
|
||||
}
|
||||
podsToDelete := activePodsForRemoval(job, activePods, int(rmAtLeast))
|
||||
if len(podsToDelete) > 0 {
|
||||
jm.expectations.ExpectDeletions(jobKey, len(podsToDelete))
|
||||
klog.V(4).InfoS("Too many pods running for job", "job", klog.KObj(job), "deleted", len(podsToDelete), "target", parallelism)
|
||||
removed, err := jm.deleteJobPods(job, jobKey, podsToDelete)
|
||||
active -= removed
|
||||
if err != nil {
|
||||
return active, err
|
||||
}
|
||||
}
|
||||
|
||||
if active < wantActive {
|
||||
diff := wantActive - active
|
||||
if diff < 0 {
|
||||
utilruntime.HandleError(fmt.Errorf("More active than wanted: job %q, want %d, have %d", jobKey, wantActive, active))
|
||||
|
@ -366,7 +366,7 @@ func TestControllerSyncJob(t *testing.T) {
|
||||
expectedCondition: &jobConditionComplete,
|
||||
expectedConditionStatus: v1.ConditionTrue,
|
||||
},
|
||||
"more active pods than completions": {
|
||||
"more active pods than parallelism": {
|
||||
parallelism: 2,
|
||||
completions: 5,
|
||||
backoffLimit: 6,
|
||||
@ -375,6 +375,17 @@ func TestControllerSyncJob(t *testing.T) {
|
||||
expectedDeletions: 8,
|
||||
expectedActive: 2,
|
||||
},
|
||||
"more active pods than remaining completions": {
|
||||
parallelism: 3,
|
||||
completions: 4,
|
||||
backoffLimit: 6,
|
||||
jobKeyForget: true,
|
||||
activePods: 3,
|
||||
succeededPods: 2,
|
||||
expectedDeletions: 1,
|
||||
expectedActive: 2,
|
||||
expectedSucceeded: 2,
|
||||
},
|
||||
"status change": {
|
||||
parallelism: 2,
|
||||
completions: 5,
|
||||
|
Loading…
Reference in New Issue
Block a user