Skip to content

Commit

Permalink
Merge pull request #337 from wangyuqing4/panic
Browse files Browse the repository at this point in the history
fix ExitCode panic
  • Loading branch information
volcano-sh-bot authored Jul 15, 2019
2 parents 57473f8 + 02b8436 commit afb0007
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/controllers/job/job_controller_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ func (cc *Controller) updatePod(oldObj, newObj interface{}) {
event = vkbatchv1.PodFailedEvent
// TODO: currently only one container pod is supported by volcano
// Once multi containers pod is supported, update accordingly.
exitCode = newPod.Status.ContainerStatuses[0].State.Terminated.ExitCode
if len(newPod.Status.ContainerStatuses) > 0 && newPod.Status.ContainerStatuses[0].State.Terminated != nil {
exitCode = newPod.Status.ContainerStatuses[0].State.Terminated.ExitCode
}
}

if oldPod.Status.Phase != v1.PodSucceeded &&
Expand Down
17 changes: 17 additions & 0 deletions pkg/controllers/job/job_controller_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,23 @@ func TestUpdatePodFunc(t *testing.T) {
},
ExpectedValue: v1.PodRunning,
},
{
Name: "UpdatePod Failed case",
Job: &vkbatchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "job1",
Namespace: namespace,
},
},
oldPod: buildPod(namespace, "pod1", v1.PodPending, nil),
newPod: buildPod(namespace, "pod1", v1.PodFailed, nil),
Annotation: map[string]string{
vkbatchv1.JobNameKey: "job1",
vkbatchv1.JobVersion: "0",
vkbatchv1.TaskSpecKey: "task1",
},
ExpectedValue: v1.PodFailed,
},
}

for i, testcase := range testcases {
Expand Down

0 comments on commit afb0007

Please sign in to comment.