Requiring SectionName or Port to be specified for distinct parents #2433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?:
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 equalhas(p2.sectionName)
and similar for port in experimental channel. (For referencep1
andp2
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:Although the behavior in standard channel is unchanged, we can also simplify that logic similarly:
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