From 69ecce1e75f9d0fc1ed8e6d635810e2cbe8e2cde Mon Sep 17 00:00:00 2001 From: gman Date: Fri, 13 Apr 2018 14:24:40 +0200 Subject: [PATCH] cephfs/volumeidentifier: changed volume ID scheme volumes have "csi-cephfs-dyn-" prefix when they are provisioned dynamically (provisionVolume=true) and have "csi-cephfs-sta-" prefix when they are provisioned statically by the user (provisionVolume=false) --- pkg/cephfs/volumeidentifier.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/cephfs/volumeidentifier.go b/pkg/cephfs/volumeidentifier.go index c4d58b04f..3380e4030 100644 --- a/pkg/cephfs/volumeidentifier.go +++ b/pkg/cephfs/volumeidentifier.go @@ -21,6 +21,12 @@ import ( "github.com/pborman/uuid" ) +const ( + dynamicallyProvisionedVolumePrefix = "csi-cephfs-dyn-" + staticallyProvisionedVolumePrefix = "csi-cephfs-sta-" + volumePrefixLen = len(dynamicallyProvisionedVolumePrefix) +) + type volumeIdentifier struct { name, uuid, id string } @@ -31,7 +37,24 @@ func newVolumeIdentifier(volOptions *volumeOptions, req *csi.CreateVolumeRequest uuid: uuid.NewUUID().String(), } - volId.id = "csi-cephfs-" + volId.uuid + prefix := staticallyProvisionedVolumePrefix + if volOptions.ProvisionVolume { + prefix = dynamicallyProvisionedVolumePrefix + } + + volId.id = prefix + volId.uuid return &volId } + +func uuidFromVolumeId(volId string) string { + return volId[volumePrefixLen:] +} + +func isDynProvision(volId string) bool { + if len(volId) <= volumePrefixLen { + return false + } + + return volId[:volumePrefixLen] == dynamicallyProvisionedVolumePrefix +}