diff --git a/test/e2e/common/node/runtimeclass.go b/test/e2e/common/node/runtimeclass.go index c782c3a097b..11ae778250f 100644 --- a/test/e2e/common/node/runtimeclass.go +++ b/test/e2e/common/node/runtimeclass.go @@ -51,7 +51,21 @@ var _ = SIGDescribe("RuntimeClass", func() { handler := f.Namespace.Name + "-handler" rcName := createRuntimeClass(f, "unconfigured-handler", handler) pod := f.PodClient().Create(e2enode.NewRuntimeClassPod(rcName)) - expectSandboxFailureEvent(f, pod, handler) + eventSelector := fields.Set{ + "involvedObject.kind": "Pod", + "involvedObject.name": pod.Name, + "involvedObject.namespace": f.Namespace.Name, + "reason": events.FailedCreatePodSandBox, + }.AsSelector().String() + // Events are unreliable, don't depend on the event. It's used only to speed up the test. + err := e2eevents.WaitTimeoutForEvent(f.ClientSet, f.Namespace.Name, eventSelector, handler, framework.PodEventTimeout) + if err != nil { + framework.Logf("Warning: did not get event about FailedCreatePodSandBox. Err: %v", err) + } + // Check the pod is still not running + p, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(context.TODO(), pod.Name, metav1.GetOptions{}) + framework.ExpectNoError(err, "could not re-read the pod after event (or timeout)") + framework.ExpectEqual(p.Status.Phase, v1.PodPending, "Pod phase isn't pending") }) // This test requires that the PreconfiguredRuntimeHandler has already been set up on nodes. @@ -273,16 +287,3 @@ func expectPodSuccess(f *framework.Framework, pod *v1.Pod) { framework.ExpectNoError(e2epod.WaitForPodSuccessInNamespace( f.ClientSet, pod.Name, f.Namespace.Name)) } - -// expectSandboxFailureEvent polls for an event with reason "FailedCreatePodSandBox" containing the -// expected message string. -func expectSandboxFailureEvent(f *framework.Framework, pod *v1.Pod, msg string) { - eventSelector := fields.Set{ - "involvedObject.kind": "Pod", - "involvedObject.name": pod.Name, - "involvedObject.namespace": f.Namespace.Name, - "reason": events.FailedCreatePodSandBox, - }.AsSelector().String() - framework.ExpectNoError(e2eevents.WaitTimeoutForEvent( - f.ClientSet, f.Namespace.Name, eventSelector, msg, framework.PodEventTimeout)) -} diff --git a/test/e2e/framework/events/events.go b/test/e2e/framework/events/events.go index d6d23de6e4e..39d70209957 100644 --- a/test/e2e/framework/events/events.go +++ b/test/e2e/framework/events/events.go @@ -31,6 +31,7 @@ import ( type Action func() error // WaitTimeoutForEvent waits the given timeout duration for an event to occur. +// Please note delivery of events is not guaranteed. Asserting on events can lead to flaky tests. func WaitTimeoutForEvent(c clientset.Interface, namespace, eventSelector, msg string, timeout time.Duration) error { interval := 2 * time.Second return wait.PollImmediate(interval, timeout, eventOccurred(c, namespace, eventSelector, msg))