-
Couldn't load subscription status.
- Fork 459
🐛 Prevent XValidation duplication by verifying if the rule already exists #1296
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: main
Are you sure you want to change the base?
🐛 Prevent XValidation duplication by verifying if the rule already exists #1296
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mcbenjemaa 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 |
|
/ok-to-test |
|
I'm not convinced that deduplication is the correct fix for this issue. Clearly we are running the ApplyToSchema twice on this XValidation rule, but why? We should only be applying once I'm also curious how this issue has only just cropped up. I've checked our APIs and we have plenty of XValidations, none of which have been duplicated. I think this needs some deeper root cause analysis before we can propose a fix |
The issue happens when XValidation rule is applied on the type level, and used twice or more within the spec. that's my conclusion until now. but I agree it would be great if we can find a better solution that prevent the XValidation.ApplyToSchema run twice on the same Type. |
Deep AnalyseI did another analysis: The issue seems to happen when a pointer type aliases with validation markers (like type MTU *uint64) cause duplication, while struct types and primitive types don't. A Pointer type alias, is processed through whereas struct types gets processed differently through Lastly, for primitive types it gets handled by The shared cached schema is returned from the schema fetcher controller-tools/pkg/crd/parser.go Line 179 in bf7d6b7
Proposed fix:The fix should be in the schema fetcher to deep copy the schema when returning it, ensuring each field gets its own copy: parser.go#197 return props.DeepCopy()This will prevent the duplication issue root cause. /cc @JoelSpeed @sbueringer |
Yes, providing a new instance of the schema from the cache as a deepcopy seems like a good fix after reviewing your notes. Thanks for taking the time to go deeper on this! |
Analyse:
When defining a custom type and applying a cel expression on the type level, and if you reuse the same type twice or more in the spec, the XValidation will be duplicated, which causes errors in patching the CRDs:
XValidation is always appended to the schema, without checking if the validation.rule already exists.
This PR adds:
XValidation.Rulealready exists in the schema before appending it.Closes #1294