Merge pull request #21268 from jsafrane/devel/recycle-provisioned

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot 2016-02-20 15:26:28 -08:00
commit a52eb5d433

View File

@ -239,24 +239,31 @@ func syncVolume(volumeIndex *persistentVolumeOrderedIndex, binderClient binderCl
if volume.Spec.ClaimRef != nil { if volume.Spec.ClaimRef != nil {
claim, err := binderClient.GetPersistentVolumeClaim(volume.Spec.ClaimRef.Namespace, volume.Spec.ClaimRef.Name) claim, err := binderClient.GetPersistentVolumeClaim(volume.Spec.ClaimRef.Namespace, volume.Spec.ClaimRef.Name)
if errors.IsNotFound(err) { if errors.IsNotFound(err) {
// Pending volumes that have a ClaimRef where the claim is missing were recently recycled. if volume.Spec.PersistentVolumeReclaimPolicy == api.PersistentVolumeReclaimRecycle {
// The Recycler set the phase to VolumePending to start the volume at the beginning of this lifecycle. // Pending volumes that have a ClaimRef where the claim is missing were recently recycled.
// removing ClaimRef unbinds the volume // The Recycler set the phase to VolumePending to start the volume at the beginning of this lifecycle.
clone, err := conversion.NewCloner().DeepCopy(volume) // removing ClaimRef unbinds the volume
if err != nil { clone, err := conversion.NewCloner().DeepCopy(volume)
return fmt.Errorf("Error cloning pv: %v", err) if err != nil {
} return fmt.Errorf("Error cloning pv: %v", err)
volumeClone, ok := clone.(*api.PersistentVolume) }
if !ok { volumeClone, ok := clone.(*api.PersistentVolume)
return fmt.Errorf("Unexpected pv cast error : %v\n", volumeClone) if !ok {
} return fmt.Errorf("Unexpected pv cast error : %v\n", volumeClone)
volumeClone.Spec.ClaimRef = nil }
volumeClone.Spec.ClaimRef = nil
if updatedVolume, err := binderClient.UpdatePersistentVolume(volumeClone); err != nil { if updatedVolume, err := binderClient.UpdatePersistentVolume(volumeClone); err != nil {
return fmt.Errorf("Unexpected error saving PersistentVolume: %+v", err) return fmt.Errorf("Unexpected error saving PersistentVolume: %+v", err)
} else {
volume = updatedVolume
volumeIndex.Update(volume)
}
} else { } else {
volume = updatedVolume // Pending volumes that has a ClaimRef and the claim is missing and is was not recycled.
volumeIndex.Update(volume) // It must have been freshly provisioned and the claim was deleted during the provisioning.
// Mark the volume as Released, it will be deleted.
nextPhase = api.VolumeReleased
} }
} else if err != nil { } else if err != nil {
return fmt.Errorf("Error getting PersistentVolumeClaim[%s/%s]: %v", volume.Spec.ClaimRef.Namespace, volume.Spec.ClaimRef.Name, err) return fmt.Errorf("Error getting PersistentVolumeClaim[%s/%s]: %v", volume.Spec.ClaimRef.Namespace, volume.Spec.ClaimRef.Name, err)