diff --git a/pkg/volume/portworx/portworx_util.go b/pkg/volume/portworx/portworx_util.go index 60677df2c9a..fbf4b883784 100644 --- a/pkg/volume/portworx/portworx_util.go +++ b/pkg/volume/portworx/portworx_util.go @@ -30,12 +30,13 @@ import ( ) const ( - osdMgmtPort = "9001" - osdDriverVersion = "v1" - pxdDriverName = "pxd" - pvcClaimLabel = "pvc" - pxServiceName = "portworx-service" - pxDriverName = "pxd-sched" + osdMgmtPort = "9001" + osdDriverVersion = "v1" + pxdDriverName = "pxd" + pvcClaimLabel = "pvc" + pvcNamespaceLabel = "namespace" + pxServiceName = "portworx-service" + pxDriverName = "pxd-sched" ) type PortworxVolumeUtil struct { @@ -80,9 +81,20 @@ func (util *PortworxVolumeUtil) CreateVolume(p *portworxVolumeProvisioner) (stri // Add claim Name as a part of Portworx Volume Labels locator.VolumeLabels[pvcClaimLabel] = p.options.PVC.Name + locator.VolumeLabels[pvcNamespaceLabel] = p.options.PVC.Namespace + + for k, v := range p.options.PVC.Annotations { + if _, present := spec.VolumeLabels[k]; present { + glog.Warningf("not saving annotation: %s=%s in spec labels due to an existing key", k, v) + continue + } + spec.VolumeLabels[k] = v + } + volumeID, err := driver.Create(locator, source, spec) if err != nil { glog.Errorf("Error creating Portworx Volume : %v", err) + return "", 0, nil, err } glog.Infof("Successfully created Portworx volume for PVC: %v", p.options.PVC.Name)