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,6 +672,19 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *api.PersistentVolume)
return nil
} else {
// Volume is bound to a claim, but the claim is bound elsewhere
if hasAnnotation(volume.ObjectMeta, annDynamicallyProvisioned) && volume.Spec.PersistentVolumeReclaimPolicy == api.PersistentVolumeReclaimDelete {
// This volume was dynamically provisioned for this claim. The
// claim got bound elsewhere, and thus this volume is not
// needed. Delete it.
if err = ctrl.reclaimVolume(volume); err != nil {
// Deletion failed, we will fall back into the same condition
// in the next call to this method
return err
}
return nil
} else {
// Volume is bound to a claim, but the claim is bound elsewhere
// and it's not dynamically provisioned.
if hasAnnotation(volume.ObjectMeta, annBoundByController) {
// This is part of the normal operation of the controller; the
// controller tried to use this volume for a claim but the claim
@ -694,6 +707,7 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *api.PersistentVolume)
}
}
}
}
}
// Run starts all of this controller's control loops