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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fix XValidations flattening #998

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cezarsa
Copy link

@cezarsa cezarsa commented Jun 27, 2024

Fixes #997

This PR ensures XValidations are merged correctly when flattening the CRD schema.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 27, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @cezarsa!

It looks like this is your first PR to kubernetes-sigs/controller-tools 馃帀. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-tools has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 馃槂

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 27, 2024
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cezarsa
Once this PR has been reviewed and has the lgtm label, please assign joelanford for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 27, 2024
@sbueringer
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 28, 2024
@JoelSpeed
Copy link
Contributor

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?

@cezarsa
Copy link
Author

cezarsa commented Jul 1, 2024

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.

@JoelSpeed
Copy link
Contributor

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

@cezarsa
Copy link
Author

cezarsa commented Jul 1, 2024

Is that true? I was under the impression that if a rule failed, further rules were not executed until the earlier rule passed?

Yes, I just tested it to be sure, using controller-gen from this branch and with an object declared as:

type FooSpec struct {
	// +kubebuilder:validation:XValidation:rule="false",message="validation 3"
	// +kubebuilder:validation:XValidation:rule="false",message="validation 4"
	Thing *Thing `json:"thing"`
}

// +kubebuilder:validation:XValidation:rule="false",message="validation 1"
// +kubebuilder:validation:XValidation:rule="false",message="validation 2"
type Thing struct {
	Field *string `json:"field"`
}

Applying it returned all the validation errors:

$  k apply -f ./example.yaml
The Foo "foo1" is invalid:
* spec.thing: Invalid value: "object": validation 1
* spec.thing: Invalid value: "object": validation 2
* spec.thing: Invalid value: "object": validation 3
* spec.thing: Invalid value: "object": validation 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid CRD generated when XValidation is used on both field and struct
4 participants