From 8b900ae1ebd2ef2bec61833ed564ff1f728d3a00 Mon Sep 17 00:00:00 2001 From: Ciara Stacke Date: Wed, 24 May 2023 12:44:34 +0100 Subject: [PATCH] Update route condition where listener is not found --- docs/gateway-api-compatibility.md | 1 + internal/state/conditions/conditions.go | 11 +++++++++++ internal/state/graph/httproute.go | 4 +--- internal/state/graph/httproute_test.go | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/gateway-api-compatibility.md b/docs/gateway-api-compatibility.md index d6b56e2bd8..ecc62ff5a4 100644 --- a/docs/gateway-api-compatibility.md +++ b/docs/gateway-api-compatibility.md @@ -118,6 +118,7 @@ Fields: * `conditions` - partially supported. Supported (Condition/Status/Reason): * `Accepted/True/Accepted` * `Accepted/False/NoMatchingListenerHostname` + * `Accepted/False/NoMatchingParent` * `Accepted/False/UnsupportedValue`: Custom reason for when the HTTPRoute includes an invalid or unsupported value. * `Accepted/False/InvalidListener`: Custom reason for when the HTTPRoute references an invalid listener. * `ResolvedRefs/True/ResolvedRefs` diff --git a/internal/state/conditions/conditions.go b/internal/state/conditions/conditions.go index 974efcc35d..73e81370f7 100644 --- a/internal/state/conditions/conditions.go +++ b/internal/state/conditions/conditions.go @@ -201,6 +201,17 @@ func NewRouteInvalidGateway() Condition { } } +// NewRouteNoMatchingParent returns a Condition that indicates that the Route is not Accepted because +// it specifies a Port and/or SectionName that does not match any Listeners in the Gateway. +func NewRouteNoMatchingParent() Condition { + return Condition{ + Type: string(v1beta1.RouteConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.RouteReasonNoMatchingParent), + Message: "Listener is not found for this parent ref", + } +} + // NewDefaultListenerConditions returns the default Conditions that must be present in the status of a Listener. func NewDefaultListenerConditions() []Condition { return []Condition{ diff --git a/internal/state/graph/httproute.go b/internal/state/graph/httproute.go index 850754609a..7124d4b2ef 100644 --- a/internal/state/graph/httproute.go +++ b/internal/state/graph/httproute.go @@ -317,9 +317,7 @@ func tryToAttachRouteToListeners( validListeners, listenerExists := findValidListeners(getSectionName(sectionName), listeners) if !listenerExists { - // FIXME(pleshakov): Add a proper condition once it is available in the Gateway API. - // https://github.com/nginxinc/nginx-kubernetes-gateway/issues/665 - return conditions.NewTODO("listener is not found"), false + return conditions.NewRouteNoMatchingParent(), false } if len(validListeners) == 0 { diff --git a/internal/state/graph/httproute_test.go b/internal/state/graph/httproute_test.go index 8a129da6cb..afbb108883 100644 --- a/internal/state/graph/httproute_test.go +++ b/internal/state/graph/httproute_test.go @@ -841,7 +841,7 @@ func TestBindRouteToListeners(t *testing.T) { Gateway: client.ObjectKeyFromObject(gw), Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedCondition: conditions.NewTODO("listener is not found"), + FailedCondition: conditions.NewRouteNoMatchingParent(), AcceptedHostnames: map[string][]string{}, }, },