Skip to content

Commit

Permalink
e2e: add timeout for pvc deletion in ephemeral e2e
Browse files Browse the repository at this point in the history
this commit adds the timeout to wait for pvc
deletion after the deletion of pod in a test.

Signed-off-by: riya-singhal31 <[email protected]>
  • Loading branch information
riya-singhal31 committed Aug 17, 2023
1 parent 47b79c8 commit d22df3e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions e2e/rbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

. "github.com/onsi/ginkgo/v2" //nolint:golint // e2e uses By() and other Ginkgo functions
v1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -255,6 +256,38 @@ func ByFileAndBlockEncryption(
})
}

func waitForPVCToBeDeleted(c clientset.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
})
}

var _ = Describe("RBD", func() {
f := framework.NewDefaultFramework(rbdType)
f.NamespacePodSecurityEnforceLevel = api.LevelPrivileged
Expand Down Expand Up @@ -813,10 +846,22 @@ var _ = Describe("RBD", func() {
// validate created backend rbd images
validateRBDImageCount(f, 1, defaultRBDPool)
validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType)

// get the PVC name associated with the pod
pvcName := app.Spec.Volumes[0].Ephemeral.VolumeClaimTemplate.ObjectMeta.Name

// delete the pod
err = deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
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, pvcName, 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)
Expand Down

0 comments on commit d22df3e

Please sign in to comment.