-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Simplify handling of cluster URIs from kubeconfig #8499
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
Conversation
Thanks for following up @vasiliy-ul ! |
👌 ... Still, let's see if the CI tests pass. I also found a couple more places where complex cluster URIs were not handled. Fixed those as well. |
@mlhnono68, FYI. Maybe you could also take a look here? Unfortunately, I do not have a Rancher cluster to test e2e. Though I checked the resulting request URIs with different kubeconfig's and the path is preserved. |
/retest-required |
/approve |
@@ -65,7 +65,7 @@ var _ = Describe("Kubevirt Version Client", func() { | |||
ghttp.RespondWithJSONEncoded(http.StatusOK, groupInfo), | |||
), | |||
ghttp.CombineHandlers( | |||
ghttp.VerifyRequest("GET", "/apis/"+groupInfo.PreferredVersion.GroupVersion+"/version"), | |||
ghttp.VerifyRequest("GET", "/apis"+groupInfo.PreferredVersion.GroupVersion+"/version"), |
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 come we don't need this "/"?
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.
Yeah, looks a bit weird. It appears that we use /apis//apis/subresources.kubevirt.io/v1alpha3/version
uri (with //
):
kubevirt/staging/src/kubevirt.io/client-go/kubecli/version.go
Lines 79 to 83 in 0f2c671
// Now, query the preferred version | |
uri = fmt.Sprintf("%s/apis/%s/version", u.Path, group.PreferredVersion.GroupVersion) | |
var serverInfo version.Info | |
result = v.restClient.Get().RequestURI(uri).Do(context.Background()) |
Here group.PreferredVersion.GroupVersion
already contains a leading /
(potentially we can fix also the format if it makes sense).
Previously, it was passed to the RequestURI
method, which under the hood calls url.Parse(uri)
. This one preserves the path as-is with //
. Hence, we needed this extra /
in the test.
With this patch, the uri is now passed to AbsPath
, which does path.Join(..., uri)
. It looks like this join sanitizes the resulting path and the output has only a single /
.
Simple reproducer: https://go.dev/play/p/IU80SS_Gj5v
Join joins any number of path elements into a single path, separating them with slashes. Empty elements are ignored. The result is Cleaned. However, if the argument list is empty or all its elements are empty, Join returns an empty string.
I was thinking more in the direction of unit-testing. Even if we manage to setup a proxy in CI and to use a custom config, still calling all the APIs e2e will require a significant amount of effort and resources. |
Agree. I was thinking about discovery & dry-run but I think unit-tests are enough too. |
Added unit tests in a separate commit. Basically, I used the existing tests for regular URIs and transformed them to tables parametrized with an additional path element. |
/test pull-kubevirt-e2e-k8s-1.23-sig-compute-nonroot |
f007747
to
88a42cb
Compare
Added more unit-tests. No functional changes. |
Handling of cluster URIs with additional path elements added in the commit fba65ed can be simplified with the use of Request.AbsPath which literally does the same as the introduced adaptUriForHostPath function. Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
E.g. https://rancher-url/k8s/clusters/c-m-someid Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
88a42cb
to
e9c7c65
Compare
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.
/approve
@rmohr Can you take a look, please?
|
||
result := v.restClient.Get().RequestURI(uri).Do(context.Background()) | ||
uri := ApiGroupName | ||
result := v.restClient.Get().AbsPath(uri).Do(context.Background()) |
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: You can inline the uri
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: xpivarc 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 |
/cc @fossedihelm Would you be able to have a look? |
@xpivarc sure |
Thanks! |
/retest-required |
1 similar comment
/retest-required |
/retest-required |
@vasiliy-ul: The following test failed, say
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. I understand the commands that are listed here. |
/retest-required |
What this PR does / why we need it:
Handling of cluster URIs with additional path elements added in the commit fba65ed can be simplified with the use of
Request.AbsPath
kubevirt/vendor/k8s.io/client-go/rest/request.go
Lines 305 to 317 in 0f2c671
which literally does the same as the introduced
adaptUriForHostPath
function:kubevirt/staging/src/kubevirt.io/client-go/kubecli/vmi.go
Lines 177 to 183 in 0f2c671
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 #
Special notes for your reviewer:
This is a follow-up of the discussion #8129 (comment)
Release note: