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 error prone account creation method of blob disk #59739

Merged

Conversation

andyzhangx
Copy link
Member

What this PR does / why we need it:
use new account generation method for blob disk to fix the error prone account creation method of blob disk

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 #59738

Special notes for your reviewer:

Release note:

fix the error prone account creation method of azure blob disk

/assign @karataliu
/sig azure

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/azure 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 Feb 12, 2018
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 12, 2018
@feiskyer feiskyer added this to the v1.10 milestone Feb 12, 2018
@feiskyer feiskyer added the kind/bug Categorizes issue or PR as related to a bug. label Feb 12, 2018
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

@@ -555,7 +543,7 @@ func (c *BlobDiskController) findSANameForDisk(storageAccountType storage.SkuNam
countAccounts := 0 // account of this type.
for _, v := range c.accounts {
// filter out any stand-alone disks/accounts
if strings.Index(v.name, storageAccountNameMatch) != 0 {
if strings.Index(v.name, azureDiskAccountNamePrefix) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

!strings.HasPrefix better

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

storageAccountNameMatch = storageAccountNamePrefix
// Used as a template to create new names for relevant accounts
storageAccountNamePrefix = storageAccountNamePrefix + "%s"
defaultContainerName = MakeCRC32(c.common.resourceGroup + c.common.location + c.common.subscriptionID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason we need a unique container name? What about using a fixed one

Copy link
Member Author

Choose a reason for hiding this comment

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

just keep it, it's not related to this PR, I just used the original code.
unique or fixed name, all looks good.

@@ -481,7 +469,7 @@ func (c *BlobDiskController) getAllStorageAccounts() (map[string]*storageAccount

accounts := make(map[string]*storageAccountState)
for _, v := range *accountListResult.Value {
if strings.Index(*v.Name, storageAccountNameMatch) != 0 {
if strings.Index(*v.Name, azureDiskAccountNamePrefix) != 0 {
Copy link
Contributor

@karataliu karataliu Feb 12, 2018

Choose a reason for hiding this comment

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

The code accesses *v.Name first, and check v.Name == nil in next block? Consider fixing it?

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 catch. fixed.

@@ -27,6 +27,7 @@ import (
const (
defaultStorageAccountType = string(storage.StandardLRS)
fileShareAccountNamePrefix = "f"
azureDiskAccountNamePrefix = "dk"
Copy link
Contributor

Choose a reason for hiding this comment

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

why not 'd', if 'k' has special meaning consider add some comments here

Copy link
Member Author

@andyzhangx andyzhangx Feb 12, 2018

Choose a reason for hiding this comment

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

This is for support kind = Shared accounts. one letter d is not enough, and I also don't want to use disk it has 4 letters, so I use dk it's not a word, to differentiate customer self created accounts. A little balancing tricky ...

Update, I used ds finally, stands for disk shared

@andyzhangx andyzhangx force-pushed the azuredisk-initaccount branch from 070c4a4 to 3f7f9b3 Compare February 12, 2018 07:42
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 again.

@@ -481,7 +469,7 @@ func (c *BlobDiskController) getAllStorageAccounts() (map[string]*storageAccount

accounts := make(map[string]*storageAccountState)
for _, v := range *accountListResult.Value {
if strings.Index(*v.Name, storageAccountNameMatch) != 0 {
if strings.Index(*v.Name, azureDiskAccountNamePrefix) != 0 {
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 catch. fixed.

@@ -555,7 +543,7 @@ func (c *BlobDiskController) findSANameForDisk(storageAccountType storage.SkuNam
countAccounts := 0 // account of this type.
for _, v := range c.accounts {
// filter out any stand-alone disks/accounts
if strings.Index(v.name, storageAccountNameMatch) != 0 {
if strings.Index(v.name, azureDiskAccountNamePrefix) != 0 {
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

@@ -27,6 +27,7 @@ import (
const (
defaultStorageAccountType = string(storage.StandardLRS)
fileShareAccountNamePrefix = "f"
azureDiskAccountNamePrefix = "dk"
Copy link
Member Author

@andyzhangx andyzhangx Feb 12, 2018

Choose a reason for hiding this comment

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

This is for support kind = Shared accounts. one letter d is not enough, and I also don't want to use disk it has 4 letters, so I use dk it's not a word, to differentiate customer self created accounts. A little balancing tricky ...

Update, I used ds finally, stands for disk shared

storageAccountNameMatch = storageAccountNamePrefix
// Used as a template to create new names for relevant accounts
storageAccountNamePrefix = storageAccountNamePrefix + "%s"
defaultContainerName = MakeCRC32(c.common.resourceGroup + c.common.location + c.common.subscriptionID)
Copy link
Member Author

Choose a reason for hiding this comment

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

just keep it, it's not related to this PR, I just used the original code.
unique or fixed name, all looks good.

@andyzhangx andyzhangx force-pushed the azuredisk-initaccount branch 2 times, most recently from 07773fb to da22599 Compare February 12, 2018 08:06
@andyzhangx
Copy link
Member Author

@karataliu now below are the prefix nameing:

+	fileShareAccountNamePrefix     = "f"
 +	sharedDiskAccountNamePrefix    = "ds"
 +	dedicatedDiskAccountNamePrefix = "dd"

@andyzhangx andyzhangx force-pushed the azuredisk-initaccount branch 2 times, most recently from be22aaf to 21f7e69 Compare February 12, 2018 09:13
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 12, 2018
@andyzhangx
Copy link
Member Author

@karataliu I added a new common func SearchStorageAccount for CreateFileShare and CreateVolume funcs, this PR should be the last of series of PRs which is targeting to refactor k8s volume on azure code stating from 2017.9, I will cherry pick this PR to v1.8, v1.9. Thanks for your code review.

@@ -75,3 +79,52 @@ func (az *Cloud) getStorageAccesskey(account string) (string, error) {
}
return "", fmt.Errorf("no valid keys")
}

// SearchStorageAccount search storage account, create one storage account(with genAccountNamePrefix) if not found, return accountName, accountKey
func (az *Cloud) SearchStorageAccount(accountName, accountType, location, genAccountNamePrefix string) (string, string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This func is to be used in package only, consider making it lower case

Also 'search' looks like a read only operation, may be use 'ensure' better, like other places

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, I am also considering a good name, ensureStorageAccount is better

fileShareAccountNamePrefix = "f"
defaultStorageAccountType = string(storage.StandardLRS)
fileShareAccountNamePrefix = "f"
sharedDiskAccountNamePrefix = "ds"
Copy link
Contributor

Choose a reason for hiding this comment

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

Those should be placed in the file where it is in use?
azure_storage.go now contains file-service only code, maybe we need to merge it to azure_file.go someday.

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, just keep it in this PR.


// find the access key with this account
accountKey, err := az.getStorageAccesskey(accountName)
accountName, accountKey, err := az.SearchStorageAccount(accountName, accountType, location, fileShareAccountNamePrefix)
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 not assign value to 'accountName' here.

Consider the code in SearchStorageAccount:

+	accountKey, err := az.getStorageAccesskey(accountName)
 +	if err != nil {
 +		return "", "", fmt.Errorf("could not get storage key for storage account %s: %v", accountName, err)
 +	}

If user specifies 'AccountName', but later getStorageAccesskey fails, then SearchStorageAccount returns empty for first parameter.

In this case the follow-up error reported would use empty value for accountName, which does not sound good to user.

Also for CreateVolume.

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 catch, fixed both funcs.

@@ -555,7 +516,7 @@ func (c *BlobDiskController) findSANameForDisk(storageAccountType storage.SkuNam
countAccounts := 0 // account of this type.
for _, v := range c.accounts {
// filter out any stand-alone disks/accounts
if strings.Index(v.name, storageAccountNameMatch) != 0 {
if strings.Index(v.name, sharedDiskAccountNamePrefix) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also strings.HasPrefix ?

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

fix comments

change azureDiskSharedAccountNamePrefix var

rename sharedDiskAccountNamePrefix

use default vhd container name as "vhds"

use one commaon func: SearchStorageAccount

fix comments
@andyzhangx andyzhangx force-pushed the azuredisk-initaccount branch from 21f7e69 to 8a7198b Compare February 12, 2018 13:10
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 really good comments, PTAL.

@@ -555,7 +516,7 @@ func (c *BlobDiskController) findSANameForDisk(storageAccountType storage.SkuNam
countAccounts := 0 // account of this type.
for _, v := range c.accounts {
// filter out any stand-alone disks/accounts
if strings.Index(v.name, storageAccountNameMatch) != 0 {
if strings.Index(v.name, sharedDiskAccountNamePrefix) != 0 {
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

fileShareAccountNamePrefix = "f"
defaultStorageAccountType = string(storage.StandardLRS)
fileShareAccountNamePrefix = "f"
sharedDiskAccountNamePrefix = "ds"
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, just keep it in this PR.


// find the access key with this account
accountKey, err := az.getStorageAccesskey(accountName)
accountName, accountKey, err := az.SearchStorageAccount(accountName, accountType, location, fileShareAccountNamePrefix)
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 catch, fixed both funcs.

@@ -75,3 +79,52 @@ func (az *Cloud) getStorageAccesskey(account string) (string, error) {
}
return "", fmt.Errorf("no valid keys")
}

// SearchStorageAccount search storage account, create one storage account(with genAccountNamePrefix) if not found, return accountName, accountKey
func (az *Cloud) SearchStorageAccount(accountName, accountType, location, genAccountNamePrefix string) (string, string, error) {
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, I am also considering a good name, ensureStorageAccount is better

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

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, 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]

@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 91c783e into kubernetes:master Feb 13, 2018
k8s-github-robot pushed a commit that referenced this pull request Mar 16, 2018
…9739-upstream-release-1.7

Automatic merge from submit-queue.

Automated cherry pick of #59739

Cherry pick of #59739 on release-1.7.

#59739: use new account generation method for blob disk
k8s-github-robot pushed a commit that referenced this pull request Mar 22, 2018
…9739-upstream-release-1.9

Automatic merge from submit-queue.

Automated cherry pick of #59739: use new account generation method for blob disk

Cherry pick of #59739 on release-1.9.

#59739: use new account generation method for blob disk
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.

fix the error prone account creation method of blob disk
5 participants