Skip to content

Commit 253a85d

Browse files
author
Kenichi Omichi
committed
Move WaitForFailure() to the test
WaitForFailure() is used at a single e2e test. So this moves the function to the specific test file for the cleanup.
1 parent a1364be commit 253a85d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

test/e2e/common/security_context.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package common
1919
import (
2020
"fmt"
2121
"strings"
22+
"time"
2223

2324
v1 "k8s.io/api/core/v1"
2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -191,7 +192,7 @@ var _ = framework.KubeDescribe("Security Context", func() {
191192
))
192193

193194
if readOnlyRootFilesystem {
194-
podClient.WaitForFailure(podName, framework.PodStartTimeout)
195+
waitForFailure(f, podName, framework.PodStartTimeout)
195196
} else {
196197
podClient.WaitForSuccess(podName, framework.PodStartTimeout)
197198
}
@@ -366,3 +367,19 @@ var _ = framework.KubeDescribe("Security Context", func() {
366367
})
367368
})
368369
})
370+
371+
// waitForFailure waits for pod to fail.
372+
func waitForFailure(f *framework.Framework, name string, timeout time.Duration) {
373+
gomega.Expect(e2epod.WaitForPodCondition(f.ClientSet, f.Namespace.Name, name, "success or failure", timeout,
374+
func(pod *v1.Pod) (bool, error) {
375+
switch pod.Status.Phase {
376+
case v1.PodFailed:
377+
return true, nil
378+
case v1.PodSucceeded:
379+
return true, fmt.Errorf("pod %q successed with reason: %q, message: %q", name, pod.Status.Reason, pod.Status.Message)
380+
default:
381+
return false, nil
382+
}
383+
},
384+
)).To(gomega.Succeed(), "wait for pod %q to fail", name)
385+
}

test/e2e/framework/pods.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -208,23 +208,6 @@ func (c *PodClient) WaitForSuccess(name string, timeout time.Duration) {
208208
)).To(gomega.Succeed(), "wait for pod %q to success", name)
209209
}
210210

211-
// WaitForFailure waits for pod to fail.
212-
func (c *PodClient) WaitForFailure(name string, timeout time.Duration) {
213-
f := c.f
214-
gomega.Expect(e2epod.WaitForPodCondition(f.ClientSet, f.Namespace.Name, name, "success or failure", timeout,
215-
func(pod *v1.Pod) (bool, error) {
216-
switch pod.Status.Phase {
217-
case v1.PodFailed:
218-
return true, nil
219-
case v1.PodSucceeded:
220-
return true, fmt.Errorf("pod %q successed with reason: %q, message: %q", name, pod.Status.Reason, pod.Status.Message)
221-
default:
222-
return false, nil
223-
}
224-
},
225-
)).To(gomega.Succeed(), "wait for pod %q to fail", name)
226-
}
227-
228211
// WaitForFinish waits for pod to finish running, regardless of success or failure.
229212
func (c *PodClient) WaitForFinish(name string, timeout time.Duration) {
230213
f := c.f

0 commit comments

Comments
 (0)