Skip to content

Commit

Permalink
Fix crash when running sonobuoy in serverless kubernetes cluster (#1108)
Browse files Browse the repository at this point in the history
In serverless kubernetes clusters, pods may need up to 10s to start after creation. Before the container starts, `pod.Status.StartTime` is nil which caused a panic in the `IsPodFailing` check.
  • Loading branch information
jovizhangwei authored Apr 24, 2020
1 parent 7d97bde commit b1016cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/plugin/driver/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func IsPodFailing(pod *v1.Pod) (bool, string) {
}

// Check if it can't fetch its image within the maximum wait time
if waiting := cstatus.State.Waiting; waiting != nil {
if waiting := cstatus.State.Waiting; waiting != nil && pod.Status.StartTime != nil {
elapsedPodTime := time.Now().Sub(pod.Status.StartTime.Time)
if elapsedPodTime > maxWaitForImageTime && (waiting.Reason == "ImagePullBackOff" || waiting.Reason == "ErrImagePull") {
errstr := fmt.Sprintf("Failed to pull image for container %v within %v. Container is in state %v", cstatus.Name, maxWaitForImageTime, waiting.Reason)
Expand Down
15 changes: 15 additions & 0 deletions pkg/plugin/driver/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ func TestPodFailing(t *testing.T) {
}
return p
}),
}, {
desc: "Does not panic if StartTime is nil when container status is waiting",
expectFailing: false,
expectMsg: "",
pod: fromGoodPod(func(p *corev1.Pod) *corev1.Pod {
p.Status.StartTime = nil
p.Status.ContainerStatuses = []corev1.ContainerStatus{
{State: corev1.ContainerState{
Waiting: &corev1.ContainerStateWaiting{
Reason: "ImagePullBackOff",
},
}},
}
return p
}),
}, {
desc: "ImagePullBackOff is not considered a failure if elapsed time within wait window",
expectFailing: false,
Expand Down

0 comments on commit b1016cc

Please sign in to comment.