From d26fcb78de9b3d4bdd73218114ee4bf93d8bff84 Mon Sep 17 00:00:00 2001 From: Kate Osborn Date: Thu, 5 Jan 2023 10:48:34 -0700 Subject: [PATCH 1/2] Fix status for parentRef with invalid listener --- internal/state/conditions/httproute.go | 14 ++++++++++++++ internal/state/graph.go | 5 +++++ internal/state/graph_test.go | 24 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/internal/state/conditions/httproute.go b/internal/state/conditions/httproute.go index d7c7464bde..2663142767 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. +var 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 { From ff8968440fd5bdbbf520b690cae53a8fe71e8fd2 Mon Sep 17 00:00:00 2001 From: Kate Osborn Date: Fri, 6 Jan 2023 09:45:39 -0700 Subject: [PATCH 2/2] Change var to const --- internal/state/conditions/httproute.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/state/conditions/httproute.go b/internal/state/conditions/httproute.go index 2663142767..d63464a253 100644 --- a/internal/state/conditions/httproute.go +++ b/internal/state/conditions/httproute.go @@ -8,7 +8,7 @@ import ( ) // RouteReasonInvalidListener is used with the "Accepted" condition when the route references an invalid listener. -var RouteReasonInvalidListener v1beta1.RouteConditionReason = "InvalidListener" +const RouteReasonInvalidListener v1beta1.RouteConditionReason = "InvalidListener" // RouteCondition defines a condition to be reported in the status of an HTTPRoute. type RouteCondition struct {