Skip to content

Commit 601b793

Browse files
authored
Merge pull request kubernetes#79971 from mrkm4ntr/fix-pv-existence-check
Add check to reduce orphaned volume
2 parents 29669a5 + 7c0b33e commit 601b793

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pkg/controller/volume/persistentvolume/pv_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,10 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(
14151415

14161416
pvName := ctrl.getProvisionedVolumeNameForClaim(claim)
14171417
volume, err := ctrl.kubeClient.CoreV1().PersistentVolumes().Get(pvName, metav1.GetOptions{})
1418+
if err != nil && !apierrs.IsNotFound(err) {
1419+
klog.V(3).Infof("error reading persistent volume %q: %v", pvName, err)
1420+
return pluginName, err
1421+
}
14181422
if err == nil && volume != nil {
14191423
// Volume has been already provisioned, nothing to do.
14201424
klog.V(4).Infof("provisionClaimOperation [%s]: volume already exists, skipping", claimToClaimKey(claim))

pkg/controller/volume/persistentvolume/testing/testing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
223223
return true, volume.DeepCopy(), nil
224224
}
225225
klog.V(4).Infof("GetVolume: volume %s not found", name)
226-
return true, nil, fmt.Errorf("Cannot find volume %s", name)
226+
return true, nil, apierrs.NewNotFound(action.GetResource().GroupResource(), name)
227227

228228
case action.Matches("get", "persistentvolumeclaims"):
229229
name := action.(core.GetAction).GetName()

0 commit comments

Comments
 (0)