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

Determine namespaceability of resources from openapi schema #2978

Merged

Conversation

mortent
Copy link
Member

@mortent mortent commented Sep 12, 2020

This uses the openapi schema to determine whether a resource is namespace-scoped or cluster-scoped as described here.
Since up until now the openapi schema that was included in kpt was not complete, but only included type definitions, I had to update the openapi schema. It is still based on kubernetes version 1.17.
This only makes the logic available in kyaml, it does not update kustomize to use it.

Ref: #2861

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 12, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mortent

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 12, 2020
@mortent mortent requested review from monopole and apelisse and removed request for Liujingfang1 September 12, 2020 22:09
Copy link

@apelisse apelisse left a comment

Choose a reason for hiding this comment

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

I think that's good. I don't know what is the best way to detect it from there looking for parameter vs string pattern. You could build a test that walks through all of them and compares?

continue
}

if strings.Contains(path, "namespaces/{namespace}") {

Choose a reason for hiding this comment

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

Yeah, you have two options:

  1. Look for that specific pattern in the path, or
  2. A path parameter like this:
"in": "path",
"name": "namespace",
"required": true,
"type": "string",
  1. Or both.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think both approaches should work equally well. The only tricky part is that even namespaced resources will have some paths that doesn't include the namespace path parameter (like /apis/apps/v1/deployments). But the code does account for this.

Choose a reason for hiding this comment

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

Right, that's fine! If you feel confident that this is good enough, go for it!
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 15, 2020
@k8s-ci-robot k8s-ci-robot merged commit 00f0fd7 into kubernetes-sigs:master Sep 15, 2020
@mortent mortent deleted the NamespaceabilityFromSchema branch July 23, 2021 02:06
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants