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

Fix CEL validations for parentRefs and use 'in' operator in some CEL expressions #2320

Merged
merged 2 commits into from
Aug 18, 2023

Conversation

gauravkghildiyal
Copy link
Member

@gauravkghildiyal gauravkghildiyal commented Aug 18, 2023

What type of PR is this?
/kind feature
/kind bug
/kind cleanup
/kind test

What this PR does / why we need it:
Fix CEL validations for parentRefs and use 'in' operator in some CEL expressions

Which issue(s) this PR fixes:

Addresses comments:

Does this PR introduce a user-facing change?:

NONE

Explanation for future reference:

The validations in this PR are meant to cover the webhook validations:

func ValidateParentRefs(parentRefs []gatewayv1b1.ParentReference, path *field.Path) field.ErrorList {

The validation is split apart into Standard and Experimental (as Port field is currently only available in Experimental). Each of them have two validations:

1. sectionName must be specified when parentRefs includes 2 or more references to the same parent

CEL Playground:

The aim of this validation is to ensure that if two references are to the same parent, then:

  • Either ALL of them don't have a sectionName (Overall, this is not a valid configuration and will be caught as part of validation number 2 for uniqueness).
  • Or ALL of them have a non-empty sectionName.

VALID:

# All have some section name (although all are exactly the same)
self:
    - group: 'example1.org'
      kind: 'Widget'
      name: 'mywidget'
      __namespace__: 'test'
      sectionName: "abc"

    - group: 'example1.org'
      kind: 'Widget'
      name: 'mywidget'
      __namespace__: 'test'
      sectionName: "abc"

# None have a sectionName
self:
    - group: 'example1.org'
      kind: 'Widget'
      name: 'mywidget'
      __namespace__: 'test'
    - group: 'example1.org'
      kind: 'Widget'
      name: 'mywidget'
      __namespace__: 'test'

INVALID:

# One has section name while other doesn't
self:
    - group: 'example1.org'
      kind: 'Widget'
      name: 'mywidget'
      __namespace__: 'test'

    - group: 'example1.org'
      kind: 'Widget'
      name: 'mywidget'
      __namespace__: 'test'
      sectionName: "abc"

2. sectionName must be unique when parentRefs includes 2 or more references to the same parent

CEL Playground:

This only tries to guarantee that the combination of all fields within parentRefs is unique.

Something like below is VALID here, but would be considered INVALID for the previous validation

# Both are unique based on their `sectionName`
self:
    - group: 'example1.org'
      kind: 'Widget'
      name: 'mywidget'
      __namespace__: 'test'

    - group: 'example1.org'
      kind: 'Widget'
      name: 'mywidget'
      __namespace__: 'test'
      sectionName: "abc"

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/feature Categorizes issue or PR as related to a new feature. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Aug 18, 2023
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 18, 2023
@gauravkghildiyal
Copy link
Member Author

Added some explanation in the description and created #2325 to track adding something within our code.

@robscott
Copy link
Member

Thanks for all the work on this @gauravkghildiyal! Definitely appreciate the detailed explanation of the validation here and the follow up issues stemming from this PR.

/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 Aug 18, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gauravkghildiyal, robscott

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 Aug 18, 2023
@k8s-ci-robot k8s-ci-robot merged commit e9b02c5 into kubernetes-sigs:main Aug 18, 2023
8 of 9 checks passed
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. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. kind/test lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants