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

fix the create azure file pvc failure if there is no storage account in current resource group #56557

Merged

Conversation

andyzhangx
Copy link
Member

@andyzhangx andyzhangx commented Nov 29, 2017

What this PR does / why we need it:
When create an azure file PVC, there will be error if there is no storage account in current resource group.
With this PR, a storage account will be created if there is no storage account in current resource group.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #56556

Special notes for your reviewer:

  1. rephrase the code logic of CreateFileShare func.
if accountName is empty, then 
    find a storage account that matches accountType
    if no storage account found, then
        create a new account
else
    we only use user specified storage account

create a file share according to found storage account
  1. Use func getStorageAccountName to get a unique storage account name by UUID, a storage account for azure file would be like f0b2b0bd40c010112e897fa. And in next PR, I will use this function to create storage account for azure disk, the storage account for azure disk would be like d8f3ad8ad92000f1e1e88bd.

Release note:

fix the create azure file pvc failure if there is no storage account in current resource group

/sig azure
/assign @rootfs

@k8s-ci-robot k8s-ci-robot added sig/azure release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 29, 2017
@andyzhangx
Copy link
Member Author

/test pull-kubernetes-unit

// find a storage account that matches storageType
accounts, err = az.getStorageAccounts(storageType)
if err != nil || len(accounts) == 0 {
storageAccount = getAccountNameForNum(az.getNextAccountNum())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is getNextAccountNum() defined? The only getNextAccountNum function I can find is defined for blob controller and it is quite buggy...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rootfs yes, it's buggy, I used another way to generate random storage account name for file share, the generated account name could be like pvcfile4100861029

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix this buggy func getNextAccountNum() in another PR, will change the account name generation method, use new one getStorageAccountName by uuid in this PR

@andyzhangx andyzhangx force-pushed the azurefile-createaccount branch 2 times, most recently from b494f06 to fdd53c5 Compare December 1, 2017 09:43
@andyzhangx
Copy link
Member Author

/retest

@rootfs
Copy link
Contributor

rootfs commented Dec 1, 2017

W1201 12:17:02.161] pkg/cloudprovider/providers/azure/azure_blobDiskController.go:94:52: not enough arguments in call to c.common.cloud.getStorageAccounts
W1201 12:17:02.161] 	have ()
W1201 12:17:02.162] 	want (string)
W1201 12:18:14.130] make[1]: *** [vet] Error 1

@andyzhangx andyzhangx force-pushed the azurefile-createaccount branch 2 times, most recently from c7bce8a to 0a02b26 Compare December 1, 2017 15:16
// find a storage account that matches storageType
accounts, err = az.getStorageAccounts(storageType)
if err != nil || len(accounts) == 0 {
uniqueID := az.controllerCommon.resourceGroup + az.controllerCommon.location + az.controllerCommon.subscriptionID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this reveals too much (perhaps sensitive) information

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rootfs there is hash like function MakeCRC32 which would transform uniqueID to a hash string, e,g. if uniqueID is resourcegroupwestuscc1624c7-3f1d-4ed3-a855-668a86e96ad8, it will convert to 2380111856, you could see no one could parse string 2380111856 to get info like resourcegroup, subscriptionID.
The reason I use both uniqueID and UUID is that it's unique for every subscriptionID, resourcegroup, thus the account name conflict possibility be near zero as 1/10 000 000 000 in one resourcegroup. If that possibility happens, user could delete the PVC and recreate PVC again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is that unique string transformed into a CRC string?

Copy link
Contributor

@karataliu karataliu Jan 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andyzhangx
Copy link
Member Author

andyzhangx commented Dec 6, 2017

@rootfs if getStorageAccountName func is ok, I will use this func to fix similar issue where storage account for azure disk is not found:
https://github.com/kubernetes/kubernetes/blob/master/pkg/cloudprovider/providers/azure/azure_blobDiskController.go#L96

@andyzhangx
Copy link
Member Author

ping @rootfs

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 17, 2017
@andyzhangx andyzhangx force-pushed the azurefile-createaccount branch from 0a02b26 to 307b49a Compare December 17, 2017 11:08
@kubernetes kubernetes deleted a comment from k8s-github-robot Dec 17, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 17, 2017
@jdumars
Copy link
Member

jdumars commented Dec 26, 2017

@rootfs PTAL? Thanks!!

@andyzhangx
Copy link
Member Author

@rootfs I have answered your question in the PR, could you take a look? Thanks.

@andyzhangx
Copy link
Member Author

rootfs on Dec 2, 2017  Member
this reveals too much (perhaps sensitive) information

@rootfs there is hash like function MakeCRC32 which would transform uniqueID to a hash string, e,g. if uniqueID is resourcegroupwestuscc1624c7-3f1d-4ed3-a855-668a86e96ad8, it will convert to 2380111856, you could see no one could parse string 2380111856 to get info like resourcegroup, subscriptionID.
The reason I use both uniqueID and UUID is that it's unique for every subscriptionID, resourcegroup, thus the account name conflict possibility be near zero as 1/10 000 000 000 in one resourcegroup. If that possibility happens, user could delete the PVC and recreate PVC again.

@andyzhangx
Copy link
Member Author

@karataliu @feiskyer PTAL, thx.

Copy link
Member

@feiskyer feiskyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 10, 2018
@@ -51,6 +51,9 @@ func (az *Cloud) getStorageAccounts() ([]accountWithLocation, error) {
storageType := ""
if acct.Sku != nil {
storageType = string((*acct.Sku).Name)
if matchingAccountType != "" && strings.ToLower(matchingAccountType) != strings.ToLower(storageType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!strings.EqualFold

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed approved label.

@andyzhangx Could you fix this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@feiskyer feiskyer removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 10, 2018
accountType = defaultStorageAccountType
}

glog.V(2).Infof("azureFile - no storage account found, begin to create a new storage account %s in resource group %s, location: %s, accountType: %s",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better be 'no matching storage account found'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

errResult = fmt.Errorf("failed to find a matching storage account")
// find the access key with this account
accountKey, err := az.getStorageAccesskey(accountName)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine err check in same line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I code like following, it looks ugly, since accountKey will be used in the next statement.

if accountKey, err := az.getStorageAccesskey(accountName); err != nil {
...
} else {
   if err := az.createFileShare(accountName, accountKey, shareName, requestGiB); err != nil {
}

@@ -46,6 +46,9 @@ func (az *Cloud) getStorageAccounts() ([]accountWithLocation, error) {
storageType := ""
if acct.Sku != nil {
storageType = string((*acct.Sku).Name)
if matchingAccountType != "" && !strings.EqualFold(matchingAccountType, storageType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. if acct.Sku is really nil we'd better also skip it.

Consider just making Line40 to verify 'acct.Name != nil && acct.Location !=nil && acct.Sku != nil' , then remaining part could be simplified.

  1. matchingAccountType check could come first to avoid unnecessary 'name & loc' assignment check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, fixed

@karataliu
Copy link
Contributor

Some comments on naming/misc, others look good.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 6, 2018
@andyzhangx andyzhangx force-pushed the azurefile-createaccount branch from b17df2c to fd08023 Compare February 9, 2018 08:38
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 9, 2018
Copy link
Contributor

@karataliu karataliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments. Could you please take a look and do a commit squash

@@ -25,29 +25,29 @@ type accountWithLocation struct {
Name, StorageType, Location string
}

// getStorageAccounts gets the storage accounts' name, type, location in a resource group
func (az *Cloud) getStorageAccounts() ([]accountWithLocation, error) {
// getStorageAccounts gets name, type, location of all storage accounts in a resource group which matches matchingAccountType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and matchingLocation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

storageType = string((*acct.Sku).Name)

location := *acct.Location
if location != "" && !strings.EqualFold(matchingLocation, location) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matchingLocation != "" ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

}
accounts = append(accounts, accountWithLocation{Name: name, StorageType: storageType, Location: loc})
accounts = append(accounts, accountWithLocation{Name: *acct.Name, StorageType: storageType, Location: location})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd better use the actual type & location from acct object here, since storageType and location could be empty

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

storageType, Location is from acc object.

			storageType := string((*acct.Sku).Name)
			if matchingAccountType != "" && !strings.EqualFold(matchingAccountType, storageType) {
				continue
			}

			location := *acct.Location
			if matchingLocation != "" && !strings.EqualFold(matchingLocation, location) {
				continue
			}

@@ -91,7 +91,7 @@ func (c *BlobDiskController) CreateVolume(name, storageAccount, storageAccountTy
accounts = append(accounts, accountWithLocation{Name: storageAccount})
} else {
// find a storage account
accounts, err = c.common.cloud.getStorageAccounts(storageAccountType)
accounts, err = c.common.cloud.getStorageAccounts(storageAccountType, location)
Copy link
Contributor

@karataliu karataliu Feb 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: We can also update upcoming account matching logic when fixing: '// TODO: create a storage account and container'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I am going to fix it in next PR, it's in my plan.

@feiskyer feiskyer added the kind/bug Categorizes issue or PR as related to a bug. label Feb 11, 2018
@feiskyer feiskyer added this to the v1.10 milestone Feb 11, 2018
use new storage account name generation method

use uuid to generate account name

change azure file account prefix

use uniqueID to generate a storage account name

fix comments

fix comments

fix comments

fix a storage account matching bug

only use UUID in getStorageAccountName func

use shorter storage account prefix for azure file

fix comments

fix comments

fix comments

fix rebase build error

rewrite CreateFileShare code logic

fix gofmt issue

fix test error

fix comments

fix a location matching bug
Copy link
Member Author

@andyzhangx andyzhangx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karataliu PTAL

@andyzhangx andyzhangx force-pushed the azurefile-createaccount branch from 663a218 to aa21bef Compare February 11, 2018 06:30
@andyzhangx
Copy link
Member Author

And I have also done a few manual tests on Azure env, it works well.

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-e2e-kops-aws

Copy link
Contributor

@karataliu karataliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

note: update func comments for getStorageAccounts

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 11, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, feiskyer, karataliu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these OWNERS Files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit cfa6774 into kubernetes:master Feb 11, 2018
k8s-github-robot pushed a commit that referenced this pull request Feb 28, 2018
…6557-upstream-release-1.9

Automatic merge from submit-queue.

Automated cherry pick of #56557

Cherry pick of #56557 on release-1.9.

#56557: create storage account if necessary when create azure file
k8s-github-robot pushed a commit that referenced this pull request Mar 2, 2018
…6557-upstream-release-1.7

Automatic merge from submit-queue.

Automated cherry pick of #56557

Cherry pick of #56557 on release-1.7.

#56557: create storage account if necessary when create azure file
jpbetz added a commit that referenced this pull request Apr 4, 2018
…6557-upstream-release-1.8

Automated cherry pick of #56557
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

failed to create azure file pvc if there is no storage account in current resource group
8 participants