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

CRDValidationRatcheting: Factor object correlation and comparison into reusable component #121118

Conversation

alexzielenski
Copy link
Contributor

@alexzielenski alexzielenski commented Oct 10, 2023

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

CachedDeepEqual is needed for #121016 to use with the CEL validator. It will also be neeed for native types in declarative validation. This PR factors out the object correlation and comparison tree into a re-usable component. At validation time the instance can be shared by all validation passes.

Tried to keep all commits semantically a no-op

Which issue(s) this PR fixes:

N/A

Special notes for your reviewer:

/assign @apelisse
/sig api-machinery

Does this PR introduce a user-facing change?

NONE

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

- [KEP]: https://kep.k8s.io/4008

Alexander Zielenski added 6 commits October 10, 2023 09:48
inlineValidator unnecessary, since we already have access to the `new` object
so it is reusable by CEL validators
going to be used from CEL validator too
for reuseability with CEL structural schema impl
@k8s-ci-robot k8s-ci-robot added the release-note-none Denotes a PR that doesn't merit a release note. label Oct 10, 2023
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 10, 2023
@jiahuif
Copy link
Member

jiahuif commented Oct 10, 2023

/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 10, 2023
Copy link
Member

@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.

Thanks! I don't see a lot of tests throughout, maybe they didn't need to be updated, if so that's great!

@alexzielenski alexzielenski force-pushed the apiserver/apiextensions/ratcheting-factor-correlation branch from b7b93de to 92158e0 Compare October 11, 2023 19:19
Alexander Zielenski added 3 commits October 11, 2023 14:30
before it required running validation first, now it builds the tree as needed
no changes except package naming
@alexzielenski alexzielenski force-pushed the apiserver/apiextensions/ratcheting-factor-correlation branch from be95cb9 to e129fb6 Compare October 11, 2023 21:31
@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 11, 2023
@alexzielenski alexzielenski force-pushed the apiserver/apiextensions/ratcheting-factor-correlation branch from e129fb6 to 1103e23 Compare October 11, 2023 22:26
@apelisse
Copy link
Member

/lgtm
/approve
/retest

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

LGTM label has been added.

Git tree hash: 243cf219e4927f96da3939517d6e4e1f64f3383b

@alexzielenski
Copy link
Contributor Author

/assign jpbetz

Copy link
Contributor

@jpbetz jpbetz left a comment

Choose a reason for hiding this comment

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

Nothing major, just some godoc suggestions and switch handling suggestions.

// Atomic lists are not correlatable by item
// Ratcheting is not available on a per-index basis
return nil
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

label this as case "granular" since that is what it's for and leave a default with panic as the fall-through if somehow this function ever receives a list type we don't expect?

Copy link
Contributor Author

@alexzielenski alexzielenski Oct 13, 2023

Choose a reason for hiding this comment

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

@apelisse pointed out the default list type was atomic, so this default case treating it as granular may be a bug. (I don't believe we have granular lists)

This was also pointed out by @apelisse when the code originally went in last release, but we decided to punt whether we should treat list items as granular for the purposes of DeepEqual comparison in ratcheting.

On one hand it'd be nice to allow users to do a point modification on a single element with ratcheting. On the other hand, there would be no CEL escape hatch for schemas that want to opt out of that behavior, and it'd be weird to allow point modification without allowing adding/removing.

Given the inconsistency and the low perceived benefit. I think we should drop support for ratcheting uncorrelatable array items in beta. (i.e. only map-type is ratchetable. Same as CEL). WDYT @apelisse @jpbetz ?

Copy link
Member

Choose a reason for hiding this comment

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

only map-type is ratchetable. Same as CEL

That's the way to go. You can't correlate atomic, and it's either atomic or map-type/set. Mapping by index doesn't really make sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm okay with deferring ratcheting on listType=atomic. I see the main benefits being cases where we're working on values nested under a listType=map.

Good catch on the default=atomic BTW. We should strive to always structure switch statements to reflect that.

Copy link
Contributor Author

@alexzielenski alexzielenski Oct 13, 2023

Choose a reason for hiding this comment

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

added case for "" to be equivalent with atomic, disallowed default case ratcheting, and updated tests

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

Updated with latest feedback. @apelisse PTAL

Copy link
Member

@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.

/lgtm

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

LGTM label has been added.

Git tree hash: 36e85dbd304de1c8900d6d9818e7a162cc7d500a

@jpbetz
Copy link
Contributor

jpbetz commented Oct 16, 2023

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexzielenski, apelisse, jpbetz

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 16, 2023
@k8s-ci-robot k8s-ci-robot merged commit 3a3dc87 into kubernetes:master Oct 16, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.29 milestone Oct 16, 2023
k8s-publishing-bot pushed a commit to kubernetes/apiserver that referenced this pull request Oct 17, 2023
discussion: kubernetes/kubernetes#121118 (comment)

Kubernetes-commit: fb1fc8b4a72758688d1251278579b2b0ac666fc7
k8s-publishing-bot pushed a commit to kubernetes/apiextensions-apiserver that referenced this pull request Oct 17, 2023
discussion: kubernetes/kubernetes#121118 (comment)

Kubernetes-commit: fb1fc8b4a72758688d1251278579b2b0ac666fc7
Sharpz7 pushed a commit to Sharpz7/kubernetes that referenced this pull request Oct 27, 2023
richabanker pushed a commit to richabanker/kubernetes that referenced this pull request Jan 9, 2024
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/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. 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
None yet
Development

Successfully merging this pull request may close these issues.

5 participants