Skip to content

Commit 40b1867

Browse files
committed
Use events to speed up the test
1 parent 683b978 commit 40b1867

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

test/e2e/storage/testsuites/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ go_library(
2020
importpath = "k8s.io/kubernetes/test/e2e/storage/testsuites",
2121
visibility = ["//visibility:public"],
2222
deps = [
23+
"//pkg/kubelet/events:go_default_library",
2324
"//staging/src/k8s.io/api/core/v1:go_default_library",
2425
"//staging/src/k8s.io/api/storage/v1:go_default_library",
2526
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
2627
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
2728
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
2829
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
30+
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
2931
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
3032
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
3133
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",

test/e2e/storage/testsuites/volumemode.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import (
2424
v1 "k8s.io/api/core/v1"
2525
storagev1 "k8s.io/api/storage/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/apimachinery/pkg/fields"
2728
clientset "k8s.io/client-go/kubernetes"
29+
"k8s.io/kubernetes/pkg/kubelet/events"
2830
"k8s.io/kubernetes/test/e2e/framework"
2931
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
3032
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
@@ -236,7 +238,7 @@ func (t *volumeModeTestSuite) defineTests(driver TestDriver, pattern testpattern
236238

237239
ginkgo.By("Creating pod")
238240
var err error
239-
pod := framework.MakeSecPod(l.ns.Name, []*v1.PersistentVolumeClaim{l.pvc}, false, "", false, false, framework.SELinuxLabel, nil)
241+
pod := framework.MakeSecPod(l.ns.Name, []*v1.PersistentVolumeClaim{l.pvc}, nil, false, "", false, false, framework.SELinuxLabel, nil)
240242
// Change volumeMounts to volumeDevices and the other way around
241243
pod = swapVolumeMode(pod)
242244

@@ -247,10 +249,31 @@ func (t *volumeModeTestSuite) defineTests(driver TestDriver, pattern testpattern
247249
framework.ExpectNoError(framework.DeletePodWithWait(f, l.cs, pod))
248250
}()
249251

250-
// TODO: find a faster way how to check the pod can't start,
251-
// perhaps when https://github.com/kubernetes/kubernetes/issues/79794 is fixed.
252-
err = e2epod.WaitTimeoutForPodRunningInNamespace(l.cs, pod.Name, l.ns.Name, framework.PodStartTimeout)
253-
framework.ExpectError(err, "pod with mismatched block/filesystem volumes should not start")
252+
ginkgo.By("Waiting for pod to fail")
253+
// Wait for an event that the pod is invalid.
254+
eventSelector := fields.Set{
255+
"involvedObject.kind": "Pod",
256+
"involvedObject.name": pod.Name,
257+
"involvedObject.namespace": l.ns.Name,
258+
"reason": events.FailedMountVolume,
259+
}.AsSelector().String()
260+
261+
var msg string
262+
if pattern.VolMode == v1.PersistentVolumeBlock {
263+
msg = "has volumeMode Block, but is specified in volumeMounts"
264+
} else {
265+
msg = "has volumeMode Filesystem, but is specified in volumeDevices"
266+
}
267+
err = e2epod.WaitTimeoutForPodEvent(l.cs, pod.Name, l.ns.Name, eventSelector, msg, framework.PodStartTimeout)
268+
// Events are unreliable, don't depend on them. They're used only to speed up the test.
269+
if err != nil {
270+
e2elog.Logf("Warning: did not get event about mismatched volume use")
271+
}
272+
273+
// Check the pod is still not running
274+
p, err := l.cs.CoreV1().Pods(l.ns.Name).Get(pod.Name, metav1.GetOptions{})
275+
framework.ExpectNoError(err, "could not re-read the pod after event (or timeout)")
276+
framework.ExpectEqual(p.Status.Phase, v1.PodPending)
254277
})
255278

256279
}

0 commit comments

Comments
 (0)