mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 00:07:50 +00:00
Merge pull request #86732 from oomichi/move-WaitForFailure
Move WaitForFailure() to the test
This commit is contained in:
commit
63411a137f
@ -19,6 +19,7 @@ package common
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@ -191,7 +192,7 @@ var _ = framework.KubeDescribe("Security Context", func() {
|
|||||||
))
|
))
|
||||||
|
|
||||||
if readOnlyRootFilesystem {
|
if readOnlyRootFilesystem {
|
||||||
podClient.WaitForFailure(podName, framework.PodStartTimeout)
|
waitForFailure(f, podName, framework.PodStartTimeout)
|
||||||
} else {
|
} else {
|
||||||
podClient.WaitForSuccess(podName, framework.PodStartTimeout)
|
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)
|
||||||
|
}
|
||||||
|
@ -199,23 +199,6 @@ func (c *PodClient) WaitForSuccess(name string, timeout time.Duration) {
|
|||||||
)).To(gomega.Succeed(), "wait for pod %q to success", name)
|
)).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.
|
// WaitForFinish waits for pod to finish running, regardless of success or failure.
|
||||||
func (c *PodClient) WaitForFinish(name string, timeout time.Duration) {
|
func (c *PodClient) WaitForFinish(name string, timeout time.Duration) {
|
||||||
f := c.f
|
f := c.f
|
||||||
|
Loading…
Reference in New Issue
Block a user