mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 13:02:14 +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
|
||||
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}
|
||||
return func() (bool, error) {
|
||||
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)
|
||||
}
|
||||
if len(events.Items) == 0 {
|
||||
return false, fmt.Errorf("no events found")
|
||||
}
|
||||
if strings.Contains(events.Items[0].Message, msg) {
|
||||
return false, fmt.Errorf("%q error not found", msg)
|
||||
} else {
|
||||
return true, nil
|
||||
return false, nil // no events have occurred yet
|
||||
}
|
||||
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",
|
||||
}.AsSelector().String()
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user