Skip to content

Commit e74a5c4

Browse files
authored
Fix binding to multiple listeners with empty section name (#730)
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.
1 parent 77a9357 commit e74a5c4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

internal/state/graph/httproute.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func tryToAttachRouteToListeners(
338338

339339
attached := false
340340
for _, l := range validListeners {
341-
attached = attached || bind(l)
341+
attached = bind(l) || attached
342342
}
343343

344344
if !attached {

internal/state/graph/httproute_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,9 @@ func TestBindRouteToListeners(t *testing.T) {
751751
Valid: true,
752752
Listeners: map[string]*Listener{
753753
"listener-80-1": createListener("listener-80-1"),
754+
"listener-80-2": createModifiedListener("listener-80-2", func(l *Listener) {
755+
l.Source.Hostname = nil
756+
}),
754757
},
755758
},
756759
expectedSectionNameRefs: []ParentRef{
@@ -761,6 +764,7 @@ func TestBindRouteToListeners(t *testing.T) {
761764
Attached: true,
762765
AcceptedHostnames: map[string][]string{
763766
"listener-80-1": {"foo.example.com"},
767+
"listener-80-2": {"foo.example.com"},
764768
},
765769
},
766770
},
@@ -771,6 +775,12 @@ func TestBindRouteToListeners(t *testing.T) {
771775
client.ObjectKeyFromObject(hr): routeWithEmptySectionName,
772776
}
773777
}),
778+
"listener-80-2": createModifiedListener("listener-80-2", func(l *Listener) {
779+
l.Routes = map[types.NamespacedName]*Route{
780+
client.ObjectKeyFromObject(hr): routeWithEmptySectionName,
781+
}
782+
l.Source.Hostname = nil
783+
}),
774784
},
775785
name: "section name is empty",
776786
},

0 commit comments

Comments
 (0)