Skip to content

fix: volumeID is incorrent when project name contains alpha/beta/v1 #1303

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

Closed
wants to merge 1 commit into from

Conversation

hoozecn
Copy link

@hoozecn hoozecn commented Jul 20, 2023

What type of PR is this?
/kind bug

Which issue(s) this PR fixes:

Fixes #1302

Does this PR introduce a user-facing change:

Fix: AttachVolume.Attach failed when name of gcp project ends with beta

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 20, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @hoozecn!

It looks like this is your first PR to kubernetes-sigs/gcp-compute-persistent-disk-csi-driver 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/gcp-compute-persistent-disk-csi-driver has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 20, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @hoozecn. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 20, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hoozecn
Once this PR has been reviewed and has the lgtm label, please assign leiyiz for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 20, 2023
@hoozecn hoozecn marked this pull request as draft July 20, 2023 14:04
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 20, 2023
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 20, 2023
@hoozecn hoozecn marked this pull request as ready for review July 20, 2023 14:19
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 20, 2023
@k8s-ci-robot k8s-ci-robot requested a review from msau42 July 20, 2023 14:19
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 20, 2023
@mattcary
Copy link
Contributor

/ok-to-test

Awesome great find. I'll take a look.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 20, 2023
@mattcary
Copy link
Contributor

Can we use net/url to parse the url for real? That will save us the next oops-regexps-are-hard error.

I think log along the lines of the following should be right?

url =url.Parse(selfLink)
if url.Scheme != http return selflink
if url.Host !~ www.*apis.com return selflink
elts := strings.Split(url.path)
if len(elts) > 0 && elts[0] =~ vi|beta|alpha return strings.Join(elts[1:], "/")

If you don't want to make this change I'll do it.

Thanks again for finding this!

@mattcary
Copy link
Contributor

mattcary commented Jul 20, 2023

hmm, my pseudocode isn't quite right as the link looks like https://www.googleapis.com/compute/v1/projects/mattcary-gke-dev3/zones/us-central1-a/disks/pvc-6d2dd754-cd70-48c8-9944-ddfa40608585, so the "compute" needs to be removed as well.

Let me back up. Other places assume the volume id is projects/PPP/zones/ZZZ/disks/NNN (or perhaps projects/PPP/region/RRR/disks/NNN). Maybe it's best to extract that rather than trying to fiddle around with the prefix.

I need to audit where else this cleanSelfLink is used, it's possible it's overloaded.

@mattcary
Copy link
Contributor

Hmm, after looking over the code, "cleanSelfLink" is just a really poor way to do what it's trying to do. Let me do a slightly larger refactor instead.

@@ -3304,6 +3304,16 @@ func TestCleanSelfLink(t *testing.T) {
in: "https://www.partnerapis.com/compute/alpha/projects/project/zones/zone/disks/disk",
want: "projects/project/zones/zone/disks/disk",
},
{
name: "project name contains keyword",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we specify the key word in the test name instead of using 1 and 2? :)

@sunnylovestiramisu
Copy link
Contributor

We can probably refer to the existing regex validation from the GCE side for this string?

@sunnylovestiramisu
Copy link
Contributor

Sorry clicked close by mistake

@mattcary
Copy link
Contributor

I think that #1304 is preferable to this---it has a better chance of fixing the next error we haven't thought of yet :-)

It's still running through the integration tests, which confirm if my idea to parse very strictly is okay.

@hoozecn
Copy link
Author

hoozecn commented Jul 21, 2023

cool. lgtm. closing this one. when would it could be applied to the gke? or is there a maual way to to patch the cluster that i already created? dont want to create another project frankly speaking

I think that #1304 is preferable to this---it has a better chance of fixing the next error we haven't thought of yet :-)

It's still running through the integration tests, which confirm if my idea to parse very strictly is okay.

/

@hoozecn hoozecn closed this Jul 21, 2023
@hoozecn hoozecn deleted the fix-volume-id branch July 21, 2023 01:58
@mattcary
Copy link
Contributor

We should be able to start pushing this out next week, it will take a couple weeks to go out. We should be able to backport to all affected versions. I'll update the timing here (but please ping if I forget).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VolumeID is incorrect when project name contains beta
4 participants