From 1f186fc662672391913eb7ebdc33bfe66193c604 Mon Sep 17 00:00:00 2001 From: jeff vance Date: Wed, 26 Jul 2017 14:16:07 -0700 Subject: [PATCH 1/2] improve detectability of deleted pods --- test/e2e/framework/util.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index b783d33b11f..6ae6d20e1c4 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -1359,14 +1359,14 @@ func podNotPending(c clientset.Interface, podName, namespace string) wait.Condit // to terminate or if the pod terminated with an unexpected reason. func waitForPodTerminatedInNamespace(c clientset.Interface, podName, reason, namespace string) error { return WaitForPodCondition(c, namespace, podName, "terminated due to deadline exceeded", PodStartTimeout, func(pod *v1.Pod) (bool, error) { - if pod.Status.Phase == v1.PodFailed { - if pod.Status.Reason == reason { + if pod.Status.Phase == v1.PodSucceeded || pod.Status.Phase == v1.PodFailed { + if reason == "" || + strings.ToLower(strings.TrimSpace(pod.Status.Reason)) == strings.ToLower(strings.TrimSpace(reason)) { return true, nil } else { - return true, fmt.Errorf("Expected pod %v in namespace %v to be terminated with reason %v, got reason: %v", podName, namespace, reason, pod.Status.Reason) + return true, fmt.Errorf("Expected pod %q in namespace %q to be terminated with reason %q, got reason: %q", podName, namespace, reason, pod.Status.Reason) } } - return false, nil }) } From dbb24264aa55779f77e4f08d4b61660092c96505 Mon Sep 17 00:00:00 2001 From: jeff vance Date: Thu, 27 Jul 2017 19:50:51 -0700 Subject: [PATCH 2/2] revert most of the changes, add comments --- test/e2e/framework/util.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 6ae6d20e1c4..079f30bd9db 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -1355,13 +1355,17 @@ func podNotPending(c clientset.Interface, podName, namespace string) wait.Condit } } -// waitForPodTerminatedInNamespace returns an error if it took too long for the pod -// to terminate or if the pod terminated with an unexpected reason. +// waitForPodTerminatedInNamespace returns an error if it takes too long for the pod to terminate, +// if the pod Get api returns an error (IsNotFound or other), or if the pod failed (and thus did not +// terminate) with an unexpected reason. Typically called to test that the passed-in pod is fully +// terminated (reason==""), but may be called to detect if a pod did *not* terminate according to +// the supplied reason. func waitForPodTerminatedInNamespace(c clientset.Interface, podName, reason, namespace string) error { return WaitForPodCondition(c, namespace, podName, "terminated due to deadline exceeded", PodStartTimeout, func(pod *v1.Pod) (bool, error) { - if pod.Status.Phase == v1.PodSucceeded || pod.Status.Phase == v1.PodFailed { - if reason == "" || - strings.ToLower(strings.TrimSpace(pod.Status.Reason)) == strings.ToLower(strings.TrimSpace(reason)) { + // Only consider Failed pods. Successful pods will be deleted and detected in + // waitForPodCondition's Get call returning `IsNotFound` + if pod.Status.Phase == v1.PodFailed { + if pod.Status.Reason == reason { // short-circuit waitForPodCondition's loop return true, nil } else { return true, fmt.Errorf("Expected pod %q in namespace %q to be terminated with reason %q, got reason: %q", podName, namespace, reason, pod.Status.Reason)