-
Notifications
You must be signed in to change notification settings - Fork 39.9k
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
add external resource group support for azure disk #64427
Conversation
resourceGroup, err := getResourceGroupFromDiskURI(diskURI) | ||
if err != nil { | ||
glog.Errorf("azureDisk - getResourceGroupFromDiskURI(%s) returned error: %v", diskURI, err) | ||
resourceGroup = c.common.resourceGroup |
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.
Shouldn't return error here? e.g. if there are disks with same name in different rg, this may delete the wrong disk?
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.
correct, I have incorrect thoughts here, worried about data disk URI format change in the future...
@@ -143,7 +147,11 @@ func (p *azureDiskProvisioner) Provision() (*v1.PersistentVolume, error) { | |||
// create disk | |||
diskURI := "" | |||
if kind == v1.AzureManagedDisk { | |||
diskURI, err = diskController.CreateManagedDisk(name, skuName, requestGB, *(p.options.CloudTags)) | |||
resourceGroup := "" |
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.
nit: default to c.common.resourceGroup
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.
I set the default in diskController.CreateManagedDisk
, mainly it's difficult to get c.common.resourceGroup
in this code level
if rg, found := p.options.PVC.Annotations[PVCAnnotationResourceGroup]; found { | ||
resourceGroup = rg | ||
} | ||
diskURI, err = diskController.CreateManagedDisk(name, skuName, resourceGroup, requestGB, *(p.options.CloudTags)) |
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.
check whether p.options.CloudTags is nil?
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
@@ -131,3 +144,13 @@ func (c *ManagedDiskController) getDisk(diskName string) (string, string, error) | |||
|
|||
return "", "", err | |||
} | |||
|
|||
// get resource group name from a managed disk URI, e.g. return {group-name} according to | |||
// /subscriptions/{sub-id}/resourcegroups/{group-name}/providers/microsoft.compute/disks/{disk-id} |
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.
nit: removing leading spaces
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
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.
@feiskyer PTAL
resourceGroup, err := getResourceGroupFromDiskURI(diskURI) | ||
if err != nil { | ||
glog.Errorf("azureDisk - getResourceGroupFromDiskURI(%s) returned error: %v", diskURI, err) | ||
resourceGroup = c.common.resourceGroup |
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.
correct, I have incorrect thoughts here, worried about data disk URI format change in the future...
@@ -131,3 +144,13 @@ func (c *ManagedDiskController) getDisk(diskName string) (string, string, error) | |||
|
|||
return "", "", err | |||
} | |||
|
|||
// get resource group name from a managed disk URI, e.g. return {group-name} according to | |||
// /subscriptions/{sub-id}/resourcegroups/{group-name}/providers/microsoft.compute/disks/{disk-id} |
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
@@ -143,7 +147,11 @@ func (p *azureDiskProvisioner) Provision() (*v1.PersistentVolume, error) { | |||
// create disk | |||
diskURI := "" | |||
if kind == v1.AzureManagedDisk { | |||
diskURI, err = diskController.CreateManagedDisk(name, skuName, requestGB, *(p.options.CloudTags)) | |||
resourceGroup := "" |
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.
I set the default in diskController.CreateManagedDisk
, mainly it's difficult to get c.common.resourceGroup
in this code level
if rg, found := p.options.PVC.Annotations[PVCAnnotationResourceGroup]; found { | ||
resourceGroup = rg | ||
} | ||
diskURI, err = diskController.CreateManagedDisk(name, skuName, resourceGroup, requestGB, *(p.options.CloudTags)) |
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
/test pull-kubernetes-bazel-test |
/test pull-kubernetes-e2e-kops-aws |
@khenidak do you have any comments on this PR? We are very close to 1.11 release now, I would like to make this PR into v1.11 if there is no other issue. Thanks. |
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
/approve
/retest |
fix naming issue fix comments
Since this is not a critical bug fix, we have missed v1.11 milestone. |
@feiskyer thanks, PTAL anyway |
/test pull-kubernetes-bazel-test |
/test pull-kubernetes-e2e-gce-100-performance |
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
/approve
ctx, cancel := getContextWithCancel() | ||
defer cancel() | ||
_, err := c.common.cloud.DisksClient.CreateOrUpdate(ctx, c.common.resourceGroup, diskName, model) | ||
_, err := c.common.cloud.DisksClient.CreateOrUpdate(ctx, resourceGroup, diskName, model) |
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.
how to ensure this rg can be accessed?
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.
user should ensure current credentials should have access to the rg, otherwise there would be error returned.
func getResourceGroupFromDiskURI(diskURI string) (string, error) { | ||
fields := strings.Split(diskURI, "/") | ||
if len(fields) != 9 { | ||
return "", fmt.Errorf("disk URI(%s) is not expected", diskURI) |
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.
invalid disk URI
if len(fields) != 9 { | ||
return "", fmt.Errorf("disk URI(%s) is not expected", diskURI) | ||
} | ||
return fields[4], nil |
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.
I am paranoid but I would verify if fields[3] == "resourceGroups"
@@ -173,3 +190,13 @@ func (c *ManagedDiskController) ResizeDisk(diskName string, oldSize resource.Qua | |||
|
|||
return newSizeQuant, nil | |||
} | |||
|
|||
// get resource group name from a managed disk URI, e.g. return {group-name} according to | |||
// /subscriptions/{sub-id}/resourcegroups/{group-name}/providers/microsoft.compute/disks/{disk-id} |
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.
be more specific, add link https://docs.microsoft.com/en-us/rest/api/compute/disks/get
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
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.
@rootfs I have addressed your comments, PTAL.
ctx, cancel := getContextWithCancel() | ||
defer cancel() | ||
_, err := c.common.cloud.DisksClient.CreateOrUpdate(ctx, c.common.resourceGroup, diskName, model) | ||
_, err := c.common.cloud.DisksClient.CreateOrUpdate(ctx, resourceGroup, diskName, model) |
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.
user should ensure current credentials should have access to the rg, otherwise there would be error returned.
@@ -173,3 +190,13 @@ func (c *ManagedDiskController) ResizeDisk(diskName string, oldSize resource.Qua | |||
|
|||
return newSizeQuant, nil | |||
} | |||
|
|||
// get resource group name from a managed disk URI, e.g. return {group-name} according to | |||
// /subscriptions/{sub-id}/resourcegroups/{group-name}/providers/microsoft.compute/disks/{disk-id} |
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
/cc @brendandburns |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andyzhangx, feiskyer, rootfs 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 files:
Approvers can indicate their approval by writing |
@andyzhangx can you follow up to update azure disk examples? |
/kind bug |
Automatic merge from submit-queue (batch tested with PRs 65032, 63471, 64104, 64672, 64427). If you want to cherry-pick this change to another branch, please follow the instructions here. |
What this PR does / why we need it:
add external resource group support for azure disk, specify
resourcegroup
in azure disk storage class so that user could specify external resource groupWhich issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #64388
Special notes for your reviewer:
Pls note above config won't change resource group for azure disk forever, next time if user don't specify resource group, only default resource group will be used.
Release note:
/sig azure
/assign @feiskyer @karataliu
/cc @khenidak