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

馃尡 add validation for default, enum and example definitions in variables #5835

Merged

Conversation

killianmuldoon
Copy link
Contributor

This PR adds schema validation for values defined for default, enum and example in a ClusterClass variable.

e.g.

If a user defines a schema with an integer and minimum value 1 a default, example or enum member of -100 will be found to be invalid and the ClusterClass will be rejected on creation or update.

It also removes the Kubernetes CRD default validation that was part of the code previously.

Fixes #5831

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 9, 2021
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 9, 2021
@sbueringer
Copy link
Member

sbueringer commented Dec 10, 2021

I think we should restructure. The current recursion is not ideal (before this PR)

~ something like:

  • top-level validateRootSchema func:

    • convertToAPIExtensionsJSONSchemaProps
      • move the basic JSON validation into this func
    • do all the stuff with the Kubernetes schema validators including ValidateDefaulting
    • call validateSchema on the current top-level apiExtensionsSchema
  • validateSchema:
    * validate type
    * build a validator with validation.NewSchemaValidator
    * validate Example & Enums
    * call validateSchema recursively for array/object

Let's pair if possible.

@killianmuldoon killianmuldoon force-pushed the add/extra-var-validation branch 3 times, most recently from dcb16cd to f376867 Compare December 10, 2021 15:15
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 10, 2021
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 10, 2021
Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

changes lgtm, I will make another past on tests

@killianmuldoon killianmuldoon force-pushed the add/extra-var-validation branch 2 times, most recently from 8d2f47e to d1a7295 Compare December 10, 2021 18:57
@sbueringer
Copy link
Member

lgtm pending squash

Co-authored-by: Stefan B眉ringer buringerst@vmware.com
Signed-off-by: killianmuldoon <kmuldoon@vmware.com>
Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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 Dec 13, 2021
@k8s-ci-robot k8s-ci-robot merged commit a5c4049 into kubernetes-sigs:main Dec 13, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.1 milestone Dec 13, 2021
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClusterClass: schema validation of Default, Enum, Example
4 participants