Add check to reduce orphaned volume

This commit is contained in:
Shintaro Murakami 2019-07-10 17:00:01 +09:00
parent bd628bc792
commit 7c0b33e012
2 changed files with 5 additions and 1 deletions

View File

@ -1415,6 +1415,10 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(
pvName := ctrl.getProvisionedVolumeNameForClaim(claim)
volume, err := ctrl.kubeClient.CoreV1().PersistentVolumes().Get(pvName, metav1.GetOptions{})
if err != nil && !apierrs.IsNotFound(err) {
klog.V(3).Infof("error reading persistent volume %q: %v", pvName, err)
return pluginName, err
}
if err == nil && volume != nil {
// Volume has been already provisioned, nothing to do.
klog.V(4).Infof("provisionClaimOperation [%s]: volume already exists, skipping", claimToClaimKey(claim))

View File

@ -223,7 +223,7 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
return true, volume.DeepCopy(), nil
}
klog.V(4).Infof("GetVolume: volume %s not found", name)
return true, nil, fmt.Errorf("Cannot find volume %s", name)
return true, nil, apierrs.NewNotFound(action.GetResource().GroupResource(), name)
case action.Matches("get", "persistentvolumeclaims"):
name := action.(core.GetAction).GetName()