Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/diag/validator/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
crashLoopBackOff = "CrashLoopBackOff"
runContainerError = "RunContainerError"
imagePullErr = "ErrImagePull"
imagePullBackOff = "ImagePullBackOff"
errImagePullBackOff = "ErrImagePullBackOff"
containerCreating = "ContainerCreating"
podKind = "pod"
Expand Down Expand Up @@ -202,14 +203,14 @@ func (p *podStatus) String() string {
}

func extractErrorMessageFromWaitingContainerStatus(c v1.ContainerStatus) (proto.StatusCode, error) {
// Extract meaning full error out of container statuses.
switch c.State.Waiting.Reason {
// Extract meaning full error out of container statuses.
case containerCreating:
return proto.StatusCode_STATUSCHECK_CONTAINER_CREATING, fmt.Errorf("creating container %s", c.Name)
case crashLoopBackOff:
// TODO, in case of container restarting, return the original failure reason due to which container failed.
return proto.StatusCode_STATUSCHECK_CONTAINER_RESTARTING, fmt.Errorf("restarting failed container %s", c.Name)
case imagePullErr, errImagePullBackOff:
case imagePullErr, imagePullBackOff, errImagePullBackOff:
return proto.StatusCode_STATUSCHECK_IMAGE_PULL_ERR, fmt.Errorf("container %s is waiting to start: %s can't be pulled", c.Name, c.Image)
case runContainerError:
match := runContainerRe.FindStringSubmatch(c.State.Waiting.Message)
Expand Down
56 changes: 56 additions & 0 deletions pkg/diag/validator/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,62 @@ func TestRun(t *testing.T) {
fmt.Errorf("container foo-container is waiting to start: foo-image can't be pulled"),
proto.StatusCode_STATUSCHECK_IMAGE_PULL_ERR)},
},
{
description: "pod is Waiting condition due to ErrImageBackOffPullErr",
pods: []*v1.Pod{{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "test",
},
Status: v1.PodStatus{
Phase: v1.PodPending,
Conditions: []v1.PodCondition{{Type: v1.PodScheduled, Status: v1.ConditionTrue}},
ContainerStatuses: []v1.ContainerStatus{
{
Name: "foo-container",
Image: "foo-image",
State: v1.ContainerState{
Waiting: &v1.ContainerStateWaiting{
Reason: "ErrImagePullBackOff",
Message: "rpc error: code = Unknown desc = Error response from daemon: pull access denied for leeroy-web1, repository does not exist or may require 'docker login': denied: requested access to the resource is denied",
},
},
},
},
},
}},
expected: []Resource{NewResource("test", "pod", "foo", "Pending",
fmt.Errorf("container foo-container is waiting to start: foo-image can't be pulled"),
proto.StatusCode_STATUSCHECK_IMAGE_PULL_ERR)},
},
{
description: "pod is Waiting due to Image Backoff Pull error",
pods: []*v1.Pod{{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "test",
},
Status: v1.PodStatus{
Phase: v1.PodPending,
Conditions: []v1.PodCondition{{Type: v1.PodScheduled, Status: v1.ConditionTrue}},
ContainerStatuses: []v1.ContainerStatus{
{
Name: "foo-container",
Image: "foo-image",
State: v1.ContainerState{
Waiting: &v1.ContainerStateWaiting{
Reason: "ImagePullBackOff",
Message: "rpc error: code = Unknown desc = Error response from daemon: pull access denied for leeroy-web1, repository does not exist or may require 'docker login': denied: requested access to the resource is denied",
},
},
},
},
},
}},
expected: []Resource{NewResource("test", "pod", "foo", "Pending",
fmt.Errorf("container foo-container is waiting to start: foo-image can't be pulled"),
proto.StatusCode_STATUSCHECK_IMAGE_PULL_ERR)},
},
{
description: "pod is in Terminated State",
pods: []*v1.Pod{{
Expand Down