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

add external resource group support for azure disk #64427

Merged
merged 3 commits into from Jun 20, 2018

Conversation

andyzhangx
Copy link
Member

@andyzhangx andyzhangx commented May 29, 2018

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 group

  • without this PR, user could only create dynamic azure disk in the same resource group as cluster
  • with this PR, user could specify external resource group in PVC:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: hdd
provisioner: kubernetes.io/azure-disk
parameters:
  skuname: Standard_LRS
  kind: managed
  cachingmode: None
  resourcegroup: RESOURCE_GROUP_NAME

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

add external resource group support for azure disk

/sig azure
/assign @feiskyer @karataliu
/cc @khenidak

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label May 29, 2018
@k8s-ci-robot k8s-ci-robot added 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 May 29, 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 May 29, 2018
resourceGroup, err := getResourceGroupFromDiskURI(diskURI)
if err != nil {
glog.Errorf("azureDisk - getResourceGroupFromDiskURI(%s) returned error: %v", diskURI, err)
resourceGroup = c.common.resourceGroup
Copy link
Member

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?

Copy link
Member Author

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 := ""
Copy link
Member

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

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 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))
Copy link
Member

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?

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

@@ -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}
Copy link
Member

Choose a reason for hiding this comment

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

nit: removing leading spaces

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

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.

@feiskyer PTAL

resourceGroup, err := getResourceGroupFromDiskURI(diskURI)
if err != nil {
glog.Errorf("azureDisk - getResourceGroupFromDiskURI(%s) returned error: %v", diskURI, err)
resourceGroup = c.common.resourceGroup
Copy link
Member Author

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}
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

@@ -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 := ""
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 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))
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

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-bazel-test
/test pull-kubernetes-e2e-gce-100-performance
/test pull-kubernetes-e2e-kops-aws
/test pull-kubernetes-integration

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-e2e-kops-aws

@andyzhangx
Copy link
Member Author

@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.

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
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 4, 2018
@feiskyer
Copy link
Member

feiskyer commented Jun 4, 2018

/retest

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 6, 2018
@andyzhangx
Copy link
Member Author

@feiskyer PTAL, and is it still possible to make this PR into v1.11?
rebased and specify external resource group in ResizeDisk, you may only need to look at this commit:
f6ffdaa

@feiskyer
Copy link
Member

feiskyer commented Jun 6, 2018

Since this is not a critical bug fix, we have missed v1.11 milestone.

@andyzhangx
Copy link
Member Author

@feiskyer thanks, PTAL anyway

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-bazel-test

@andyzhangx
Copy link
Member Author

/test pull-kubernetes-e2e-gce-100-performance
/test pull-kubernetes-e2e-gce-device-plugin-gpu

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 7, 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
/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)
Copy link
Contributor

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?

Copy link
Member Author

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)
Copy link
Contributor

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
Copy link
Contributor

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}
Copy link
Contributor

Choose a reason for hiding this comment

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

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

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 19, 2018
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.

@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)
Copy link
Member Author

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}
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
Copy link
Member

/cc @brendandburns

@rootfs
Copy link
Contributor

rootfs commented Jun 19, 2018

/lgtm

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

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rootfs
Copy link
Contributor

rootfs commented Jun 19, 2018

@andyzhangx can you follow up to update azure disk examples?

@andyzhangx
Copy link
Member Author

/kind bug

@k8s-github-robot
Copy link

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.

@k8s-github-robot k8s-github-robot merged commit 3f581dc into kubernetes:master Jun 20, 2018
k8s-github-robot pushed a commit that referenced this pull request Jun 23, 2018
…4427-upstream-release-1.8

Automatic merge from submit-queue.

Automated cherry pick of #64427: add external resource group support for azure disk

Cherry pick of #64427 on release-1.8.

#64427: add external resource group support for azure disk
k8s-github-robot pushed a commit that referenced this pull request Jul 4, 2018
…4427-upstream-release-1.10

Automatic merge from submit-queue.

Automated cherry pick of #64427: add external resource group support for azure disk

Cherry pick of #64427 on release-1.10.

#64427: add external resource group support for azure disk
k8s-github-robot pushed a commit that referenced this pull request Jul 10, 2018
…4427-upstream-release-1.11

Automatic merge from submit-queue.

Automated cherry pick of #64427: add external resource group support for azure disk

Cherry pick of #64427 on release-1.11.

#64427: add external resource group support for azure disk
k8s-github-robot pushed a commit that referenced this pull request Aug 10, 2018
…4427-upstream-release-1.9

Automatic merge from submit-queue.

Automated cherry pick of #64427: add external resource group support for azure disk

Cherry pick of #64427 on release-1.9.

#64427: add external resource group support for azure 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

specify resource group for azure disk PVC dynamic creation
8 participants