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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validation: Allow loose validation for sets #247

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

apelisse
Copy link
Contributor

If a set (or associative lists keys) has duplicated elements, then this will not fail the validation. Everything else is still the same.

/assign @alexzielenski

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apelisse

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 requested a review from jpbetz September 26, 2023 22:28
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 26, 2023
@apelisse
Copy link
Contributor Author

This is starting to address #234. I have all the code passing the numerous tests I've written, but I'm going to send small PRs.
cc @thockin

typed/typed.go Outdated
type ValidationOptions int

const (
Loose ValidationOptions = iota
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I'm actually renaming this AllowDuplicates since .. that's a lot closer to what it actually is.

If a set (or associative lists keys) has duplicated elements, then this
will not fail the validation. Everything is still the same.
Copy link
Contributor

@alexzielenski alexzielenski left a comment

Choose a reason for hiding this comment

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

easy to follow

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 26, 2023
// AsTyped accepts a value and a type and returns a TypedValue. 'v' must have
// type 'typeName' in the schema. An error is returned if the v doesn't conform
// to the schema.
func AsTyped(v value.Value, s *schema.Schema, typeRef schema.TypeRef) (*TypedValue, error) {
func AsTyped(v value.Value, s *schema.Schema, typeRef schema.TypeRef, opts ...ValidationOptions) (*TypedValue, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've decided to use that convention since we want to backport this code and I didn't want to break the compatibility with existing code (forcing me to bump the major version). Alternative could be to make a AsTypedWithDuplicates

@alexzielenski
Copy link
Contributor

alexzielenski commented Sep 26, 2023

/hold

edit: whoops too late

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 26, 2023
@k8s-ci-robot k8s-ci-robot merged commit 042aa8e into kubernetes-sigs:master Sep 26, 2023
@apelisse
Copy link
Contributor Author

No worries, let me know what you want me to address, I'll focus on that before continuing.

@@ -24,16 +24,24 @@ import (
"sigs.k8s.io/structured-merge-diff/v4/value"
)

// ValidationOptions is the list of all the options available when running the validation.
type ValidationOptions int
Copy link
Contributor

@alexzielenski alexzielenski Sep 26, 2023

Choose a reason for hiding this comment

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

Think it would be better if this was not an int and instead something like a func (v *validatingObjectWalker) or something similar so that we aren't bound to very simple options in the future.

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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants