@@ -173,9 +173,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
173
173
}
174
174
}
175
175
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
179
180
}
180
181
181
182
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)
184
185
mc .ObserveOperationWithResult (isOperationSucceeded )
185
186
}()
186
187
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 )
188
189
client , err := azstorage .NewBasicClientOnSovereignCloud (accountName , accountKey , d .cloud .Environment )
189
190
if err != nil {
190
191
return nil , err
191
192
}
192
193
193
194
blobClient := client .GetBlobService ()
194
- container := blobClient .GetContainerReference (containerName )
195
+ container := blobClient .GetContainerReference (validContainerName )
195
196
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 )
197
198
}
198
199
199
200
if storeAccountKey != storeAccountKeyFalse && len (req .GetSecrets ()) == 0 {
@@ -206,13 +207,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
206
207
}
207
208
}
208
209
209
- volumeID := fmt .Sprintf (volumeIDTemplate , resourceGroup , accountName , containerName )
210
+ volumeID := fmt .Sprintf (volumeIDTemplate , resourceGroup , accountName , validContainerName )
210
211
if containerName != "" {
211
212
// add volume name as suffix to differentiate volumeID since "containerName" is specified
212
213
// not necessary for dynamic container name creation since volumeID already contains volume name
213
214
volumeID = volumeID + "#" + name
214
215
}
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 )
216
217
217
218
isOperationSucceeded = true
218
219
return & csi.CreateVolumeResponse {
0 commit comments