Skip to content

Commit 5d100aa

Browse files
authored
Fix status for parentRef with invalid listener (#350)
Problem: If an HTTPRoute references an invalid listener in a parentRef, the status is incorrectly reported as Accepted:True. Fix: Check if the listener associated with the parentRef is valid when binding HTTPRoutes to listeners. If not valid, mark the section name as invalid with a condition of Accepted:False and a Reason of InvalidListener. This commit adds a new route Reason InvalidListener.
1 parent b3942e4 commit 5d100aa

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

internal/state/conditions/httproute.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"sigs.k8s.io/gateway-api/apis/v1beta1"
88
)
99

10+
// RouteReasonInvalidListener is used with the "Accepted" condition when the route references an invalid listener.
11+
const RouteReasonInvalidListener v1beta1.RouteConditionReason = "InvalidListener"
12+
1013
// RouteCondition defines a condition to be reported in the status of an HTTPRoute.
1114
type RouteCondition struct {
1215
Type v1beta1.RouteConditionType
@@ -70,3 +73,14 @@ func NewRouteTODO(msg string) RouteCondition {
7073
Message: fmt.Sprintf("The condition for this has not been implemented yet: %s", msg),
7174
}
7275
}
76+
77+
// NewRouteInvalidListener returns a RouteCondition that indicates that the HTTPRoute is not accepted because of an
78+
// invalid listener.
79+
func NewRouteInvalidListener() RouteCondition {
80+
return RouteCondition{
81+
Type: v1beta1.RouteConditionAccepted,
82+
Status: metav1.ConditionFalse,
83+
Reason: RouteReasonInvalidListener,
84+
Message: "The listener is invalid for this parent ref",
85+
}
86+
}

internal/state/graph.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ func bindHTTPRouteToListeners(
242242
continue
243243
}
244244

245+
if !l.Valid {
246+
r.InvalidSectionNameRefs[name] = conditions.NewRouteInvalidListener()
247+
continue
248+
}
249+
245250
accepted := findAcceptedHostnames(l.Source.Hostname, ghr.Spec.Hostnames)
246251

247252
if len(accepted) > 0 {

internal/state/graph_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,30 @@ func TestBindRouteToListeners(t *testing.T) {
10201020
expectedListeners: nil,
10211021
msg: "HTTPRoute when no gateway exists",
10221022
},
1023+
{
1024+
httpRoute: hrFoo,
1025+
gw: gw,
1026+
ignoredGws: nil,
1027+
listeners: map[string]*listener{
1028+
"listener-80-1": createModifiedListener(func(l *listener) {
1029+
l.Valid = false
1030+
}),
1031+
},
1032+
expectedIgnored: false,
1033+
expectedRoute: &route{
1034+
Source: hrFoo,
1035+
ValidSectionNameRefs: map[string]struct{}{},
1036+
InvalidSectionNameRefs: map[string]conditions.RouteCondition{
1037+
"listener-80-1": conditions.NewRouteInvalidListener(),
1038+
},
1039+
},
1040+
expectedListeners: map[string]*listener{
1041+
"listener-80-1": createModifiedListener(func(l *listener) {
1042+
l.Valid = false
1043+
}),
1044+
},
1045+
msg: "HTTPRoute with invalid listener parentRef",
1046+
},
10231047
}
10241048

10251049
for _, test := range tests {

0 commit comments

Comments
 (0)