8000 ListenerSet adjust PortNumber kubebuilder validations by dprotaso · Pull Request #3750 · kubernetes-sigs/gateway-api · GitHub
[go: up one dir, main page]

Skip to content

Conversation

dprotaso
Copy link
Contributor
@dprotaso dprotaso commented Apr 14, 2025
  • set proper min/max value for listenerentry.port
  • adjust kubebuilder annotations for PortNumber to accomodate ListenerSet changes
PortNumber for ListenerEntry now supports setting to 0 - implying a port is chosen by the implementation

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. 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. labels Apr 14, 2025
@k8s-ci-robot k8s-ci-robot added kind/gep PRs related to Gateway Enhancement Proposal(GEP) size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 14, 2025
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 17, 2025
@dprotaso dprotaso changed the title [wip] adjust PortNumber kubebuilder validations ListenerSet adjust PortNumber kubebuilder validations Apr 17, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 17, 2025
dprotaso added a commit to dprotaso/gateway-api that referenced this pull request Apr 17, 2025
dprotaso added a commit to dprotaso/gateway-api that referenced this pull request Apr 17, 2025
dprotaso added a commit to dprotaso/gateway-api that referenced this pull request Apr 17, 2025
@dprotaso dprotaso mentioned this pull request Apr 17, 2025
@dprotaso dprotaso force-pushed the listenerset-port-number branch from f0f9284 to 2797f27 Compare April 17, 2025 05:41
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 17, 2025
@dprotaso
Copy link
Contributor Author
dprotaso commented May 6, 2025

bump

Copy link
Member
@mlavacca mlavacca left a comment

Choose a reason for hiding this comment

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

k8s-ci-robot pushed a commit that referenced this pull request Jun 11, 2025
* formatting

* clarify optional port semantics

* clarify listener name semantics

* clarify attachment/grants semantics

- Route attachment without sectionName
- re-order policy attachment section
- include a section about ReferenceGrants

* set proper min/max value for listenerentry.port

We had to drop the use of the PortNumber type because of
limitations with overriding min max using kubebuilder
annotations

* Update geps/gep-1713/index.md

Co-authored-by: Nick Young <inocuo@gmail.com>

* Drop validation markers this is handled in another PR

See: #3750

* address Nick's feedback

* remove stray backtick

* address Rob's feedback

* incorporate gep changes into godoc

---------

Co-authored-by: Nick Young <inocuo@gmail.com>
@dprotaso dprotaso force-pushed the listenerset-port-number branch from bbdc171 to 2314651 Compare June 13, 2025 16:42
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 13, 2025
dprotaso added 3 commits June 13, 2025 12:44
controller-tools only allows this to work on object types and not ref types
//
// +optional
//
// +kubebuilder:default=0
Copy link
Contributor

Choose a reason for hiding this comment

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

If the default is now 0, is this not a backward compatible change once it goes to standard? Formerly the port was optional, so there could be widespread omitted-port cases that were already properly handled. Now there could be a completely different way that missing ports are handled. Do we need to worry about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the default is now 0, is this not a backward compatible change once it goes to standard?

I don't think so the ListenerSet is an alpha API so I believe we can make these changes.

Formerly the port was optional

It wasn't actually - maybe that's the confusion here

Copy link
Contributor

Choose a reason for hiding this comment

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

This is only non-breaking because we're going from required to optional. But as @dprotaso says, it would be okay to make a breaking change because this is alpha.

@youngnick
Copy link
Contributor

This LGTM since it's for ListenerSet.

Also, I would update the changelog note to remove the word randomly, since it can be up to the implementation how the port is actually chosen.

@dprotaso
Copy link
Contributor Author

update the changelog note to remove the word randomly

@youngnick done

@dprotaso
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 30, 2025
@youngnick
Copy link
Contributor

This LGTM now, so I'll approve.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, youngnick

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 Jul 1, 2025
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 1, 2025
@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 4, 2025
@kflynn
Copy link
Contributor
kflynn commented Aug 5, 2025

There are language nits I might be able to pick with this, but it looks good to me overall, so

/lgtm

I'd really like to see this one followed up quickly with making listeners optional in Gateway...

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 5, 2025
@kflynn
Copy link
Contributor
kflynn commented Aug 5, 2025

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 5, 2025
@k8s-ci-robot k8s-ci-robot merged commit 5836f6f into kubernetes-sigs:main Aug 5, 2025
19 checks passed
@youngnick
Copy link
Contributor

I'd prefer not to make Listeners optional in Gateway until we're confident that this shape for ListenerSet is what we want. Making that change is one we can't walk back once we do it, and it will require a bunch of updates to conformance tests and status expectations.

@dprotaso dprotaso deleted the listenerset-port-number branch August 6, 2025 14:40
@dprotaso
Copy link
Contributor Author
dprotaso commented Aug 6, 2025

Right now the GEP states

In a future (potential) release when an implementation supports ListenerSets, Gateways MUST allow the list of listeners to be empty. Thus the present minItems=1 constraint on the listener list will be removed. This allows implementations to avoid security, cost etc. concerns with having dummy listeners. When there are no listeners the Gateway's status.listeners should be empty or unset. status.listeners is already an optional field.

But we haven't reflected that in any API tags etc. I sorta view this as a implementation detail that we recommend for now.

@kflynn
Copy link
Contributor
kflynn commented Aug 6, 2025

Yeah, @youngnick, I should've been more clear. I look forward to that day, but I am definitely not advocating that we rush it. 🙂

@JoelSpeed
Copy link

I believe this is a bit of an odd change...

We previously had

// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
type PortNumber int32

This allowed many places to re-use the same validations by just re-using the type

This PR changed it to

type PortNumber int32

Removing the shared validations. Now having a PortNumber type declared appears to be pointless?

What's worse, is that it's breaking controller-gen (see slack) and fixing controller gen to support this doesn't look like a very easy fix.

IMO we should either remove the PortNumber declaration altogether (unless there's some other benefit I've missed?) or restore PortNumber to what it was, and create a separate PortNumberAllowZero type for the cases that need to allow 0?

@dprotaso
Copy link
Contributor Author

controller-gen or whatever had issues with overwriting markers when doing type aliases. There's an open issue somewhere I believe.

The approach taken in the PR was the only way to get this to work in GatewayAPI

Adding a new go type for different validations ruins the UX for go authors. Then you could end up with 5 different port numbers types

@dprotaso
Copy link
Contributor Author

Honestly the right fix seems to be to introduce the validation back once controller tools has fixed their alias support for overriding markers

@dprotaso
Copy link
Contributor Author

We also had to adjust the min/max marker as well because it didn't look at underlying types and just dropped markers

See:

func (m Minimum) ApplyToSchema(schema *apiext.JSONSchemaProps) error {

@JoelSpeed
Copy link

controller-gen or whatever had issues with overwriting markers when doing type aliases.

Nit, there's a difference in Go between a type alias (type PortNumber = int32) and a type declaration (type PortNumber int32), and controller-gen is ok with aliases, but not local declarations.

Adding a new go type for different validations ruins the UX for go authors.

What benefit does having to cast all int32s to a PortNumber type provide for Go authors at the moment?

Then you could end up with 5 different port numbers types

Each with different use cases, specific documentation to those use cases, and the ability to evolve with those use cases without then affecting other use cases inadvertently... That sounds like a good thing to me?

We also had to adjust the min/max marker as well because it didn't look at underlying types and just dropped markers

This is to do with the way that controller-gen parses and then flattens the types. I have a fix that would potentially unblock this, but it is perhaps a breaking change, see kubernetes-sigs/controller-tools#1270

@dprotaso
Copy link
Contributor Author

Nit

Yup

What benefit does having to cast all int32s to a PortNumber type provide for Go authors at the moment?

I'm assuming it was for the validation markers - until controller-gen didn't work as expected

Each with different use cases, specific documentation to those use cases, and the ability to evolve with those use cases without then affecting other use cases inadvertently... That sounds like a good thing to me?

I'd rather the documentation be on the field use vs. the type (assuming overriding markers works)

This is to do with the way that controller-gen parses and then flattens the types. I have a fix that would potentially unblock this, but it is perhaps a breaking change, see kubernetes-sigs/controller-tools#1270

Awesome if the change lands we can make the tweaks in this repo. Then in theory it should be a noop once we re-adjust our markers.

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/gep PRs related to Gateway Enhancement Proposal(GEP) lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

8 participants
0