diff --git a/test/e2e/common/security_context.go b/test/e2e/common/security_context.go index 88bf9e77e38..f08fcba2cc8 100644 --- a/test/e2e/common/security_context.go +++ b/test/e2e/common/security_context.go @@ -19,6 +19,7 @@ package common import ( "fmt" "strings" + "time" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -191,7 +192,7 @@ var _ = framework.KubeDescribe("Security Context", func() { )) if readOnlyRootFilesystem { - podClient.WaitForFailure(podName, framework.PodStartTimeout) + waitForFailure(f, podName, framework.PodStartTimeout) } else { podClient.WaitForSuccess(podName, framework.PodStartTimeout) } @@ -366,3 +367,19 @@ var _ = framework.KubeDescribe("Security Context", func() { }) }) }) + +// waitForFailure waits for pod to fail. +func waitForFailure(f *framework.Framework, name string, timeout time.Duration) { + gomega.Expect(e2epod.WaitForPodCondition(f.ClientSet, f.Namespace.Name, name, "success or failure", timeout, + func(pod *v1.Pod) (bool, error) { + switch pod.Status.Phase { + case v1.PodFailed: + return true, nil + case v1.PodSucceeded: + return true, fmt.Errorf("pod %q successed with reason: %q, message: %q", name, pod.Status.Reason, pod.Status.Message) + default: + return false, nil + } + }, + )).To(gomega.Succeed(), "wait for pod %q to fail", name) +} diff --git a/test/e2e/framework/pods.go b/test/e2e/framework/pods.go index b3d6887d750..0bd6e37c334 100644 --- a/test/e2e/framework/pods.go +++ b/test/e2e/framework/pods.go @@ -199,23 +199,6 @@ func (c *PodClient) WaitForSuccess(name string, timeout time.Duration) { )).To(gomega.Succeed(), "wait for pod %q to success", name) } -// WaitForFailure waits for pod to fail. -func (c *PodClient) WaitForFailure(name string, timeout time.Duration) { - f := c.f - gomega.Expect(e2epod.WaitForPodCondition(f.ClientSet, f.Namespace.Name, name, "success or failure", timeout, - func(pod *v1.Pod) (bool, error) { - switch pod.Status.Phase { - case v1.PodFailed: - return true, nil - case v1.PodSucceeded: - return true, fmt.Errorf("pod %q successed with reason: %q, message: %q", name, pod.Status.Reason, pod.Status.Message) - default: - return false, nil - } - }, - )).To(gomega.Succeed(), "wait for pod %q to fail", name) -} - // WaitForFinish waits for pod to finish running, regardless of success or failure. func (c *PodClient) WaitForFinish(name string, timeout time.Duration) { f := c.f