Skip to content

Commit 2e96bf5

Browse files
authored
Merge pull request kubernetes#76988 from andyzhangx/azurefile-create
specify azure file share name in azure file plugin
2 parents e53118d + ad9d033 commit 2e96bf5

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

pkg/cloudprovider/providers/azure/azure_file.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ func (f *azureFileClient) createFileShare(accountName, accountKey, name string,
6060
}
6161
share := fileClient.GetShareReference(name)
6262
share.Properties.Quota = sizeGiB
63-
if err = share.Create(nil); err != nil {
63+
newlyCreated, err := share.CreateIfNotExists(nil)
64+
if err != nil {
6465
return fmt.Errorf("failed to create file share, err: %v", err)
6566
}
67+
if !newlyCreated {
68+
klog.V(2).Infof("file share(%s) under account(%s) already exists", name, accountName)
69+
}
6670
return nil
6771
}
6872

pkg/volume/azure_file/azure_provision.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,8 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
142142
return nil, fmt.Errorf("%s does not support block volume provisioning", a.plugin.GetPluginName())
143143
}
144144

145-
var sku, resourceGroup, location, account string
145+
var sku, resourceGroup, location, account, shareName string
146146

147-
// File share name has a length limit of 63, and it cannot contain two consecutive '-'s.
148-
name := util.GenerateVolumeName(a.options.ClusterName, a.options.PVName, 63)
149-
name = strings.Replace(name, "--", "-", -1)
150147
capacity := a.options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
151148
requestGiB := int(volumehelpers.RoundUpToGiB(capacity))
152149
secretNamespace := a.options.PVC.Namespace
@@ -164,6 +161,8 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
164161
secretNamespace = v
165162
case "resourcegroup":
166163
resourceGroup = v
164+
case "sharename":
165+
shareName = v
167166
default:
168167
return nil, fmt.Errorf("invalid option %q for volume plugin %s", k, a.plugin.GetPluginName())
169168
}
@@ -173,12 +172,18 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
173172
return nil, fmt.Errorf("claim.Spec.Selector is not supported for dynamic provisioning on Azure file")
174173
}
175174

175+
if shareName == "" {
176+
// File share name has a length limit of 63, and it cannot contain two consecutive '-'s.
177+
name := util.GenerateVolumeName(a.options.ClusterName, a.options.PVName, 63)
178+
shareName = strings.Replace(name, "--", "-", -1)
179+
}
180+
176181
// when use azure file premium, account kind should be specified as FileStorage
177182
accountKind := string(storage.StorageV2)
178183
if strings.HasPrefix(strings.ToLower(sku), "premium") {
179184
accountKind = string(storage.FileStorage)
180185
}
181-
account, key, err := a.azureProvider.CreateFileShare(name, account, sku, accountKind, resourceGroup, location, requestGiB)
186+
account, key, err := a.azureProvider.CreateFileShare(shareName, account, sku, accountKind, resourceGroup, location, requestGiB)
182187
if err != nil {
183188
return nil, err
184189
}
@@ -206,7 +211,7 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
206211
PersistentVolumeSource: v1.PersistentVolumeSource{
207212
AzureFile: &v1.AzureFilePersistentVolumeSource{
208213
SecretName: secretName,
209-
ShareName: name,
214+
ShareName: shareName,
210215
SecretNamespace: &secretNamespace,
211216
},
212217
},

0 commit comments

Comments
 (0)