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 <rsinghal@redhat.com>
This commit is contained in:
riya-singhal31
2023-08-17 14:32:36 +05:30
committed by mergify[bot]
parent 16e5de5e1d
commit d435b59656
3 changed files with 48 additions and 0 deletions

View File

@ -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
})
}