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

Use OpenAPI V3 for client side SMP #120707

Merged
merged 4 commits into from Oct 31, 2023
Merged

Conversation

Jefftree
Copy link
Member

What type of PR is this?

/kind feature

What this PR does / why we need it:

Use OpenAPI V3 for client side apply

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Client-side apply will use OpenAPI V3 by default

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubectl sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 15, 2023

// TODO: GVK parser should be moved elsewhere
// Is this duplicated somewhere?
func gvkMatches(targetGVK schema.GroupVersionKind, ext spec.Extensions) bool {
Copy link
Member

Choose a reason for hiding this comment

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

There's a strong possibility that Alex has already written a piece of code to do that, I also suspect maybe sean has written a layer that goes on top of the OpenAPI client to find the object directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

I saw Sean's snippet in query params verifier v3. It's really concise and I'm going to opt to duplicate it because patch requires checking for two different kinds of gvks. Schemas can have a list of gvks while the patch endpoint can only have a single gvk.

Comment on lines 127 to 142
if gvkSupported, _ := p.gvkSupportsPatchOpenAPIV3(p.Mapping.GroupVersionKind); gvkSupported {
patch, err = p.buildStrategicMergePatchFromOpenAPIV3(original, modified, current)
Copy link
Member

Choose a reason for hiding this comment

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

it seems like these two things are running together yet they have a lot of common code? Can we actually return the PatchMeta if we find one?

Copy link
Member Author

Choose a reason for hiding this comment

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

I like keeping the two separate because they look at different components of the OpenAPI. gvkSupportsPatchOpenAPIV3 looks at the PATCH verb for a resource path (does not look at schema at all) while buildStrategicMergePatchFromOpenAPIV3 looks at Component definitions and traverses the schema resource.

staging/src/k8s.io/kubectl/pkg/cmd/apply/patcher.go Outdated Show resolved Hide resolved
if ext == nil {
return false
}
f, ok := ext["x-kubernetes-group-version-kind"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a constant somewhere for this string (x-kubernetes-group-version-kind)?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is in util/openapi in kubectl but that's coupled with OpenAPI V2 and I was hoping we can keep OpenAPI V2 and V3 coupling to a minimum. I declared a constant in this file instead.

Copy link
Contributor

@seans3 seans3 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 this approach looks good. I would hope for more kubectl tests.

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 24, 2023
@Jefftree
Copy link
Member Author

@seans3 I added kubectl testing by extending the existing apply tests and showing that OpenAPI V3 produces the same result. Let me know if there are other cases you'd like to see.

@Jefftree Jefftree changed the title [WIP] Use OpenAPI V3 for client side SMP Use OpenAPI V3 for client side SMP Oct 24, 2023
@k8s-ci-robot k8s-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 Oct 24, 2023
@Jefftree
Copy link
Member Author

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 24, 2023
@apelisse
Copy link
Member

How would we disable the feature if this doesn't work though? Like if openapi v3 generates the wrong patch, is there a way to revert back to v2?

@Jefftree Jefftree force-pushed the csa-openapiv3 branch 2 times, most recently from fa5150b to 1b78deb Compare October 25, 2023 19:52
@apelisse
Copy link
Member

Only minor nits, feel free to push back.

@Jefftree Jefftree force-pushed the csa-openapiv3 branch 5 times, most recently from 363e417 to 3b44bdd Compare October 31, 2023 16:42
@Jefftree
Copy link
Member Author

I'll send a follow up PR to for linter hints since it involves changing invocations of existing tests. It's a non blocking CI.

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Oct 31, 2023

@Jefftree: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-linter-hints eb32969 link false /test pull-kubernetes-linter-hints
pull-kubernetes-verify-lint eb32969 link false /test pull-kubernetes-verify-lint

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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.

@apelisse
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 31, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 045d3242f41da2d99c5b92e9bf31da352b9bb1d9

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apelisse, Jefftree

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 Oct 31, 2023
@k8s-ci-robot k8s-ci-robot merged commit 07d2da7 into kubernetes:master Oct 31, 2023
11 of 14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.29 milestone Oct 31, 2023
@Jefftree Jefftree deleted the csa-openapiv3 branch January 25, 2024 22:22
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. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants