Delete provisioned volumes that are not needed.

We should delete volumes that are provisioned for a claim and the claim
gets bound to different volume during the provisioning.
This commit is contained in:
Jan Safranek 2016-05-17 14:55:27 +02:00
parent 9fb0f7a3fd
commit 92dc159ab6

View File

@ -672,25 +672,39 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *api.PersistentVolume)
return nil return nil
} else { } else {
// Volume is bound to a claim, but the claim is bound elsewhere // Volume is bound to a claim, but the claim is bound elsewhere
if hasAnnotation(volume.ObjectMeta, annBoundByController) { if hasAnnotation(volume.ObjectMeta, annDynamicallyProvisioned) && volume.Spec.PersistentVolumeReclaimPolicy == api.PersistentVolumeReclaimDelete {
// This is part of the normal operation of the controller; the // This volume was dynamically provisioned for this claim. The
// controller tried to use this volume for a claim but the claim // claim got bound elsewhere, and thus this volume is not
// was fulfilled by another volume. We did this; fix it. // needed. Delete it.
glog.V(4).Infof("synchronizing PersistentVolume[%s]: volume is bound by controller to a claim that is bound to another volume, unbinding", volume.Name) if err = ctrl.reclaimVolume(volume); err != nil {
if err = ctrl.unbindVolume(volume); err != nil { // Deletion failed, we will fall back into the same condition
// in the next call to this method
return err return err
} }
return nil return nil
} else { } else {
// The PV must have been created with this ptr; leave it alone. // Volume is bound to a claim, but the claim is bound elsewhere
glog.V(4).Infof("synchronizing PersistentVolume[%s]: volume is bound by user to a claim that is bound to another volume, waiting for the claim to get unbound", volume.Name) // and it's not dynamically provisioned.
// This just updates the volume phase and clears if hasAnnotation(volume.ObjectMeta, annBoundByController) {
// volume.Spec.ClaimRef.UID. It leaves the volume pre-bound // This is part of the normal operation of the controller; the
// to the claim. // controller tried to use this volume for a claim but the claim
if err = ctrl.unbindVolume(volume); err != nil { // was fulfilled by another volume. We did this; fix it.
return err glog.V(4).Infof("synchronizing PersistentVolume[%s]: volume is bound by controller to a claim that is bound to another volume, unbinding", volume.Name)
if err = ctrl.unbindVolume(volume); err != nil {
return err
}
return nil
} else {
// The PV must have been created with this ptr; leave it alone.
glog.V(4).Infof("synchronizing PersistentVolume[%s]: volume is bound by user to a claim that is bound to another volume, waiting for the claim to get unbound", volume.Name)
// This just updates the volume phase and clears
// volume.Spec.ClaimRef.UID. It leaves the volume pre-bound
// to the claim.
if err = ctrl.unbindVolume(volume); err != nil {
return err
}
return nil
} }
return nil
} }
} }
} }