From 0bd901afeaa55ebe8d634a97b97c84026fc270ae Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 16 Sep 2022 08:58:07 +0200 Subject: [PATCH] e2e framework: better error messages when pod has failed or completed Getting a message about "pod ran to completion" is confusing when the pod hasn't been able to start at all. The failed state now has a different message. To address the previous ambiguity, the success state is described as "ran to completion successfully". --- test/e2e/framework/pod/resource.go | 6 +++++- test/e2e/framework/pod/wait.go | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test/e2e/framework/pod/resource.go b/test/e2e/framework/pod/resource.go index 4f3765dfb09..0adc985f3ca 100644 --- a/test/e2e/framework/pod/resource.go +++ b/test/e2e/framework/pod/resource.go @@ -41,7 +41,11 @@ import ( // errPodCompleted is returned by PodRunning or PodContainerRunning to indicate that // the pod has already reached completed state. -var errPodCompleted = fmt.Errorf("pod ran to completion") +var errPodCompleted = fmt.Errorf("pod ran to completion successfully") + +// errPodFailed is returned by PodRunning or PodContainerRunning to indicate that +// the pod has already reached a permanent failue state. +var errPodFailed = fmt.Errorf("pod failed permanently") // LabelLogOnPodFailure can be used to mark which Pods will have their logs logged in the case of // a test failure. By default, if there are no Pods with this label, only the first 5 Pods will diff --git a/test/e2e/framework/pod/wait.go b/test/e2e/framework/pod/wait.go index da490106f0c..5f97f7c0e61 100644 --- a/test/e2e/framework/pod/wait.go +++ b/test/e2e/framework/pod/wait.go @@ -403,7 +403,9 @@ func WaitTimeoutForPodRunningInNamespace(c clientset.Interface, podName, namespa switch pod.Status.Phase { case v1.PodRunning: return true, nil - case v1.PodFailed, v1.PodSucceeded: + case v1.PodFailed: + return false, errPodFailed + case v1.PodSucceeded: return false, errPodCompleted } return false, nil @@ -441,7 +443,10 @@ func WaitForPodNoLongerRunningInNamespace(c clientset.Interface, podName, namesp func WaitTimeoutForPodReadyInNamespace(c clientset.Interface, podName, namespace string, timeout time.Duration) error { return WaitForPodCondition(c, namespace, podName, "running and ready", timeout, func(pod *v1.Pod) (bool, error) { switch pod.Status.Phase { - case v1.PodFailed, v1.PodSucceeded: + case v1.PodFailed: + e2elog.Logf("The phase of Pod %s is %s which is unexpected, pod status: %#v", pod.Name, pod.Status.Phase, pod.Status) + return false, errPodFailed + case v1.PodSucceeded: e2elog.Logf("The phase of Pod %s is %s which is unexpected, pod status: %#v", pod.Name, pod.Status.Phase, pod.Status) return false, errPodCompleted case v1.PodRunning: