From bcb5073c8aec1fd52a485cd5f9cba08ed75a6b39 Mon Sep 17 00:00:00 2001 From: Kate Osborn Date: Thu, 8 Jun 2023 14:30:31 -0600 Subject: [PATCH] Fix binding to multiple listeners with empty section name Problem: If an HTTPRoute has a parentRef with an empty section name, and the referenced gateway has multiple valid listeners, the route would only bind to the first listener. Solution: Attempt to bind to every valid listener in the referenced Gateway. --- internal/state/graph/httproute.go | 2 +- internal/state/graph/httproute_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/state/graph/httproute.go b/internal/state/graph/httproute.go index 7124d4b2e..d00b7878d 100644 --- a/internal/state/graph/httproute.go +++ b/internal/state/graph/httproute.go @@ -338,7 +338,7 @@ func tryToAttachRouteToListeners( attached := false for _, l := range validListeners { - attached = attached || bind(l) + attached = bind(l) || attached } if !attached { diff --git a/internal/state/graph/httproute_test.go b/internal/state/graph/httproute_test.go index afbb10888..2e62d5923 100644 --- a/internal/state/graph/httproute_test.go +++ b/internal/state/graph/httproute_test.go @@ -751,6 +751,9 @@ func TestBindRouteToListeners(t *testing.T) { Valid: true, Listeners: map[string]*Listener{ "listener-80-1": createListener("listener-80-1"), + "listener-80-2": createModifiedListener("listener-80-2", func(l *Listener) { + l.Source.Hostname = nil + }), }, }, expectedSectionNameRefs: []ParentRef{ @@ -761,6 +764,7 @@ func TestBindRouteToListeners(t *testing.T) { Attached: true, AcceptedHostnames: map[string][]string{ "listener-80-1": {"foo.example.com"}, + "listener-80-2": {"foo.example.com"}, }, }, }, @@ -771,6 +775,12 @@ func TestBindRouteToListeners(t *testing.T) { client.ObjectKeyFromObject(hr): routeWithEmptySectionName, } }), + "listener-80-2": createModifiedListener("listener-80-2", func(l *Listener) { + l.Routes = map[types.NamespacedName]*Route{ + client.ObjectKeyFromObject(hr): routeWithEmptySectionName, + } + l.Source.Hostname = nil + }), }, name: "section name is empty", },