Skip to content

Commit 9feb0df

Browse files
committed
Add pending status for pastBackoffLimitOnFailure
1 parent e9af72c commit 9feb0df

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

pkg/controller/job/job_controller.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -631,16 +631,15 @@ func pastBackoffLimitOnFailure(job *batch.Job, pods []*v1.Pod) bool {
631631
result := int32(0)
632632
for i := range pods {
633633
po := pods[i]
634-
if po.Status.Phase != v1.PodRunning {
635-
continue
636-
}
637-
for j := range po.Status.InitContainerStatuses {
638-
stat := po.Status.InitContainerStatuses[j]
639-
result += stat.RestartCount
640-
}
641-
for j := range po.Status.ContainerStatuses {
642-
stat := po.Status.ContainerStatuses[j]
643-
result += stat.RestartCount
634+
if po.Status.Phase == v1.PodRunning || po.Status.Phase == v1.PodPending {
635+
for j := range po.Status.InitContainerStatuses {
636+
stat := po.Status.InitContainerStatuses[j]
637+
result += stat.RestartCount
638+
}
639+
for j := range po.Status.ContainerStatuses {
640+
stat := po.Status.ContainerStatuses[j]
641+
result += stat.RestartCount
642+
}
644643
}
645644
}
646645
if *job.Spec.BackoffLimit == 0 {

pkg/controller/job/job_controller_test.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,7 @@ func TestJobBackoffForOnFailure(t *testing.T) {
14141414
// pod setup
14151415
jobKeyForget bool
14161416
restartCounts []int32
1417+
podPhase v1.PodPhase
14171418

14181419
// expectations
14191420
expectedActive int32
@@ -1424,32 +1425,47 @@ func TestJobBackoffForOnFailure(t *testing.T) {
14241425
}{
14251426
"backoffLimit 0 should have 1 pod active": {
14261427
1, 1, 0,
1427-
true, []int32{0},
1428+
true, []int32{0}, v1.PodRunning,
14281429
1, 0, 0, nil, "",
14291430
},
14301431
"backoffLimit 1 with restartCount 0 should have 1 pod active": {
14311432
1, 1, 1,
1432-
true, []int32{0},
1433+
true, []int32{0}, v1.PodRunning,
14331434
1, 0, 0, nil, "",
14341435
},
1435-
"backoffLimit 1 with restartCount 1 should have 0 pod active": {
1436+
"backoffLimit 1 with restartCount 1 and podRunning should have 0 pod active": {
14361437
1, 1, 1,
1437-
true, []int32{1},
1438+
true, []int32{1}, v1.PodRunning,
14381439
0, 0, 1, &jobConditionFailed, "BackoffLimitExceeded",
14391440
},
1440-
"too many job failures - single pod": {
1441+
"backoffLimit 1 with restartCount 1 and podPending should have 0 pod active": {
1442+
1, 1, 1,
1443+
true, []int32{1}, v1.PodPending,
1444+
0, 0, 1, &jobConditionFailed, "BackoffLimitExceeded",
1445+
},
1446+
"too many job failures with podRunning - single pod": {
14411447
1, 5, 2,
1442-
true, []int32{2},
1448+
true, []int32{2}, v1.PodRunning,
14431449
0, 0, 1, &jobConditionFailed, "BackoffLimitExceeded",
14441450
},
1445-
"too many job failures - multiple pods": {
1451+
"too many job failures with podPending - single pod": {
1452+
1, 5, 2,
1453+
true, []int32{2}, v1.PodPending,
1454+
0, 0, 1, &jobConditionFailed, "BackoffLimitExceeded",
1455+
},
1456+
"too many job failures with podRunning - multiple pods": {
1457+
2, 5, 2,
1458+
true, []int32{1, 1}, v1.PodRunning,
1459+
0, 0, 2, &jobConditionFailed, "BackoffLimitExceeded",
1460+
},
1461+
"too many job failures with podPending - multiple pods": {
14461462
2, 5, 2,
1447-
true, []int32{1, 1},
1463+
true, []int32{1, 1}, v1.PodPending,
14481464
0, 0, 2, &jobConditionFailed, "BackoffLimitExceeded",
14491465
},
14501466
"not enough failures": {
14511467
2, 5, 3,
1452-
true, []int32{1, 1},
1468+
true, []int32{1, 1}, v1.PodRunning,
14531469
2, 0, 0, nil, "",
14541470
},
14551471
}
@@ -1474,7 +1490,7 @@ func TestJobBackoffForOnFailure(t *testing.T) {
14741490
job.Spec.Template.Spec.RestartPolicy = v1.RestartPolicyOnFailure
14751491
sharedInformerFactory.Batch().V1().Jobs().Informer().GetIndexer().Add(job)
14761492
podIndexer := sharedInformerFactory.Core().V1().Pods().Informer().GetIndexer()
1477-
for i, pod := range newPodList(int32(len(tc.restartCounts)), v1.PodRunning, job) {
1493+
for i, pod := range newPodList(int32(len(tc.restartCounts)), tc.podPhase, job) {
14781494
pod.Status.ContainerStatuses = []v1.ContainerStatus{{RestartCount: tc.restartCounts[i]}}
14791495
podIndexer.Add(&pod)
14801496
}

0 commit comments

Comments
 (0)