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
GCP: Fix uninstaller to not use hardcoded base path. #3702
Conversation
/test e2e-gcp |
/test e2e-gcp |
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 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) |
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 good... please delete the getInstanceGroupURL function definition as well. It doesn't appear to be used after this change.
installer/pkg/destroy/gcp/gcp.go
Lines 186 to 189 in a7f8c8d
// 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) | |
} |
pkg/destroy/gcp/disk.go
Outdated
for _, item := range scopedList.Disks { | ||
if filterFunc == nil || filterFunc != nil && filterFunc(item) { | ||
zone := o.getZoneName(item.Zone) | ||
zone := strings.Split(key, "/")[1] |
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.
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]
installer/pkg/destroy/gcp/gcp.go
Lines 168 to 175 in a7f8c8d
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 "" | |
} |
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.
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.
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.
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]
}
pkg/destroy/gcp/instance.go
Outdated
for _, item := range scopedList.Instances { | ||
if filterFunc == nil || filterFunc != nil && filterFunc(item) { | ||
zoneName := o.getZoneName(item.Zone) | ||
zoneName := strings.Split(key, "/")[1] |
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.
again, update getZoneName instead.
pkg/destroy/gcp/instancegroup.go
Outdated
for _, item := range scopedList.InstanceGroups { | ||
if filterFunc == nil || filterFunc != nil && filterFunc(item) { | ||
zoneName := o.getZoneName(item.Zone) | ||
zoneName := strings.Split(key, "/")[1] |
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.
again, update getZoneName instead.
3281165
to
01b7482
Compare
/test e2e-gcp |
2 similar comments
/test e2e-gcp |
/test e2e-gcp |
00fd84e
to
760d90b
Compare
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.
760d90b
to
269031f
Compare
/test e2e-gcp |
1 similar comment
/test e2e-gcp |
/lgtm |
/approve |
[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 |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
21 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
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.