diff --git a/internal/state/conditions/httproute.go b/internal/state/conditions/httproute.go index d7c7464bde..d63464a253 100644 --- a/internal/state/conditions/httproute.go +++ b/internal/state/conditions/httproute.go @@ -7,6 +7,9 @@ import ( "sigs.k8s.io/gateway-api/apis/v1beta1" ) +// RouteReasonInvalidListener is used with the "Accepted" condition when the route references an invalid listener. +const RouteReasonInvalidListener v1beta1.RouteConditionReason = "InvalidListener" + // RouteCondition defines a condition to be reported in the status of an HTTPRoute. type RouteCondition struct { Type v1beta1.RouteConditionType @@ -70,3 +73,14 @@ func NewRouteTODO(msg string) RouteCondition { Message: fmt.Sprintf("The condition for this has not been implemented yet: %s", msg), } } + +// NewRouteInvalidListener returns a RouteCondition that indicates that the HTTPRoute is not accepted because of an +// invalid listener. +func NewRouteInvalidListener() RouteCondition { + return RouteCondition{ + Type: v1beta1.RouteConditionAccepted, + Status: metav1.ConditionFalse, + Reason: RouteReasonInvalidListener, + Message: "The listener is invalid for this parent ref", + } +} diff --git a/internal/state/graph.go b/internal/state/graph.go index df8d1d52cb..1e9587dc23 100644 --- a/internal/state/graph.go +++ b/internal/state/graph.go @@ -242,6 +242,11 @@ func bindHTTPRouteToListeners( continue } + if !l.Valid { + r.InvalidSectionNameRefs[name] = conditions.NewRouteInvalidListener() + continue + } + accepted := findAcceptedHostnames(l.Source.Hostname, ghr.Spec.Hostnames) if len(accepted) > 0 { diff --git a/internal/state/graph_test.go b/internal/state/graph_test.go index 16bfa5d947..7d776511f5 100644 --- a/internal/state/graph_test.go +++ b/internal/state/graph_test.go @@ -1020,6 +1020,30 @@ func TestBindRouteToListeners(t *testing.T) { expectedListeners: nil, msg: "HTTPRoute when no gateway exists", }, + { + httpRoute: hrFoo, + gw: gw, + ignoredGws: nil, + listeners: map[string]*listener{ + "listener-80-1": createModifiedListener(func(l *listener) { + l.Valid = false + }), + }, + expectedIgnored: false, + expectedRoute: &route{ + Source: hrFoo, + ValidSectionNameRefs: map[string]struct{}{}, + InvalidSectionNameRefs: map[string]conditions.RouteCondition{ + "listener-80-1": conditions.NewRouteInvalidListener(), + }, + }, + expectedListeners: map[string]*listener{ + "listener-80-1": createModifiedListener(func(l *listener) { + l.Valid = false + }), + }, + msg: "HTTPRoute with invalid listener parentRef", + }, } for _, test := range tests {