Skip to content

Commit afb0007

Browse files
Merge pull request #337 from wangyuqing4/panic
fix ExitCode panic
2 parents 57473f8 + 02b8436 commit afb0007

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pkg/controllers/job/job_controller_handler.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ func (cc *Controller) updatePod(oldObj, newObj interface{}) {
234234
event = vkbatchv1.PodFailedEvent
235235
// TODO: currently only one container pod is supported by volcano
236236
// Once multi containers pod is supported, update accordingly.
237-
exitCode = newPod.Status.ContainerStatuses[0].State.Terminated.ExitCode
237+
if len(newPod.Status.ContainerStatuses) > 0 && newPod.Status.ContainerStatuses[0].State.Terminated != nil {
238+
exitCode = newPod.Status.ContainerStatuses[0].State.Terminated.ExitCode
239+
}
238240
}
239241

240242
if oldPod.Status.Phase != v1.PodSucceeded &&

pkg/controllers/job/job_controller_handler_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,23 @@ func TestUpdatePodFunc(t *testing.T) {
365365
},
366366
ExpectedValue: v1.PodRunning,
367367
},
368+
{
369+
Name: "UpdatePod Failed case",
370+
Job: &vkbatchv1.Job{
371+
ObjectMeta: metav1.ObjectMeta{
372+
Name: "job1",
373+
Namespace: namespace,
374+
},
375+
},
376+
oldPod: buildPod(namespace, "pod1", v1.PodPending, nil),
377+
newPod: buildPod(namespace, "pod1", v1.PodFailed, nil),
378+
Annotation: map[string]string{
379+
vkbatchv1.JobNameKey: "job1",
380+
vkbatchv1.JobVersion: "0",
381+
vkbatchv1.TaskSpecKey: "task1",
382+
},
383+
ExpectedValue: v1.PodFailed,
384+
},
368385
}
369386

370387
for i, testcase := range testcases {

0 commit comments

Comments
 (0)