diff --git a/cmd/csi-provisioner/csi-provisioner.go b/cmd/csi-provisioner/csi-provisioner.go index 8af4304916..7997110188 100644 --- a/cmd/csi-provisioner/csi-provisioner.go +++ b/cmd/csi-provisioner/csi-provisioner.go @@ -44,7 +44,7 @@ var ( csiEndpoint = flag.String("csi-address", "/run/csi/socket", "The gRPC endpoint for Target CSI Volume") connectionTimeout = flag.Duration("connection-timeout", 10*time.Second, "Timeout for waiting for CSI driver socket.") volumeNamePrefix = flag.String("volume-name-prefix", "pvc", "Prefix to apply to the name of a created volume") - volumeNameUUIDLength = flag.Int("volume-name-uuid-length", 16, "Length in characters for the generated uuid of a created volume") + volumeNameUUIDLength = flag.Int("volume-name-uuid-length", -1, "Truncates generated UUID of a created volume to this length. Defaults behavior is to NOT truncate.") showVersion = flag.Bool("version", false, "Show version.") provisionController *controller.ProvisionController diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 4ad6c85a62..a19c2bb4d4 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -274,7 +274,14 @@ func makeVolumeName(prefix, pvcUID string, volumeNameUUIDLength int) (string, er if len(pvcUID) == 0 { return "", fmt.Errorf("corrupted PVC object, it is missing UID") } - return fmt.Sprintf("%s-%s", prefix, strings.Replace(string(pvcUID), "-", "", -1)[0:volumeNameUUIDLength]), nil + if volumeNameUUIDLength == -1 { + // Default behavior is to not truncate or remove dashes + return fmt.Sprintf("%s-%s", prefix, pvcUID), nil + } else { + // Else we remove all dashes from UUID and truncate to volumeNameUUIDLength + return fmt.Sprintf("%s-%s", prefix, strings.Replace(string(pvcUID), "-", "", -1)[0:volumeNameUUIDLength]), nil + } + } func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.PersistentVolume, error) {