From 8ebed5776796916a820eacf39a92af84bfe14eda Mon Sep 17 00:00:00 2001 From: Vladimir Vivien Date: Mon, 30 Jan 2017 12:15:44 -0500 Subject: [PATCH] Prevent pv controller from forcefully overwrite provisioned volume name This fix prevents the PV controller from forcefully overwriting the provisioned volume's name with the generated PV name. Instead, it allows dynamic provisioner implementers to set the name of the volume to a value that they choose. --- pkg/controller/volume/persistentvolume/pv_controller.go | 4 +++- pkg/volume/plugins.go | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/controller/volume/persistentvolume/pv_controller.go b/pkg/controller/volume/persistentvolume/pv_controller.go index 1d5b54185d9..9b17e9ffe43 100644 --- a/pkg/controller/volume/persistentvolume/pv_controller.go +++ b/pkg/controller/volume/persistentvolume/pv_controller.go @@ -1329,7 +1329,9 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(claimObj interfa glog.V(3).Infof("volume %q for claim %q created", volume.Name, claimToClaimKey(claim)) // Create Kubernetes PV object for the volume. - volume.Name = pvName + if volume.Name == "" { + volume.Name = pvName + } // Bind it to the claim volume.Spec.ClaimRef = claimRef volume.Status.Phase = v1.VolumeBound diff --git a/pkg/volume/plugins.go b/pkg/volume/plugins.go index f63b8993203..bc94c0bc826 100644 --- a/pkg/volume/plugins.go +++ b/pkg/volume/plugins.go @@ -42,8 +42,10 @@ type VolumeOptions struct { // Reclamation policy for a persistent volume PersistentVolumeReclaimPolicy v1.PersistentVolumeReclaimPolicy - // PV.Name of the appropriate PersistentVolume. Used to generate cloud - // volume name. + // Suggested PV.Name of the PersistentVolume to provision. + // This is a generated name guaranteed to be unique in Kubernetes cluster. + // If you choose not to use it as volume name, ensure uniqueness by either + // combining it with your value or create unique values of your own. PVName string // PVC is reference to the claim that lead to provisioning of a new PV. // Provisioners *must* create a PV that would be matched by this PVC,