Skip to content

Commit fc25f6b

Browse files
authored
Merge pull request #4269 from tejal29/small_upgrades
Collapse ImagePullBackOff and ErrImagePullBackOff together
2 parents cce35f6 + 35e0ee6 commit fc25f6b

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

pkg/diag/validator/pod.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838
crashLoopBackOff = "CrashLoopBackOff"
3939
runContainerError = "RunContainerError"
4040
imagePullErr = "ErrImagePull"
41+
imagePullBackOff = "ImagePullBackOff"
4142
errImagePullBackOff = "ErrImagePullBackOff"
4243
containerCreating = "ContainerCreating"
4344
podKind = "pod"
@@ -202,14 +203,14 @@ func (p *podStatus) String() string {
202203
}
203204

204205
func extractErrorMessageFromWaitingContainerStatus(c v1.ContainerStatus) (proto.StatusCode, error) {
205-
// Extract meaning full error out of container statuses.
206206
switch c.State.Waiting.Reason {
207+
// Extract meaning full error out of container statuses.
207208
case containerCreating:
208209
return proto.StatusCode_STATUSCHECK_CONTAINER_CREATING, fmt.Errorf("creating container %s", c.Name)
209210
case crashLoopBackOff:
210211
// TODO, in case of container restarting, return the original failure reason due to which container failed.
211212
return proto.StatusCode_STATUSCHECK_CONTAINER_RESTARTING, fmt.Errorf("restarting failed container %s", c.Name)
212-
case imagePullErr, errImagePullBackOff:
213+
case imagePullErr, imagePullBackOff, errImagePullBackOff:
213214
return proto.StatusCode_STATUSCHECK_IMAGE_PULL_ERR, fmt.Errorf("container %s is waiting to start: %s can't be pulled", c.Name, c.Image)
214215
case runContainerError:
215216
match := runContainerRe.FindStringSubmatch(c.State.Waiting.Message)

pkg/diag/validator/pod_test.go

+56
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,62 @@ func TestRun(t *testing.T) {
7575
fmt.Errorf("container foo-container is waiting to start: foo-image can't be pulled"),
7676
proto.StatusCode_STATUSCHECK_IMAGE_PULL_ERR)},
7777
},
78+
{
79+
description: "pod is Waiting condition due to ErrImageBackOffPullErr",
80+
pods: []*v1.Pod{{
81+
ObjectMeta: metav1.ObjectMeta{
82+
Name: "foo",
83+
Namespace: "test",
84+
},
85+
Status: v1.PodStatus{
86+
Phase: v1.PodPending,
87+
Conditions: []v1.PodCondition{{Type: v1.PodScheduled, Status: v1.ConditionTrue}},
88+
ContainerStatuses: []v1.ContainerStatus{
89+
{
90+
Name: "foo-container",
91+
Image: "foo-image",
92+
State: v1.ContainerState{
93+
Waiting: &v1.ContainerStateWaiting{
94+
Reason: "ErrImagePullBackOff",
95+
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",
96+
},
97+
},
98+
},
99+
},
100+
},
101+
}},
102+
expected: []Resource{NewResource("test", "pod", "foo", "Pending",
103+
fmt.Errorf("container foo-container is waiting to start: foo-image can't be pulled"),
104+
proto.StatusCode_STATUSCHECK_IMAGE_PULL_ERR)},
105+
},
106+
{
107+
description: "pod is Waiting due to Image Backoff Pull error",
108+
pods: []*v1.Pod{{
109+
ObjectMeta: metav1.ObjectMeta{
110+
Name: "foo",
111+
Namespace: "test",
112+
},
113+
Status: v1.PodStatus{
114+
Phase: v1.PodPending,
115+
Conditions: []v1.PodCondition{{Type: v1.PodScheduled, Status: v1.ConditionTrue}},
116+
ContainerStatuses: []v1.ContainerStatus{
117+
{
118+
Name: "foo-container",
119+
Image: "foo-image",
120+
State: v1.ContainerState{
121+
Waiting: &v1.ContainerStateWaiting{
122+
Reason: "ImagePullBackOff",
123+
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",
124+
},
125+
},
126+
},
127+
},
128+
},
129+
}},
130+
expected: []Resource{NewResource("test", "pod", "foo", "Pending",
131+
fmt.Errorf("container foo-container is waiting to start: foo-image can't be pulled"),
132+
proto.StatusCode_STATUSCHECK_IMAGE_PULL_ERR)},
133+
},
78134
{
79135
description: "pod is in Terminated State",
80136
pods: []*v1.Pod{{

0 commit comments

Comments
 (0)