Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #76988: add shareName param in azure file storage class #77043

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/cloudprovider/providers/azure/azure_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ func (f *azureFileClient) createFileShare(accountName, accountKey, name string,
}
share := fileClient.GetShareReference(name)
share.Properties.Quota = sizeGiB
if err = share.Create(nil); err != nil {
newlyCreated, err := share.CreateIfNotExists(nil)
if err != nil {
return fmt.Errorf("failed to create file share, err: %v", err)
}
if !newlyCreated {
klog.V(2).Infof("file share(%s) under account(%s) already exists", name, accountName)
}
return nil
}

Expand Down
17 changes: 11 additions & 6 deletions pkg/volume/azure_file/azure_provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,8 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
return nil, fmt.Errorf("%s does not support block volume provisioning", a.plugin.GetPluginName())
}

var sku, resourceGroup, location, account string
var sku, resourceGroup, location, account, shareName string

// File share name has a length limit of 63, and it cannot contain two consecutive '-'s.
name := util.GenerateVolumeName(a.options.ClusterName, a.options.PVName, 63)
name = strings.Replace(name, "--", "-", -1)
capacity := a.options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
requestBytes := capacity.Value()
requestGiB := int(util.RoundUpSize(requestBytes, 1024*1024*1024))
Expand All @@ -164,6 +161,8 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
secretNamespace = v
case "resourcegroup":
resourceGroup = v
case "sharename":
shareName = v
default:
return nil, fmt.Errorf("invalid option %q for volume plugin %s", k, a.plugin.GetPluginName())
}
Expand All @@ -173,12 +172,18 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
return nil, fmt.Errorf("claim.Spec.Selector is not supported for dynamic provisioning on Azure file")
}

if shareName == "" {
// File share name has a length limit of 63, and it cannot contain two consecutive '-'s.
name := util.GenerateVolumeName(a.options.ClusterName, a.options.PVName, 63)
shareName = strings.Replace(name, "--", "-", -1)
}

// when use azure file premium, account kind should be specified as FileStorage
accountKind := string(storage.StorageV2)
if strings.HasPrefix(strings.ToLower(sku), "premium") {
accountKind = string(storage.FileStorage)
}
account, key, err := a.azureProvider.CreateFileShare(name, account, sku, accountKind, resourceGroup, location, requestGiB)
account, key, err := a.azureProvider.CreateFileShare(shareName, account, sku, accountKind, resourceGroup, location, requestGiB)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -206,7 +211,7 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
PersistentVolumeSource: v1.PersistentVolumeSource{
AzureFile: &v1.AzureFilePersistentVolumeSource{
SecretName: secretName,
ShareName: name,
ShareName: shareName,
SecretNamespace: &secretNamespace,
},
},
Expand Down