-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
fix the error prone account creation method of blob disk #59739
Conversation
There was a problem hiding this 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!strings.HasPrefix better
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
070c4a4
to
3f7f9b3
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
07773fb
to
da22599
Compare
@karataliu now below are the prefix nameing:
|
be22aaf
to
21f7e69
Compare
@karataliu I added a new common func |
@@ -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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also strings.HasPrefix ?
There was a problem hiding this comment.
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
21f7e69
to
8a7198b
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[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 |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here. |
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:
/assign @karataliu
/sig azure