Skip to content

Commit eea0c3f

Browse files
authored
Merge pull request #246 from andyzhangx/bring-key-fix
fix: mount failure in bring key scenario
2 parents 3b07824 + c1f092e commit eea0c3f

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

pkg/blob/blob.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const (
5454
tagsField = "tags"
5555
protocolField = "protocol"
5656
secretNamespaceField = "secretnamespace"
57+
containerNameField = "containername"
5758
storeAccountKeyField = "storeaccountkey"
5859
storeAccountKeyFalse = "false"
5960
defaultSecretAccountName = "azurestorageaccountname"
@@ -255,7 +256,7 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID string, attrib, secret
255256

256257
for k, v := range attrib {
257258
switch strings.ToLower(k) {
258-
case "containername":
259+
case containerNameField:
259260
containerName = v
260261
case "keyvaulturl":
261262
keyVaultURL = v
@@ -373,7 +374,7 @@ func (d *Driver) GetStorageAccountAndContainer(ctx context.Context, volumeID str
373374

374375
for k, v := range attrib {
375376
switch strings.ToLower(k) {
376-
case "containername":
377+
case containerNameField:
377378
containerName = v
378379
case "keyvaulturl":
379380
keyVaultURL = v
@@ -518,20 +519,19 @@ func setAzureCredentials(kubeClient kubernetes.Interface, accountName, accountKe
518519
return secretName, err
519520
}
520521

521-
// GetStorageAccesskey get Azure storage account key
522-
func (d *Driver) GetStorageAccesskey(accountOptions *azure.AccountOptions, secrets map[string]string, secretNamespace string) (string, error) {
522+
// GetStorageAccesskey get Azure storage (account name, account key)
523+
func (d *Driver) GetStorageAccesskey(accountOptions *azure.AccountOptions, secrets map[string]string, secretNamespace string) (string, string, error) {
523524
if len(secrets) > 0 {
524-
_, accountKey, err := getStorageAccount(secrets)
525-
return accountKey, err
525+
return getStorageAccount(secrets)
526526
}
527527

528528
// read from k8s secret first
529529
accountKey, err := d.GetStorageAccesskeyFromSecret(accountOptions.Name, secretNamespace)
530530
if err != nil {
531531
klog.V(2).Infof("could not get account(%s) key from secret, error: %v, use cluster identity to get account key instead", accountOptions.Name, err)
532-
return d.cloud.GetStorageAccesskey(accountOptions.Name, accountOptions.ResourceGroup)
532+
accountKey, err = d.cloud.GetStorageAccesskey(accountOptions.Name, accountOptions.ResourceGroup)
533533
}
534-
return accountKey, err
534+
return accountOptions.Name, accountKey, err
535535
}
536536

537537
// GetStorageAccesskeyFromSecret get storage account key from k8s secret

pkg/blob/controllerserver.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
5353
requestGiB := int(util.RoundUpGiB(volSizeBytes))
5454

5555
parameters := req.GetParameters()
56+
if parameters == nil {
57+
parameters = make(map[string]string)
58+
}
5659
var storageAccountType, resourceGroup, location, account, containerName, protocol, customTags, storeAccountKey, secretNamespace string
5760

5861
// Apply ProvisionerParameters (case-insensitive). We leave validation of
@@ -69,7 +72,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
6972
account = v
7073
case "resourcegroup":
7174
resourceGroup = v
72-
case "containername":
75+
case containerNameField:
7376
containerName = v
7477
case protocolField:
7578
protocol = v
@@ -146,13 +149,14 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
146149
accountOptions.Name = accountName
147150

148151
if accountKey == "" {
149-
if accountKey, err = d.GetStorageAccesskey(accountOptions, req.GetSecrets(), secretNamespace); err != nil {
152+
if accountName, accountKey, err = d.GetStorageAccesskey(accountOptions, req.GetSecrets(), secretNamespace); err != nil {
150153
return nil, fmt.Errorf("failed to GetStorageAccesskey on account(%s) rg(%s), error: %v", accountOptions.Name, accountOptions.ResourceGroup, err)
151154
}
152155
}
153156

154157
if containerName == "" {
155158
containerName = getValidContainerName(name, protocol)
159+
parameters[containerNameField] = containerName
156160
}
157161

158162
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)

0 commit comments

Comments
 (0)