-
Notifications
You must be signed in to change notification settings - Fork 41k
Fix IntOrString cost estimation when schema has a MaxLength constraint #132837
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
base: master
Are you sure you want to change the base?
Fix IntOrString cost estimation when schema has a MaxLength constraint #132837
Conversation
/test all |
/triage accepted @JoelSpeed Hi Joel. Thanks for the contribution. Please remember to add unit tests to prove that the bug is fixed. Thanks. |
@seans3 Have added a unit in the most appropriate place I could find (trying to add one close to the change, where thye don't exist, was creating import cycles trying to get interfaces to line up) |
/assign @jpbetz I'll need your approval to cover both the fix and test update here |
52b3343
to
ddaec51
Compare
/assign @cici37 |
Thanks for the fix! The fix looks good to me. If you could add a test into the estimated cost test cases, that will be awesome (Just to verify the estimated cost calculation respect the maxLength set. And it should fail before the PR changes added^^ |
Fixes #132370 |
@cici37: GitHub didn't allow me to request PR reviews from the following users: lalitc375. Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
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-sigs/prow repository. |
ddaec51
to
b8d74e7
Compare
/test unit Error appears to be completely unrelated |
@JoelSpeed: The specified target(s) for
The following commands are available to trigger optional jobs:
Use
In response to this:
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-sigs/prow repository. |
/test pull-kubernetes-unit |
@cici37 I've added the test case you requested |
Thank you for the fix! |
LGTM label has been added. Git tree hash: 0ce27de7978691ed49692bc2861db4752d465d18
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: cici37, JoelSpeed The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
What this PR does / why we need it:
This updates the way that the maximum size of an IntOrString is calculated in the CEL cost estimator to take into account an openapi maxlength constraint.
I was working with someone on a field like:
We then started adding some CEL rules, for example,
The API server started to complain of high validation costs. Typically this is because the unbounded string length results in a high
MaxElements
in the cost estimates.The usual fix would be to add a maximum length, for example:
But this doesn't work initially because of the way controller-gen is applying different parts of the schema, adding
Allows it to produce the following schema:
We then noticed that the cost estimates were still particularly high. It turns out, that the logic handling any
XIntOrString
field isn't correctly observing theMaxLength
.As far as I can tell, the above is a valid schema and the API server appears to accept this schema, and enforce the maximum string length (note int64 has a maximum length of 19 so the integer max length should be covered by this case too, though CELs cost estimates for integers doesn't set a max elements AFAICT)
This PR updates the logic to take into account the max length and resolves our issue.
Which issue(s) this PR is related to:
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: