Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks!--What happened: Based on discussion , events can be throttled and should not be used to validate failure conditions in e2e tests. We should remove the event checks from subpath and local pv tests and just wait for pod failure. <!-- DO NOT EDIT BELOW THIS LINE --/kind bug
/assign
could you help look at this for local PV tests?
sure /assign
/area deflake
"Invalid AWS KMS key" also waits for an event

Discussion:
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", <del> "//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library", </del> "//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",

storagev1 "k8s.io/api/storage/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" <del> "k8s.io/apimachinery/pkg/fields" </del> "k8s.io/apimachinery/pkg/runtime/schema" utilerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/sets"

By("Deleting second pod") framework.DeletePodOrFail(config.client, config.ns, pod2.Name) }) <del> It("should not set different fsGroups for two pods simultaneously", func() { fsGroup1, fsGroup2 := int64(1234), int64(4321) By("Create first pod and check fsGroup is set") pod1 := createPodWithFsGroupTest(config, testVol, fsGroup1, fsGroup1) By("Create second pod and check fsGroup is still the old one") pod2 := createPodWithFsGroupTest(config, testVol, fsGroup2, fsGroup1) ep := &eventPatterns{ reason:  "AlreadyMountedVolume", pattern: make([]string, 2), } ep.pattern = append(ep.pattern, fmt.Sprintf("The requested fsGroup is %d", fsGroup2)) ep.pattern = append(ep.pattern, "The volume may not be shareable.") checkPodEvents(config, pod2.Name, ep) By("Deleting first pod") framework.DeletePodOrFail(config.client, config.ns, pod1.Name) By("Deleting second pod") framework.DeletePodOrFail(config.client, config.ns, pod2.Name) }) </del> }) })

// TODO: // - check for these errors in unit tests instead It("should fail due to non-existent path", func() { <del> ep := &eventPatterns{ reason:  "FailedMount", pattern: make([]string, 2)} ep.pattern = append(ep.pattern, "MountVolume.NewMounter initialization failed") </del> testVol := &localTestVolume{ node:            config.node0, hostDir:         "/non-existent/location/nowhere",

createLocalPVCsPVs(config, []*localTestVolume{testVol}, immediateMode) pod, err := createLocalPod(config, testVol, nil) Expect(err).To(HaveOccurred()) <del> checkPodEvents(config, pod.Name, ep) </del> <ins> err = framework.WaitTimeoutForPodRunningInNamespace(config.client, pod.Name, pod.Namespace, framework.PodStartShortTimeout) Expect(err).To(HaveOccurred()) </ins> cleanupLocalPVCsPVs(config, []*localTestVolume{testVol}) })

framework.Skipf("Runs only when number of nodes >= 2") } <del> ep := &eventPatterns{ reason:  "FailedMount", pattern: make([]string, 2)} ep.pattern = append(ep.pattern, "NodeSelectorTerm") ep.pattern = append(ep.pattern, "MountVolume.NodeAffinity check failed") </del> testVols := setupLocalVolumesPVCsPVs(config, DirectoryLocalVolumeType, config.node0, 1, immediateMode) testVol := testVols[0]

err = framework.WaitTimeoutForPodRunningInNamespace(config.client, pod.Name, pod.Namespace, framework.PodStartShortTimeout) Expect(err).To(HaveOccurred()) <del> checkPodEvents(config, pod.Name, ep) </del> cleanupLocalVolumes(config, []*localTestVolume{testVol}) })

Expect(err).NotTo(HaveOccurred()) } <del> type eventPatterns struct { reason  string pattern []string } func checkPodEvents(config *localTestConfig, podName string, ep *eventPatterns) { var events *v1.EventList selector := fields.Set{ "involvedObject.kind":      "Pod", "involvedObject.name":      podName, "involvedObject.namespace": config.ns, "reason":                   ep.reason, }.AsSelector().String() options := metav1.ListOptions{FieldSelector: selector} events, err := config.client.CoreV1().Events(config.ns).List(options) Expect(err).NotTo(HaveOccurred()) Expect(len(events.Items)).NotTo(Equal(0)) for _, p := range ep.pattern { Expect(events.Items[0].Message).To(ContainSubstring(p)) } } </del> // The tests below are run against multiple mount point types // Test two pods at the same time, write from pod1, and read from pod2