From 040adc9cb6b4985cd3af77a538a941c594aa4f6b Mon Sep 17 00:00:00 2001 From: riya-singhal31 Date: Thu, 17 Aug 2023 14:32:36 +0530 Subject: [PATCH] e2e: add timeout for pvc deletion in ephemeral e2e this commit adds the timeout to wait for pvc deletion after the deletion of pod in test. Signed-off-by: riya-singhal31 --- e2e/cephfs.go | 7 +++++++ e2e/pvc.go | 32 ++++++++++++++++++++++++++++++++ e2e/rbd.go | 7 +++++++ 3 files changed, 46 insertions(+) diff --git a/e2e/cephfs.go b/e2e/cephfs.go index 474a6d335e9..6753019feee 100644 --- a/e2e/cephfs.go +++ b/e2e/cephfs.go @@ -399,6 +399,13 @@ var _ = Describe(cephfsType, func() { if err != nil { framework.Failf("failed to delete application: %v", err) } + + // wait for the associated PVC to be deleted + err = waitForPVCToBeDeleted(f.ClientSet, app.Namespace, "mypvc", deployTimeout) + if err != nil { + framework.Failf("failed to wait for PVC deletion: %v", err) + } + validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup) validateOmapCount(f, 0, cephfsType, metadataPool, volumesType) err = deleteResource(cephFSExamplePath + "storageclass.yaml") diff --git a/e2e/pvc.go b/e2e/pvc.go index fe4fb9cda32..a067331a736 100644 --- a/e2e/pvc.go +++ b/e2e/pvc.go @@ -430,3 +430,35 @@ func getMetricsForPVC(f *framework.Framework, pvc *v1.PersistentVolumeClaim, t i return false, nil }) } + +func waitForPVCToBeDeleted(c kubernetes.Interface, namespace, pvcName string, t int) error { + timeout := time.Duration(t) * time.Minute + ctx := context.TODO() + start := time.Now() + + return wait.PollUntilContextTimeout(ctx, poll, timeout, true, func(ctx context.Context) (bool, error) { + pvc, err := c.CoreV1().PersistentVolumeClaims(namespace).Get(ctx, pvcName, metav1.GetOptions{}) + // Check that the PVC is really deleted. + framework.Logf( + "waiting for PVC %s in state %s to be deleted (%d seconds elapsed)", + pvcName, + pvc.Status.String(), + int(time.Since(start).Seconds())) + if err == nil { + framework.Logf("PVC %s (status: %s) has not been deleted yet, rechecking...", pvcName, pvc.Status) + + return false, nil + } + if isRetryableAPIError(err) { + framework.Logf("failed to verify deletion of PVC %s (status: %s): %v", pvcName, pvc.Status, err) + + return false, nil + } + if !apierrs.IsNotFound(err) { + return false, fmt.Errorf("get on deleted PVC %v failed with error other than \"not found\": %w", pvcName, err) + } + + // PVC has been successfully deleted + return true, nil + }) +} diff --git a/e2e/rbd.go b/e2e/rbd.go index 57d0c1b7996..b3abc526da8 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -817,6 +817,13 @@ var _ = Describe("RBD", func() { if err != nil { framework.Failf("failed to delete application: %v", err) } + + // wait for the associated PVC to be deleted + err = waitForPVCToBeDeleted(f.ClientSet, app.Namespace, "mypvc", deployTimeout) + if err != nil { + framework.Failf("failed to wait for PVC deletion: %v", err) + } + // validate created backend rbd images validateRBDImageCount(f, 0, defaultRBDPool) validateOmapCount(f, 0, rbdType, defaultRBDPool, volumesType)