From 8d644092ed8deda63e0c18aa0948864ab52ea7cc Mon Sep 17 00:00:00 2001 From: Fabio Bertinatto Date: Tue, 9 Jun 2020 13:13:30 +0200 Subject: [PATCH] Create pod to force volume provisioning in storage e2e test Otherwise, tests can fail if the default StorageClass is configured with late binding. --- test/e2e/storage/testsuites/provisioning.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/e2e/storage/testsuites/provisioning.go b/test/e2e/storage/testsuites/provisioning.go index c8acf822f77..9e1223c8bc7 100644 --- a/test/e2e/storage/testsuites/provisioning.go +++ b/test/e2e/storage/testsuites/provisioning.go @@ -350,6 +350,23 @@ func (t StorageClassTest) TestDynamicProvisioning() *v1.PersistentVolume { } }() + if class == nil { + // StorageClass is nil, so the default one will be used + scName, err := e2epv.GetDefaultStorageClassName(client) + framework.ExpectNoError(err) + defaultSC, err := client.StorageV1().StorageClasses().Get(context.TODO(), scName, metav1.GetOptions{}) + framework.ExpectNoError(err) + // If late binding is configured, create and delete a pod to provision the volume + if *defaultSC.VolumeBindingMode == storagev1.VolumeBindingWaitForFirstConsumer { + ginkgo.By("creating a pod referring to the claim") + var pod *v1.Pod + pod, err := e2epod.CreatePod(t.Client, claim.Namespace, nil /* nodeSelector */, []*v1.PersistentVolumeClaim{claim}, true /* isPrivileged */, "" /* command */) + // Delete pod now, otherwise PV can't be deleted below + framework.ExpectNoError(err) + e2epod.DeletePodOrFail(t.Client, pod.Namespace, pod.Name) + } + } + // Run the checker if t.PvCheck != nil { t.PvCheck(claim)