diff --git a/pkg/cloudprovider/providers/azure/azure_blobDiskController.go b/pkg/cloudprovider/providers/azure/azure_blobDiskController.go index 7331db72f7cd6..b5db3efe684b7 100644 --- a/pkg/cloudprovider/providers/azure/azure_blobDiskController.go +++ b/pkg/cloudprovider/providers/azure/azure_blobDiskController.go @@ -79,7 +79,7 @@ func newBlobDiskController(common *controllerCommon) (*BlobDiskController, error // If no storage account is given, search all the storage accounts associated with the resource group and pick one that // fits storage type and location. func (c *BlobDiskController) CreateVolume(blobName, accountName, accountType, location string, requestGB int) (string, string, int, error) { - account, key, err := c.common.cloud.ensureStorageAccount(accountName, accountType, location, dedicatedDiskAccountNamePrefix) + account, key, err := c.common.cloud.ensureStorageAccount(accountName, accountType, c.common.resourceGroup, location, dedicatedDiskAccountNamePrefix) if err != nil { return "", "", 0, fmt.Errorf("could not get storage key for storage account %s: %v", accountName, err) } @@ -107,7 +107,7 @@ func (c *BlobDiskController) DeleteVolume(diskURI string) error { if err != nil { return fmt.Errorf("failed to parse vhd URI %v", err) } - key, err := c.common.cloud.getStorageAccesskey(accountName) + key, err := c.common.cloud.getStorageAccesskey(accountName, c.common.resourceGroup) if err != nil { return fmt.Errorf("no key for storage account %s, err %v", accountName, err) } diff --git a/pkg/cloudprovider/providers/azure/azure_storage.go b/pkg/cloudprovider/providers/azure/azure_storage.go index 91b6df67df5e2..7a7ba50359c3c 100644 --- a/pkg/cloudprovider/providers/azure/azure_storage.go +++ b/pkg/cloudprovider/providers/azure/azure_storage.go @@ -31,8 +31,12 @@ const ( ) // CreateFileShare creates a file share, using a matching storage account -func (az *Cloud) CreateFileShare(shareName, accountName, accountType, location string, requestGiB int) (string, string, error) { - account, key, err := az.ensureStorageAccount(accountName, accountType, location, fileShareAccountNamePrefix) +func (az *Cloud) CreateFileShare(shareName, accountName, accountType, resourceGroup, location string, requestGiB int) (string, string, error) { + if resourceGroup == "" { + resourceGroup = az.resourceGroup + } + + account, key, err := az.ensureStorageAccount(accountName, accountType, resourceGroup, location, fileShareAccountNamePrefix) if err != nil { return "", "", fmt.Errorf("could not get storage key for storage account %s: %v", accountName, err) } diff --git a/pkg/cloudprovider/providers/azure/azure_storageaccount.go b/pkg/cloudprovider/providers/azure/azure_storageaccount.go index 7218fb0218429..c85f2f670f762 100644 --- a/pkg/cloudprovider/providers/azure/azure_storageaccount.go +++ b/pkg/cloudprovider/providers/azure/azure_storageaccount.go @@ -30,16 +30,16 @@ type accountWithLocation struct { } // getStorageAccounts gets name, type, location of all storage accounts in a resource group which matches matchingAccountType, matchingLocation -func (az *Cloud) getStorageAccounts(matchingAccountType, matchingLocation string) ([]accountWithLocation, error) { +func (az *Cloud) getStorageAccounts(matchingAccountType, resourceGroup, matchingLocation string) ([]accountWithLocation, error) { az.operationPollRateLimiter.Accept() - glog.V(10).Infof("StorageAccountClient.ListByResourceGroup(%v): start", az.ResourceGroup) - result, err := az.StorageAccountClient.ListByResourceGroup(az.ResourceGroup) - glog.V(10).Infof("StorageAccountClient.ListByResourceGroup(%v): end", az.ResourceGroup) + glog.V(10).Infof("StorageAccountClient.ListByResourceGroup(%v): start", resourceGroup) + result, err := az.StorageAccountClient.ListByResourceGroup(resourceGroup) + glog.V(10).Infof("StorageAccountClient.ListByResourceGroup(%v): end", resourceGroup) if err != nil { return nil, err } if result.Value == nil { - return nil, fmt.Errorf("unexpected error when listing storage accounts from resource group %s", az.ResourceGroup) + return nil, fmt.Errorf("unexpected error when listing storage accounts from resource group %s", resourceGroup) } accounts := []accountWithLocation{} @@ -62,10 +62,10 @@ func (az *Cloud) getStorageAccounts(matchingAccountType, matchingLocation string } // getStorageAccesskey gets the storage account access key -func (az *Cloud) getStorageAccesskey(account string) (string, error) { +func (az *Cloud) getStorageAccesskey(account, resourceGroup string) (string, error) { az.operationPollRateLimiter.Accept() glog.V(10).Infof("StorageAccountClient.ListKeys(%q): start", account) - result, err := az.StorageAccountClient.ListKeys(az.ResourceGroup, account) + result, err := az.StorageAccountClient.ListKeys(resourceGroup, account) glog.V(10).Infof("StorageAccountClient.ListKeys(%q): end", account) if err != nil { return "", err @@ -87,10 +87,10 @@ func (az *Cloud) getStorageAccesskey(account string) (string, error) { } // ensureStorageAccount search storage account, create one storage account(with genAccountNamePrefix) if not found, return accountName, accountKey -func (az *Cloud) ensureStorageAccount(accountName, accountType, location, genAccountNamePrefix string) (string, string, error) { +func (az *Cloud) ensureStorageAccount(accountName, accountType, resourceGroup, location, genAccountNamePrefix string) (string, string, error) { if len(accountName) == 0 { // find a storage account that matches accountType - accounts, err := az.getStorageAccounts(accountType, location) + accounts, err := az.getStorageAccounts(accountType, resourceGroup, location) if err != nil { return "", "", fmt.Errorf("could not list storage accounts for account type %s: %v", accountType, err) } @@ -111,7 +111,7 @@ func (az *Cloud) ensureStorageAccount(accountName, accountType, location, genAcc } glog.V(2).Infof("azure - no matching account found, begin to create a new account %s in resource group %s, location: %s, accountType: %s", - accountName, az.ResourceGroup, location, accountType) + accountName, resourceGroup, location, accountType) cp := storage.AccountCreateParameters{ Sku: &storage.Sku{Name: storage.SkuName(accountType)}, Tags: &map[string]*string{"created-by": to.StringPtr("azure")}, @@ -119,7 +119,7 @@ func (az *Cloud) ensureStorageAccount(accountName, accountType, location, genAcc Location: &location} cancel := make(chan struct{}) - _, errchan := az.StorageAccountClient.Create(az.ResourceGroup, accountName, cp, cancel) + _, errchan := az.StorageAccountClient.Create(resourceGroup, accountName, cp, cancel) err := <-errchan if err != nil { return "", "", fmt.Errorf(fmt.Sprintf("Failed to create storage account %s, error: %s", accountName, err)) @@ -128,7 +128,7 @@ func (az *Cloud) ensureStorageAccount(accountName, accountType, location, genAcc } // find the access key with this account - accountKey, err := az.getStorageAccesskey(accountName) + accountKey, err := az.getStorageAccesskey(accountName, resourceGroup) if err != nil { return "", "", fmt.Errorf("could not get storage key for storage account %s: %v", accountName, err) } diff --git a/pkg/volume/azure_file/azure_provision.go b/pkg/volume/azure_file/azure_provision.go index dbbdda0b5c054..4241f6131ed8f 100644 --- a/pkg/volume/azure_file/azure_provision.go +++ b/pkg/volume/azure_file/azure_provision.go @@ -38,7 +38,7 @@ var _ volume.ProvisionableVolumePlugin = &azureFilePlugin{} // azure cloud provider should implement it type azureCloudProvider interface { // create a file share - CreateFileShare(shareName, accountName, accountType, location string, requestGiB int) (string, string, error) + CreateFileShare(shareName, accountName, accountType, resourceGroup, location string, requestGiB int) (string, string, error) // delete a file share DeleteFileShare(accountName, accountKey, shareName string) error } @@ -134,7 +134,7 @@ func (a *azureFileProvisioner) Provision() (*v1.PersistentVolume, error) { return nil, fmt.Errorf("invalid AccessModes %v: only AccessModes %v are supported", a.options.PVC.Spec.AccessModes, a.plugin.GetAccessModes()) } - var sku, location, account string + var sku, resourceGroup, location, account string // File share name has a length limit of 63, and it cannot contain two consecutive '-'s. name := volume.GenerateVolumeName(a.options.ClusterName, a.options.PVName, 63) @@ -155,6 +155,8 @@ func (a *azureFileProvisioner) Provision() (*v1.PersistentVolume, error) { account = v case "secretnamespace": secretNamespace = v + case "resourcegroup": + resourceGroup = v default: return nil, fmt.Errorf("invalid option %q for volume plugin %s", k, a.plugin.GetPluginName()) } @@ -164,7 +166,7 @@ func (a *azureFileProvisioner) Provision() (*v1.PersistentVolume, error) { return nil, fmt.Errorf("claim.Spec.Selector is not supported for dynamic provisioning on Azure file") } - account, key, err := a.azureProvider.CreateFileShare(name, account, sku, location, requestGB) + account, key, err := a.azureProvider.CreateFileShare(name, account, sku, resourceGroup, location, requestGB) if err != nil { return nil, err }