Skip to content

Commit fbacb6e

Browse files
authored
Merge pull request kubernetes#90335 from pohly/cleanup-late-binding
e2e storage: wait for PV deletion also for late binding
2 parents e8d6d37 + e3d258d commit fbacb6e

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)