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

GCP: Fix uninstaller to not use hardcoded base path. #3702

Merged

Conversation

rna-afk
Copy link
Contributor

@rna-afk rna-afk commented Jun 1, 2020

The uninstaller currently hard codes the base path as the GCP
API base path has changed.

Change 1:
For the getZoneName function, the InstanceGroupAggregatedList,
InstanceAggregatedList and the disk list functions that calls
this to get the proper url all have a shortened URL as the key
in the list.Items map. Example of a shortened URL is
zones/us-central1-a.
Reusing the key value instead of hard coding the base path
and TrimLeft operation.

Change 2:
For the getInstanceGroupURL function, the call to the underlying
InstanceGroupAggregatedList to get the InstanceGroups already have
the URL to hit called the SelfLink which is now set to the returning
object and used for the URL, thus not requiring the call.

Change 3:
For the getInstanceNameAndZone, since the underlying object has only
the URL and no other relevant information, the base path is removed
and the TrimLeft operation is changed to Split based on the '/projects/'
URL query parameter instead of using the base path.

Previous commit information:
11c9773#diff-4781d154886c4da10a007bb219f27d8aL170
TODO: Find a better solution for change 3.

@rna-afk
Copy link
Contributor Author

rna-afk commented Jun 1, 2020

/test e2e-gcp

@rna-afk rna-afk changed the title GCP: Fix uninstaller to not use hardcoded base path. [WIP] GCP: Fix uninstaller to not use hardcoded base path. Jun 1, 2020
@openshift-ci-robot openshift-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 Jun 1, 2020
@rna-afk
Copy link
Contributor Author

rna-afk commented Jun 4, 2020

/test e2e-gcp

@patrickdillon
Copy link
Contributor

@jstuever PTAL when you get a chance. I have spent time trying to review but I think I'm missing too much context to give high-level insight. I don't want to send @rna-afk too far in the wrong direction.

Copy link
Contributor

@jstuever jstuever left a comment

Choose a reason for hiding this comment

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

Just a few recommendations....

@@ -22,7 +22,7 @@ func (o *ClusterUninstaller) listCloudControllerInstanceGroups() ([]cloudResourc
func (o *ClusterUninstaller) listCloudControllerBackendServices(instanceGroups []cloudResource) ([]cloudResource, error) {
urls := sets.NewString()
for _, instanceGroup := range instanceGroups {
urls.Insert(o.getInstanceGroupURL(instanceGroup))
urls.Insert(instanceGroup.url)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is good... please delete the getInstanceGroupURL function definition as well. It doesn't appear to be used after this change.

// TODO: Find a better way to get the instance group URL to account for changes in base path
func (o *ClusterUninstaller) getInstanceGroupURL(ig cloudResource) string {
return fmt.Sprintf("%s%s/zones/%s/instanceGroups/%s", "https://www.googleapis.com/compute/v1/projects/", o.ProjectID, ig.zone, ig.name)
}

for _, item := range scopedList.Disks {
if filterFunc == nil || filterFunc != nil && filterFunc(item) {
zone := o.getZoneName(item.Zone)
zone := strings.Split(key, "/")[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this, let's update getZoneName to split based on /projects/ similar to how you did in instance.go. This allows us to update it in a single place if it changes again in the future.

Split(instanceURL, "/projects/")[1]

func (o *ClusterUninstaller) getZoneName(zoneURL string) string {
path := strings.TrimLeft(zoneURL, "https://www.googleapis.com/compute/v1/projects/")
parts := strings.Split(path, "/")
if len(parts) >= 3 {
return parts[2]
}
return ""
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would split based on /projects/ not cause a problem? I was worried that there might be something else named projects in the URL. That might cause some problems.

Copy link
Contributor

Choose a reason for hiding this comment

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

There might be a risk of that... probably less of a risk with the surrounding slashes. I also notice that the zone name is the last entity in strings.Split(path, "/").... so that might be better here.

parts:=strings.Split(path, "/")
if len(parts) {
  return parts[len(parts)-1]
}

for _, item := range scopedList.Instances {
if filterFunc == nil || filterFunc != nil && filterFunc(item) {
zoneName := o.getZoneName(item.Zone)
zoneName := strings.Split(key, "/")[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

again, update getZoneName instead.

for _, item := range scopedList.InstanceGroups {
if filterFunc == nil || filterFunc != nil && filterFunc(item) {
zoneName := o.getZoneName(item.Zone)
zoneName := strings.Split(key, "/")[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

again, update getZoneName instead.

@rna-afk rna-afk force-pushed the gcp-uninstaller-basepath-fix branch 2 times, most recently from 3281165 to 01b7482 Compare June 8, 2020 12:27
@rna-afk rna-afk changed the title [WIP] GCP: Fix uninstaller to not use hardcoded base path. GCP: Fix uninstaller to not use hardcoded base path. Jun 8, 2020
@openshift-ci-robot openshift-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 Jun 8, 2020
@jstuever
Copy link
Contributor

jstuever commented Jun 8, 2020

/test e2e-gcp

2 similar comments
@rna-afk
Copy link
Contributor Author

rna-afk commented Jun 9, 2020

/test e2e-gcp

@rna-afk
Copy link
Contributor Author

rna-afk commented Jun 10, 2020

/test e2e-gcp

@rna-afk rna-afk force-pushed the gcp-uninstaller-basepath-fix branch 2 times, most recently from 00fd84e to 760d90b Compare June 10, 2020 13:31
The uninstaller currently hard codes the base path as the GCP
API base path has changed.

Change 1:
For the getZoneName function, the InstanceGroupAggregatedList,
InstanceAggregatedList and the disk list functions that calls
this to get the proper url all have a shortened URL as the key
in the list.Items map. Example of a shortened URL is
zones/us-central1-a.
Reusing the key value instead of hard coding the base path
and TrimLeft operation.

Change 2:
For the getInstanceGroupURL function, the call to the underlying
InstanceGroupAggregatedList to get the InstanceGroups already have
the URL to hit called the SelfLink which is now set to the returning
object and used for the URL, thus not requiring the call.

Change 3:
For the getInstanceNameAndZone, since the underlying object has only
the URL and no other relevant information, the base path is removed
and the TrimLeft operation is changed to Split based on the '/projects/'
URL query parameter instead of using the base path.

Previous commit information:
openshift@11c9773#diff-4781d154886c4da10a007bb219f27d8aL170
TODO: Find a better solution for change 3.
@rna-afk rna-afk force-pushed the gcp-uninstaller-basepath-fix branch from 760d90b to 269031f Compare June 10, 2020 13:40
@jstuever
Copy link
Contributor

/test e2e-gcp

1 similar comment
@rna-afk
Copy link
Contributor Author

rna-afk commented Jun 10, 2020

/test e2e-gcp

@jstuever
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 11, 2020
@jstuever
Copy link
Contributor

/approve

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jstuever

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 11, 2020
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

21 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 8d1ebc1 into openshift:master Jun 12, 2020
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants