Skip to content

Commit

Permalink
Include Image name in image pull error message (#1718)
Browse files Browse the repository at this point in the history
* add image name in error of image pull

Signed-off-by: DiptoChakrabarty <diptochuck123@gmail.com>

* fix format for image name

Signed-off-by: DiptoChakrabarty <diptochuck123@gmail.com>

* fix sytax error

Signed-off-by: DiptoChakrabarty <diptochuck123@gmail.com>
  • Loading branch information
DiptoChakrabarty authored May 27, 2022
1 parent 87e26ab commit c4593e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/plugin/driver/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func IsPodFailing(pod *v1.Pod) (bool, string) {
if waiting := cstatus.State.Waiting; waiting != nil && pod.Status.StartTime != nil {
elapsedPodTime := time.Since(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)
errstr := fmt.Sprintf("Failed to pull image %v for container %v within %v. Container is in state %v", cstatus.Image, cstatus.Name, maxWaitForImageTime, waiting.Reason)
return true, errstr
}
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/plugin/driver/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ func TestPodFailing(t *testing.T) {
}, {
desc: "ImagePullBackOff is considered a failure if elapsed time greater than wait window",
expectFailing: true,
expectMsg: "Failed to pull image for container error-container within 5m0s. Container is in state ImagePullBackOff",
expectMsg: "Failed to pull image random-image for container error-container within 5m0s. Container is in state ImagePullBackOff",
pod: fromGoodPod(func(p *corev1.Pod) *corev1.Pod {
p.Status.StartTime = &metav1.Time{Time: time.Now().Add(-maxWaitForImageTime)}
p.Status.ContainerStatuses = []corev1.ContainerStatus{
{
Name: "error-container",
Name: "error-container",
Image: "random-image",
State: corev1.ContainerState{
Waiting: &corev1.ContainerStateWaiting{
Reason: "ImagePullBackOff",
Expand All @@ -126,12 +127,13 @@ func TestPodFailing(t *testing.T) {
}, {
desc: "ErrImagePull is considered a failure if elapsed time greater than wait window",
expectFailing: true,
expectMsg: "Failed to pull image for container error-container within 5m0s. Container is in state ErrImagePull",
expectMsg: "Failed to pull image random-image for container error-container within 5m0s. Container is in state ErrImagePull",
pod: fromGoodPod(func(p *corev1.Pod) *corev1.Pod {
p.Status.StartTime = &metav1.Time{Time: time.Now().Add(-maxWaitForImageTime)}
p.Status.ContainerStatuses = []corev1.ContainerStatus{
{
Name: "error-container",
Name: "error-container",
Image: "random-image",
State: corev1.ContainerState{
Waiting: &corev1.ContainerStateWaiting{
Reason: "ErrImagePull",
Expand Down

0 comments on commit c4593e0

Please sign in to comment.