Merge pull request #69300 from mrunalp/subpath_test_wait_for_event
test: Wait for pod event to show up
This commit is contained in:
@@ -119,6 +119,9 @@ const (
|
||||
// How long to wait for a pod to be deleted
|
||||
PodDeleteTimeout = 5 * time.Minute
|
||||
|
||||
// PodEventTimeout is how much we wait for a pod event to occur.
|
||||
PodEventTimeout = 2 * time.Minute
|
||||
|
||||
// If there are any orphaned namespaces to clean up, this test is running
|
||||
// on a long lived cluster. A long wait here is preferably to spurious test
|
||||
// failures caused by leaked resources from a previous test run.
|
||||
@@ -1460,6 +1463,29 @@ 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))
|
||||
}
|
||||
|
||||
func eventOccured(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)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Waits default amount of time (DefaultPodDeletionTimeout) for the specified pod to stop running.
|
||||
// Returns an error if timeout occurs first.
|
||||
func WaitForPodNoLongerRunningInNamespace(c clientset.Interface, podName, namespace string) error {
|
||||
|
Reference in New Issue
Block a user