Skip to content

[Gateway API] Support attaching routes from listeners originating from a ListenerSet#4639

Merged
k8s-ci-robot merged 7 commits intokubernetes-sigs:mainfrom
zac-nixon:main
Mar 24, 2026
Merged

[Gateway API] Support attaching routes from listeners originating from a ListenerSet#4639
k8s-ci-robot merged 7 commits intokubernetes-sigs:mainfrom
zac-nixon:main

Conversation

@zac-nixon
Copy link
Copy Markdown
Collaborator

Description

Refactored the route, listener mapper to hopefully clean the code up a bit. This PR adds the ability for users to attach listeners from a ListenerSet to a Gateway. Things left to do:

1/ Add ListenerSet status updates
2/ Automated E2E test add.

See inline comments for more context.

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zac-nixon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 23, 2026
return nameCheck && nsCheck
}

func doesResourceAllowNamespace(ctx context.Context, fromNamespaces gwv1.FromNamespaces, labelSelector *metav1.LabelSelector, nsSelector namespaceSelector, resourceNamespace string, gw gwv1.Gateway) (bool, error) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We want to re-use the logic between ListenerSet and Gateway.

// a route to attach to it.
type listenerAttachmentHelper interface {
listenerAllowsAttachment(ctx context.Context, gw gwv1.Gateway, listener gwv1.Listener, route preLoadRouteDescriptor, matchedParentRef *gwv1.ParentReference, hostnamesFromHttpRoutes map[types.NamespacedName][]gwv1.Hostname, hostnamesFromGrpcRoutes map[types.NamespacedName][]gwv1.Hostname) ([]gwv1.Hostname, bool, *RouteData, error)
listenerAllowsAttachment(ctx context.Context, parentNamespace string, listener gwv1.Listener, route preLoadRouteDescriptor, matchedParentRef gwv1.ParentReference, hostnamesFromHttpRoutes map[int32]sets.Set[gwv1.Hostname], hostnamesFromGrpcRoutes map[int32]sets.Set[gwv1.Hostname]) ([]gwv1.Hostname, *RouteData, error)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

There was a bug where we only considered conflicting hostnames using listener section name, however we need to use listener port to accurately capture all attached hostnames.

// check namespace TODO --- Update for ListenerSet, should be ListenerSet namespace.
namespaceOK, err := attachmentHelper.namespaceCheck(ctx, parentNamespace, listener, route)
if err != nil {
return nil, false, nil, err
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed returning false / true for attachment. Users can utilize RouteData being nil to signify successful attachment.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can it be nil? i remember they need some attributes not empty

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

check out the old code path. there was no case where we returned attachment = true with route data being nil.

if !kindOK {
rd := GenerateRouteData(false, true, string(gwv1.RouteReasonNotAllowedByListeners), RouteStatusInfoRejectedMessageKindNotMatch, route.GetRouteNamespacedName(), route.GetRouteKind(), route.GetRouteGeneration(), gw, port, sectionName)
return nil, false, &rd, nil
return nil, new(GenerateRouteData(false, true, string(gwv1.RouteReasonNotAllowedByListeners), RouteStatusInfoRejectedMessageKindNotMatch, route.GetRouteNamespacedName(), route.GetRouteKind(), route.GetRouteGeneration(), matchedParentRef)), nil
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was suggested by my IDE. In go 1.26 we can use new() instead of &Value{}.

Comment thread pkg/gateway/routeutils/listener_attachment_helper.go
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I was able to consolidate this logic into loader.go, we didn't need all this additional logic.

@zac-nixon
Copy link
Copy Markdown
Collaborator Author

/retest

Routes: loadedRoute,
Listeners: gw.Spec.Listeners,
AttachedRoutesMap: attachedRouteMap,
AttachedRoutesMap: mapResult.routesPerListener,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why do we remove Listeners from loaderResult? is it gonna be added back?

Comment thread pkg/gateway/routeutils/listener_attachment_helper.go
// check namespace TODO --- Update for ListenerSet, should be ListenerSet namespace.
namespaceOK, err := attachmentHelper.namespaceCheck(ctx, parentNamespace, listener, route)
if err != nil {
return nil, false, nil, err
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can it be nil? i remember they need some attributes not empty

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks for the refactor!

@shuqz
Copy link
Copy Markdown
Collaborator

shuqz commented Mar 24, 2026

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 24, 2026
@k8s-ci-robot k8s-ci-robot merged commit acfc9ac into kubernetes-sigs:main Mar 24, 2026
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants