chore: set resourceGroup into azure pv annotation

Signed-off-by: ZeroMagic <jiliu8@microsoft.com>
This commit is contained in:
ZeroMagic 2020-05-09 02:51:26 +00:00
parent f3a64e22d9
commit 01713f2411
2 changed files with 21 additions and 3 deletions

View File

@ -169,6 +169,9 @@ func (plugin *azureFilePlugin) ExpandVolumeDevice(
if err != nil {
return oldSize, err
}
if spec.PersistentVolume.ObjectMeta.Annotations[resourceGroupAnnotation] != "" {
resourceGroup = spec.PersistentVolume.ObjectMeta.Annotations[resourceGroupAnnotation]
}
secretName, secretNamespace, err := getSecretNameAndNamespace(spec, spec.PersistentVolume.Spec.ClaimRef.Namespace)
if err != nil {

View File

@ -36,8 +36,12 @@ import (
utilstrings "k8s.io/utils/strings"
)
var _ volume.DeletableVolumePlugin = &azureFilePlugin{}
var _ volume.ProvisionableVolumePlugin = &azureFilePlugin{}
var (
_ volume.DeletableVolumePlugin = &azureFilePlugin{}
_ volume.ProvisionableVolumePlugin = &azureFilePlugin{}
resourceGroupAnnotation = "kubernetes.io/azure-file-resource-group"
)
// Abstract interface to file share operations.
// azure cloud provider should implement it
@ -62,6 +66,9 @@ func (plugin *azureFilePlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, er
klog.V(4).Infof("failed to get azure provider")
return nil, err
}
if spec.PersistentVolume != nil && spec.PersistentVolume.ObjectMeta.Annotations[resourceGroupAnnotation] != "" {
resourceGroup = spec.PersistentVolume.ObjectMeta.Annotations[resourceGroupAnnotation]
}
return plugin.newDeleterInternal(spec, &azureSvc{}, azure, resourceGroup)
}
@ -94,7 +101,7 @@ func (plugin *azureFilePlugin) newDeleterInternal(spec *volume.Spec, util azureU
}
func (plugin *azureFilePlugin) NewProvisioner(options volume.VolumeOptions) (volume.Provisioner, error) {
azure, _, err := getAzureCloudProvider(plugin.host.GetCloudProvider())
azure, resourceGroup, err := getAzureCloudProvider(plugin.host.GetCloudProvider())
if err != nil {
klog.V(4).Infof("failed to get azure provider")
return nil, err
@ -102,6 +109,9 @@ func (plugin *azureFilePlugin) NewProvisioner(options volume.VolumeOptions) (vol
if len(options.PVC.Spec.AccessModes) == 0 {
options.PVC.Spec.AccessModes = plugin.GetAccessModes()
}
if resourceGroup != "" {
options.PVC.ObjectMeta.Annotations[resourceGroupAnnotation] = resourceGroup
}
return plugin.newProvisionerInternal(options, azure)
}
@ -181,6 +191,10 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
shareName = strings.Replace(name, "--", "-", -1)
}
if resourceGroup == "" {
resourceGroup = a.options.PVC.ObjectMeta.Annotations[resourceGroupAnnotation]
}
// when use azure file premium, account kind should be specified as FileStorage
accountKind := string(storage.StorageV2)
if strings.HasPrefix(strings.ToLower(sku), "premium") {
@ -203,6 +217,7 @@ func (a *azureFileProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
Labels: map[string]string{},
Annotations: map[string]string{
util.VolumeDynamicallyCreatedByKey: "azure-file-dynamic-provisioner",
resourceGroupAnnotation: resourceGroup,
},
},
Spec: v1.PersistentVolumeSpec{