mirror of https://github.com/k3s-io/k3s
Merge pull request #69300 from mrunalp/subpath_test_wait_for_event
test: Wait for pod event to show uppull/58/head
commit
a27adf1612
|
@ -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 {
|
||||
|
|
|
@ -596,11 +596,8 @@ func testPodFailSubpathError(f *framework.Framework, pod *v1.Pod, errorMsg strin
|
|||
"involvedObject.namespace": f.Namespace.Name,
|
||||
"reason": "Failed",
|
||||
}.AsSelector().String()
|
||||
options := metav1.ListOptions{FieldSelector: selector}
|
||||
events, err := f.ClientSet.CoreV1().Events(f.Namespace.Name).List(options)
|
||||
Expect(err).NotTo(HaveOccurred(), "while getting pod events")
|
||||
Expect(len(events.Items)).NotTo(Equal(0), "no events found")
|
||||
Expect(events.Items[0].Message).To(ContainSubstring(errorMsg), fmt.Sprintf("%q error not found", errorMsg))
|
||||
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")
|
||||
}
|
||||
|
||||
// Tests that the existing subpath mount is detected when a container restarts
|
||||
|
|
Loading…
Reference in New Issue