-
Notifications
You must be signed in to change notification settings - Fork 423
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
🐛 Fix XValidations flattening #998
🐛 Fix XValidations flattening #998
Conversation
Welcome @cezarsa! |
Hi @cezarsa. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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-sigs/prow repository. |
/ok-to-test |
Do we need to consider the ordering in flattening? CRD validations are executed in order so do we think the field level validations or the struct level validations should come first? What will happen with this approach, I assume the output here is deterministic? |
It is deterministic and, with the current approach, struct-level validations will come first. This kinda makes sense to me but I don't have a definitive answer if this is the intended behavior or if this has been discussed before. Ultimately, I don't think the order can affect the correctness or the cost budget for the validations as they are all executed even after a failed rule. |
Is that true? I was under the impression that if a rule failed, further rules were not executed until the earlier rule passed? Either way, I guess that doesn't hugely matter since all rules must pass for the object to be accepted. I would be tempted to poke some of the API machinery folks though just in case they can foresee any issues here/have a suggestion for prioritisation |
Yes, I just tested it to be sure, using controller-gen from this branch and with an object declared as:
Applying it returned all the validation errors:
|
I think for cost estimation / compile checks at CRD create/update all rules are compiled and afterwards error messages are produced accordingly: https://github.com/kubernetes/kubernetes/blob/d081fd56a2aba4663f11dd5e27dbcf64c0ec6638/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go#L1226 During CR create/update:
@cezarsa @JoelSpeed WDYT? does that make sense? (feel free to cc someone from api-machinery, not sure who :)) |
7e435ac
to
4361106
Compare
Having
|
kubernetes/kubernetes#124381 was merged into master quite recently. Does it resolve this problem? |
Hey @jpbetz, thanks I wasn't aware of that PR but apparently it doesn't solve the problem.
The test above tries to apply a CRD with
|
pkg/crd/flatten.go
Outdated
@@ -147,6 +147,8 @@ func flattenAllOfInto(dst *apiext.JSONSchemaProps, src apiext.JSONSchemaProps, e | |||
dstField.Set(srcField) | |||
case "XMapType": | |||
dstField.Set(srcField) | |||
case "XValidations": | |||
dstField.Set(reflect.AppendSlice(dstField, srcField)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would flip the order here. I think it's better if the validation from the field is before the ones from the type.
Basically this allows to add validations add the start of the validation array when importing external types (~ that would prioritize "local" validations over imported ones)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Order flipped in 43d3d3a.
@cezarsa Sorry for the delay. Last comment from my side: #998 (comment) I think even if the current output would be somehow valid (which it doesn't seem to be), it still makes sense to flatten in this case |
/ok-to-test |
Thank you very much! /lgtm |
LGTM label has been added. Git tree hash: 41fdb218319688b4ade7972c98782bd6a77b78d0
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cezarsa, sbueringer 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 |
Fixes #997
This PR ensures XValidations are merged correctly when flattening the CRD schema.