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

Requiring SectionName or Port to be specified for distinct parents #2433

Merged
merged 1 commit into from
Sep 28, 2023

Conversation

robscott
Copy link
Member

@robscott robscott commented Sep 27, 2023

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
Previously parents could be distinct if one specified a port and one specified a listener. Now they either both need to specify a distinct SectionName, both need to specify a distinct Port, or both. This PR replaces #2350.

Which issue(s) this PR fixes:
Fixes #2326
Fixes #1925

Does this PR introduce a user-facing change?:

Experimental Channel: For ParentRefs to be considered distinct, they either both need to specify a distinct SectionName, both need to specify a distinct Port, or both.

Note For Reviewers:
CEL is complicated, and this took some time for me to fully understand. Fortunately @gauravkghildiyal pointed me back to his well documented PR that added the initial validation here #2320.

Essentially, this requires 2 lines of validation per channel. The first one ensures that whenever ParentRefs refer to the same object (Group + Kind + Namespace + Name), they all must have the same fields set. The second one ensures that all values within ParentRefs are unique.

In this case we only need to change the first one, and we needed to ensure that has(p1.sectionName) must equal has(p2.sectionName) and similar for port in experimental channel. (For reference p1 and p2 are different parentRefs in the list in both this example and the CEL validation code). This change actually enables us to simplify our logic a bit so the key part of the condition in experimental channel looks like this:

((!has(p1.sectionName) || p1.sectionName == '') == (!has(p2.sectionName) || p2.sectionName == '') && (!has(p1.port) || p1.port == 0) == (!has(p2.port) || p2.port == 0))

Although the behavior in standard channel is unchanged, we can also simplify that logic similarly:

((!has(p1.sectionName) || p1.sectionName == '') == (!has(p2.sectionName) || p2.sectionName == '')

A huge thanks to @gauravkghildiyal for the help with this and also to @youngnick who contributed the actual changes to the guidance in the spec I'm including here.

/cc @youngnick @gauravkghildiyal

Previously parents could be distinct if one specified a port and one
specified a listener. Now they either both need to specify a distinct
SectionName, both need to specify a distinct Port, or both.

Co-authored-by: Gaurav Ghildiyal <[email protected]>
Co-authored-by: Nick Young <[email protected]>
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Sep 27, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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 27, 2023
@shaneutt shaneutt added the release-blocker MUST be completed to complete the milestone label Sep 27, 2023
@shaneutt shaneutt added this to the v1.0.0 milestone Sep 27, 2023
@gauravkghildiyal
Copy link
Member

gauravkghildiyal commented Sep 28, 2023

Thanks @robscott . This LGTM (I verified as well). Will defer to @youngnick for approval

That's a brilliant idea to compare boolean values. Definitely shortens thing up a lot.

@youngnick
Copy link
Contributor

/lgtm

Thanks @robscott for sorting this one out.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 28, 2023
@k8s-ci-robot k8s-ci-robot merged commit d3b272e into kubernetes-sigs:main Sep 28, 2023
3 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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-blocker MUST be completed to complete the milestone release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
No open projects
5 participants