Skip to content

Commit e3d258d

Browse files
committed
e2e storage: wait for PV deletion also for late binding
When a test pattern or storage class uses late binding, the cleanup code didn't know about the PV that may have been created for the PVC since setting it up and thus then also didn't wait for PV deletion. This is problematic for test isolation because the next test was allowed to be started before fully cleaning up. Worse, it the driver gets removed after the test, the volume might never get deleted.
1 parent 72cdc8c commit e3d258d

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

test/e2e/storage/testsuites/base.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,37 @@ func (r *VolumeResource) CleanupResource() error {
308308
r.Pv.Name, v1.PersistentVolumeReclaimDelete)
309309
}
310310
if r.Pvc != nil {
311+
cs := f.ClientSet
312+
pv := r.Pv
313+
if pv == nil && r.Pvc.Name != "" {
314+
// This happens for late binding. Check whether we have a volume now that we need to wait for.
315+
pvc, err := cs.CoreV1().PersistentVolumeClaims(r.Pvc.Namespace).Get(context.TODO(), r.Pvc.Name, metav1.GetOptions{})
316+
switch {
317+
case err == nil:
318+
if pvc.Spec.VolumeName != "" {
319+
pv, err = cs.CoreV1().PersistentVolumes().Get(context.TODO(), pvc.Spec.VolumeName, metav1.GetOptions{})
320+
if err != nil {
321+
cleanUpErrs = append(cleanUpErrs, errors.Wrapf(err, "Failed to find PV %v", pvc.Spec.VolumeName))
322+
}
323+
}
324+
case apierrors.IsNotFound(err):
325+
// Without the PVC, we cannot locate the corresponding PV. Let's
326+
// hope that it is gone.
327+
default:
328+
cleanUpErrs = append(cleanUpErrs, errors.Wrapf(err, "Failed to find PVC %v", r.Pvc.Name))
329+
}
330+
}
331+
311332
err := e2epv.DeletePersistentVolumeClaim(f.ClientSet, r.Pvc.Name, f.Namespace.Name)
312333
if err != nil {
313334
cleanUpErrs = append(cleanUpErrs, errors.Wrapf(err, "Failed to delete PVC %v", r.Pvc.Name))
314335
}
315-
if r.Pv != nil {
316-
err = e2epv.WaitForPersistentVolumeDeleted(f.ClientSet, r.Pv.Name, 5*time.Second, 5*time.Minute)
336+
337+
if pv != nil {
338+
err = e2epv.WaitForPersistentVolumeDeleted(f.ClientSet, pv.Name, 5*time.Second, 5*time.Minute)
317339
if err != nil {
318340
cleanUpErrs = append(cleanUpErrs, errors.Wrapf(err,
319-
"Persistent Volume %v not deleted by dynamic provisioner", r.Pv.Name))
341+
"Persistent Volume %v not deleted by dynamic provisioner", pv.Name))
320342
}
321343
}
322344
}

0 commit comments

Comments
 (0)