mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Remove some uses of watch.Until in e2e tests
This commit is contained in:
parent
3ce49346a7
commit
4cef1008f4
@ -1230,13 +1230,24 @@ func waitForPodRunningInNamespaceSlow(c clientset.Interface, podName, namespace,
|
|||||||
return waitTimeoutForPodRunningInNamespace(c, podName, namespace, resourceVersion, slowPodStartTimeout)
|
return waitTimeoutForPodRunningInNamespace(c, podName, namespace, resourceVersion, slowPodStartTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitTimeoutForPodRunningInNamespace(c clientset.Interface, podName, namespace, resourceVersion string, timeout time.Duration) error {
|
func waitTimeoutForPodRunningInNamespace(c clientset.Interface, podName, namespace, resouceVersion string, timeout time.Duration) error {
|
||||||
w, err := c.Core().Pods(namespace).Watch(metav1.SingleObject(metav1.ObjectMeta{Name: podName, ResourceVersion: resourceVersion}))
|
return wait.PollImmediate(10*time.Millisecond, timeout, podRunning(c, podName, namespace))
|
||||||
if err != nil {
|
}
|
||||||
return err
|
|
||||||
|
func podRunning(c clientset.Interface, podName, namespace string) wait.ConditionFunc {
|
||||||
|
return func() (bool, error) {
|
||||||
|
pod, err := c.Core().Pods(namespace).Get(podName, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
switch pod.Status.Phase {
|
||||||
|
case v1.PodRunning:
|
||||||
|
return true, nil
|
||||||
|
case v1.PodFailed, v1.PodSucceeded:
|
||||||
|
return false, conditions.ErrPodCompleted
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
_, err = watch.Until(timeout, w, conditions.PodRunning)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Waits default amount of time (podNoLongerRunningTimeout) for the specified pod to stop running.
|
// Waits default amount of time (podNoLongerRunningTimeout) for the specified pod to stop running.
|
||||||
@ -1246,33 +1257,63 @@ func WaitForPodNoLongerRunningInNamespace(c clientset.Interface, podName, namesp
|
|||||||
}
|
}
|
||||||
|
|
||||||
func WaitTimeoutForPodNoLongerRunningInNamespace(c clientset.Interface, podName, namespace, resourceVersion string, timeout time.Duration) error {
|
func WaitTimeoutForPodNoLongerRunningInNamespace(c clientset.Interface, podName, namespace, resourceVersion string, timeout time.Duration) error {
|
||||||
w, err := c.Core().Pods(namespace).Watch(metav1.SingleObject(metav1.ObjectMeta{Name: podName, ResourceVersion: resourceVersion}))
|
return wait.PollImmediate(10*time.Millisecond, timeout, podCompleted(c, podName, namespace))
|
||||||
if err != nil {
|
}
|
||||||
return err
|
|
||||||
|
func podCompleted(c clientset.Interface, podName, namespace string) wait.ConditionFunc {
|
||||||
|
return func() (bool, error) {
|
||||||
|
pod, err := c.Core().Pods(namespace).Get(podName, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
switch pod.Status.Phase {
|
||||||
|
case v1.PodFailed, v1.PodSucceeded:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
_, err = watch.Until(timeout, w, conditions.PodCompleted)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitTimeoutForPodReadyInNamespace(c clientset.Interface, podName, namespace, resourceVersion string, timeout time.Duration) error {
|
func waitTimeoutForPodReadyInNamespace(c clientset.Interface, podName, namespace, resourceVersion string, timeout time.Duration) error {
|
||||||
w, err := c.Core().Pods(namespace).Watch(metav1.SingleObject(metav1.ObjectMeta{Name: podName, ResourceVersion: resourceVersion}))
|
return wait.PollImmediate(10*time.Millisecond, timeout, podRunningAndReady(c, podName, namespace))
|
||||||
if err != nil {
|
}
|
||||||
return err
|
|
||||||
|
func podRunningAndReady(c clientset.Interface, podName, namespace string) wait.ConditionFunc {
|
||||||
|
return func() (bool, error) {
|
||||||
|
pod, err := c.Core().Pods(namespace).Get(podName, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
switch pod.Status.Phase {
|
||||||
|
case v1.PodFailed, v1.PodSucceeded:
|
||||||
|
return false, conditions.ErrPodCompleted
|
||||||
|
case v1.PodRunning:
|
||||||
|
return v1.IsPodReady(pod), nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
_, err = watch.Until(timeout, w, conditions.PodRunningAndReady)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForPodNotPending returns an error if it took too long for the pod to go out of pending state.
|
// WaitForPodNotPending returns an error if it took too long for the pod to go out of pending state.
|
||||||
// The resourceVersion is used when Watching object changes, it tells since when we care
|
// The resourceVersion is used when Watching object changes, it tells since when we care
|
||||||
// about changes to the pod.
|
// about changes to the pod.
|
||||||
func WaitForPodNotPending(c clientset.Interface, ns, podName, resourceVersion string) error {
|
func WaitForPodNotPending(c clientset.Interface, ns, podName, resourceVersion string) error {
|
||||||
w, err := c.Core().Pods(ns).Watch(metav1.SingleObject(metav1.ObjectMeta{Name: podName, ResourceVersion: resourceVersion}))
|
return wait.PollImmediate(10*time.Millisecond, PodStartTimeout, podNotPending(c, podName, ns))
|
||||||
if err != nil {
|
}
|
||||||
return err
|
|
||||||
|
func podNotPending(c clientset.Interface, podName, namespace string) wait.ConditionFunc {
|
||||||
|
return func() (bool, error) {
|
||||||
|
pod, err := c.Core().Pods(namespace).Get(podName, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
switch pod.Status.Phase {
|
||||||
|
case v1.PodPending:
|
||||||
|
return false, nil
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_, err = watch.Until(PodStartTimeout, w, conditions.PodNotPending)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitForPodTerminatedInNamespace returns an error if it took too long for the pod
|
// waitForPodTerminatedInNamespace returns an error if it took too long for the pod
|
||||||
|
Loading…
Reference in New Issue
Block a user