Skip to content

fix: inject port into legacy XListenerSet status to fix required field validation#14231

Merged
davidjumani merged 5 commits into
kgateway-dev:mainfrom
babakzarrinbal:fix/xlistenerset-port-required-field
Jul 13, 2026
Merged

fix: inject port into legacy XListenerSet status to fix required field validation#14231
davidjumani merged 5 commits into
kgateway-dev:mainfrom
babakzarrinbal:fix/xlistenerset-port-required-field

Conversation

@babakzarrinbal

@babakzarrinbal babakzarrinbal commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #14196.

Since v2.3.0 (PR #13671), BuildListenerSetStatus was migrated from gwxv1a1.ListenerEntryStatus to gwv1.ListenerEntryStatus. The promoted type no longer carries a Port field, but the legacy XListenerSet CRD schema still requires status.listeners[*].port. As a result, every reconcile cycle fails to patch XListenerSet status with:

XListenerSet.gateway.networking.x-k8s.io "<name>" is invalid: status.listeners[0].port: Required value

Changes:

  • pkg/kgateway/proxy_syncer/status_syncer.go: In patchListenerSetStatus, inject port into the unstructured status map before patching the legacy XListenerSet. Adds injectListenerPorts helper that precomputes a name→port map from ls.Spec.Listeners using kubeutils.DetectListenerPortNumber, with a named legacyPortFallback constant (65535) for both unknown protocols and unmatched listeners — matching v2.2.4 behaviour. The promoted ListenerSet path (legacyListenerSet == nil) is untouched.
  • pkg/kgateway/proxy_syncer/inject_listener_ports_test.go: 8 table-driven unit tests covering spec-explicit port, HTTP/HTTPS default ports, unknown-protocol fallback, multiple listeners, orphan listener (no spec match → fallback port), missing key, and empty slice.

Change Type

/kind fix

Changelog

Fix XListenerSet status patch failures caused by missing required port field since v2.3.0.

Additional Notes

The fix is intentionally scoped to the legacy XListenerSet code path only. Copilot review comments addressed: named constant for 65535, O(n²) → O(n) precomputed map, fallback port for unmatched listeners, and test improvements.

Copilot AI review requested due to automatic review settings June 11, 2026 10:00
@gateway-bot gateway-bot added do-not-merge/description-invalid do-not-merge/kind-invalid Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/release-note-invalid Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds compatibility logic so legacy XListenerSet CRDs continue to receive required status.listeners[*].port fields even though the promoted gwv1.ListenerEntryStatus no longer includes Port.

Changes:

  • Inject port into legacy ListenerSet status entries by looking up matching listeners in spec.
  • Use kubeutils.DetectListenerPortNumber to derive port defaults when spec port is 0.
  • Add unit tests covering multiple listener/protocol scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
pkg/kgateway/proxy_syncer/status_syncer.go Injects legacy-required port into ListenerSet status before patching.
pkg/kgateway/proxy_syncer/inject_listener_ports_test.go Adds unit tests for the listener port injection helper.

Comment thread pkg/kgateway/proxy_syncer/status_syncer.go
Comment thread pkg/kgateway/proxy_syncer/status_syncer.go
Comment thread pkg/kgateway/proxy_syncer/status_syncer.go Outdated
Comment thread pkg/kgateway/proxy_syncer/status_syncer.go Outdated
Comment thread pkg/kgateway/proxy_syncer/inject_listener_ports_test.go Outdated
Comment thread pkg/kgateway/proxy_syncer/inject_listener_ports_test.go Outdated
@gateway-bot gateway-bot added kind/fix Categorizes issue or PR as related to a bug. release-note and removed do-not-merge/description-invalid do-not-merge/kind-invalid Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/release-note-invalid Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 11, 2026
@davidjumani
davidjumani added this pull request to the merge queue Jul 13, 2026
Merged via the queue into kgateway-dev:main with commit ff49aa0 Jul 13, 2026
32 checks passed
davidjumani added a commit that referenced this pull request Jul 14, 2026
…d validation (#14231)

Signed-off-by: Babak Zarrinbal <[email protected]>
Co-authored-by: Babak Zarrinbal <[email protected]>
Co-authored-by: David Jumani <[email protected]>
Signed-off-by: David Jumani <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/fix Categorizes issue or PR as related to a bug. release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: BuildListenerSetStatus drops Port field since v2.3.0, causing XListenerSet status patch failures

5 participants