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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fix parsing of requests to root path of a workload cluster #2405

Conversation

erwinvaneyk
Copy link
Contributor

@erwinvaneyk erwinvaneyk commented Nov 24, 2022

Summary

kcp is rejecting (valid) calls to the root path of a cluster. With a default setup, the following error is returned:

# with KUBECONFIG pointing to some workload cluster within kcp
$ kubectl get --raw='/'
[{
  "metadata": {},
  "status": "Failure",
  "message": "unable to parse cluster: no `/` found in path root",
  "reason": "BadRequest",
  "code": 400
}]

This PR resolves this issue by fixing the parsing and removing the error. With this fix:

# with KUBECONFIG pointing to some workload cluster within kcp
$ kubectl get --raw='/'
{
  "paths": [
    "/api",
    "/api/v1",
    "/apis",
    "/apis/",
    "/apis/admissionregistration.k8s.io",
    "/apis/admissionregistration.k8s.io/v1",
    "/apis/apiextensions.k8s.io",
    ...
  ]
}

@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 24, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 24, 2022

Hi @erwinvaneyk. Thanks for your PR.

I'm waiting for a kcp-dev 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.

@ncdc
Copy link
Member

ncdc commented Nov 29, 2022

I think it may make sense to support /, /healthz, and /readyz, but we shouldn't expose /api and /apis at the root.

@erwinvaneyk
Copy link
Contributor Author

erwinvaneyk commented Nov 30, 2022

@ncdc Maybe I could have worded the title a bit better, but this PR solely fixes requests to the root path (/) of a workload cluster. So an endpoint like this: $HOST/apis/clusters/my-cluster/. it doesn't change anything at the root path of kcp itself

@erwinvaneyk erwinvaneyk changed the title 馃悰 Fix parsing of requests to root path 馃悰 Fix parsing of requests to root path of a workload cluster Nov 30, 2022
@ncdc
Copy link
Member

ncdc commented Nov 30, 2022

Ahh ok, thanks for clarifying. I got confused from the description, because kubectl get --raw='/' ignores any path in the kubeconfig's server and literally requests /, which we don't allow. I thought you were changing that.

I do now see what your PR is doing, and it's 馃憤:

Before:

k --user shard-admin get --raw /clusters/root
Error from server (BadRequest): unable to parse cluster: no `/` found in path root

After:

k --user shard-admin get --raw /clusters/root
{
  "paths": [
    "/api",
    "/api/v1",
    "/apis",
    "/apis/",
    "/apis/admissionregistration.k8s.io",
...

@ncdc
Copy link
Member

ncdc commented Nov 30, 2022

Some additional testing:

# get /clusters
Error from server (NotFound): the server could not find the requested resource

# get /clusters/
Error from server (InternalError): an error on the server ("cluster name is empty in the request context - RequestInfo: &request.RequestInfo{IsResourceRequest:false, Path:\"/\", Verb:\"get\", APIPrefix:\"\", APIGroup:\"\", APIVersion:\"\", Namespace:\"\", Resource:\"\", Subresource:\"\", Name:\"\", Parts:[]string(nil)}") has prevented the request from succeeding

I think the error for /clusters is good. Should we fix /clusters/ to also return a NotFound?

@stevekuznetsov do you want an e2e for this/these to make sure we don't regress?

@ncdc
Copy link
Member

ncdc commented Dec 1, 2022

@erwinvaneyk would you be able to fix /clusters/ too and also add a small e2e?

@vincepri
Copy link
Contributor

/lgtm

I'll follow-up with some fixes

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 14, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 14, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ncdc

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 openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 14, 2022
@ncdc
Copy link
Member

ncdc commented Dec 14, 2022

/ok-to-test

@openshift-ci openshift-ci bot 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 Dec 14, 2022
@vincepri
Copy link
Contributor

/retest

@openshift-merge-robot openshift-merge-robot merged commit 70ce15f into kcp-dev:main Dec 14, 2022
@erwinvaneyk erwinvaneyk deleted the private/main/erwinvaneyk/fix-root-path-parsing branch December 14, 2022 20:21
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants