mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 05:21:58 +00:00
Fix WaitTimeoutForPodEvent logic
This commit is contained in:
parent
a4aab0e1e7
commit
5214be3f16
@ -1465,10 +1465,10 @@ func podRunning(c clientset.Interface, podName, namespace string) wait.Condition
|
|||||||
|
|
||||||
// WaitTimeoutForPodEvent waits for an event to occur for a pod
|
// WaitTimeoutForPodEvent waits for an event to occur for a pod
|
||||||
func WaitTimeoutForPodEvent(c clientset.Interface, podName, namespace, eventSelector, msg string, timeout time.Duration) error {
|
func WaitTimeoutForPodEvent(c clientset.Interface, podName, namespace, eventSelector, msg string, timeout time.Duration) error {
|
||||||
return wait.PollImmediate(Poll, timeout, eventOccured(c, podName, namespace, eventSelector, msg))
|
return wait.PollImmediate(Poll, timeout, eventOccurred(c, podName, namespace, eventSelector, msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func eventOccured(c clientset.Interface, podName, namespace, eventSelector, msg string) wait.ConditionFunc {
|
func eventOccurred(c clientset.Interface, podName, namespace, eventSelector, msg string) wait.ConditionFunc {
|
||||||
options := metav1.ListOptions{FieldSelector: eventSelector}
|
options := metav1.ListOptions{FieldSelector: eventSelector}
|
||||||
return func() (bool, error) {
|
return func() (bool, error) {
|
||||||
events, err := c.CoreV1().Events(namespace).List(options)
|
events, err := c.CoreV1().Events(namespace).List(options)
|
||||||
@ -1476,13 +1476,9 @@ func eventOccured(c clientset.Interface, podName, namespace, eventSelector, msg
|
|||||||
return false, fmt.Errorf("got error while getting pod events: %s", err)
|
return false, fmt.Errorf("got error while getting pod events: %s", err)
|
||||||
}
|
}
|
||||||
if len(events.Items) == 0 {
|
if len(events.Items) == 0 {
|
||||||
return false, fmt.Errorf("no events found")
|
return false, nil // no events have occurred yet
|
||||||
}
|
|
||||||
if strings.Contains(events.Items[0].Message, msg) {
|
|
||||||
return false, fmt.Errorf("%q error not found", msg)
|
|
||||||
} else {
|
|
||||||
return true, nil
|
|
||||||
}
|
}
|
||||||
|
return strings.Contains(events.Items[0].Message, msg), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,7 +597,7 @@ func testPodFailSubpathError(f *framework.Framework, pod *v1.Pod, errorMsg strin
|
|||||||
"reason": "Failed",
|
"reason": "Failed",
|
||||||
}.AsSelector().String()
|
}.AsSelector().String()
|
||||||
err = framework.WaitTimeoutForPodEvent(f.ClientSet, pod.Name, f.Namespace.Name, selector, errorMsg, framework.PodEventTimeout)
|
err = framework.WaitTimeoutForPodEvent(f.ClientSet, pod.Name, f.Namespace.Name, selector, errorMsg, framework.PodEventTimeout)
|
||||||
Expect(err).To(HaveOccurred(), "while waiting for failed event to occur")
|
Expect(err).NotTo(HaveOccurred(), "while waiting for failed event to occur")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the existing subpath mount is detected when a container restarts
|
// Tests that the existing subpath mount is detected when a container restarts
|
||||||
|
Loading…
Reference in New Issue
Block a user