@@ -308,15 +308,37 @@ func (r *VolumeResource) CleanupResource() error {
308
308
r .Pv .Name , v1 .PersistentVolumeReclaimDelete )
309
309
}
310
310
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
+
311
332
err := e2epv .DeletePersistentVolumeClaim (f .ClientSet , r .Pvc .Name , f .Namespace .Name )
312
333
if err != nil {
313
334
cleanUpErrs = append (cleanUpErrs , errors .Wrapf (err , "Failed to delete PVC %v" , r .Pvc .Name ))
314
335
}
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 )
317
339
if err != nil {
318
340
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 ))
320
342
}
321
343
}
322
344
}
0 commit comments