Skip to content

Commit f426089

Browse files
authored
Merge pull request #424 from andyzhangx/volumeid-format-issue
fix: incorrect volumeid format
2 parents 6d37ff2 + d1d6c02 commit f426089

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

pkg/blob/controllerserver.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
173173
}
174174
}
175175

176-
if containerName == "" {
177-
containerName = getValidContainerName(name, protocol)
178-
parameters[containerNameField] = containerName
176+
validContainerName := containerName
177+
if validContainerName == "" {
178+
validContainerName = getValidContainerName(name, protocol)
179+
parameters[containerNameField] = validContainerName
179180
}
180181

181182
mc := metrics.NewMetricContext(blobCSIDriverName, "controller_create_volume", d.cloud.ResourceGroup, d.cloud.SubscriptionID, d.Name)
@@ -184,16 +185,16 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
184185
mc.ObserveOperationWithResult(isOperationSucceeded)
185186
}()
186187

187-
klog.V(2).Infof("begin to create container(%s) on account(%s) type(%s) rg(%s) location(%s) size(%d)", containerName, accountName, storageAccountType, resourceGroup, location, requestGiB)
188+
klog.V(2).Infof("begin to create container(%s) on account(%s) type(%s) rg(%s) location(%s) size(%d)", validContainerName, accountName, storageAccountType, resourceGroup, location, requestGiB)
188189
client, err := azstorage.NewBasicClientOnSovereignCloud(accountName, accountKey, d.cloud.Environment)
189190
if err != nil {
190191
return nil, err
191192
}
192193

193194
blobClient := client.GetBlobService()
194-
container := blobClient.GetContainerReference(containerName)
195+
container := blobClient.GetContainerReference(validContainerName)
195196
if _, err = container.CreateIfNotExists(&azstorage.CreateContainerOptions{Access: azstorage.ContainerAccessTypePrivate}); err != nil {
196-
return nil, fmt.Errorf("failed to create container(%s) on account(%s) type(%s) rg(%s) location(%s) size(%d), error: %v", containerName, accountName, storageAccountType, resourceGroup, location, requestGiB, err)
197+
return nil, fmt.Errorf("failed to create container(%s) on account(%s) type(%s) rg(%s) location(%s) size(%d), error: %v", validContainerName, accountName, storageAccountType, resourceGroup, location, requestGiB, err)
197198
}
198199

199200
if storeAccountKey != storeAccountKeyFalse && len(req.GetSecrets()) == 0 {
@@ -206,13 +207,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
206207
}
207208
}
208209

209-
volumeID := fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, containerName)
210+
volumeID := fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, validContainerName)
210211
if containerName != "" {
211212
// add volume name as suffix to differentiate volumeID since "containerName" is specified
212213
// not necessary for dynamic container name creation since volumeID already contains volume name
213214
volumeID = volumeID + "#" + name
214215
}
215-
klog.V(2).Infof("create container %s on storage account %s successfully", containerName, accountName)
216+
klog.V(2).Infof("create container %s on storage account %s successfully", validContainerName, accountName)
216217

217218
isOperationSucceeded = true
218219
return &csi.CreateVolumeResponse{

0 commit comments

Comments
 (0)