From 7a5e981834361d7669918eb28648762db630dcbc Mon Sep 17 00:00:00 2001 From: Mattia Lavacca Date: Mon, 23 Jan 2023 11:54:11 +0100 Subject: [PATCH] conformance: HTTPRoute and not allowing listener When a Route references a gateway having no listener whose allowedRoutes criteria permit the route, the reason NotAllowedByListeners should be used for the accepted condition. Signed-off-by: Mattia Lavacca --- .../tests/httproute-disallowed-kind.go | 19 ++++++++++++++----- .../tests/httproute-hostname-intersection.go | 4 ++-- ...oute-invalid-cross-namespace-parent-ref.go | 8 ++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/conformance/tests/httproute-disallowed-kind.go b/conformance/tests/httproute-disallowed-kind.go index e46e5fb431..d072c8b9e9 100644 --- a/conformance/tests/httproute-disallowed-kind.go +++ b/conformance/tests/httproute-disallowed-kind.go @@ -19,8 +19,10 @@ package tests import ( "testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/gateway-api/apis/v1beta1" "sigs.k8s.io/gateway-api/conformance/utils/kubernetes" "sigs.k8s.io/gateway-api/conformance/utils/suite" ) @@ -31,7 +33,7 @@ func init() { var HTTPRouteDisallowedKind = suite.ConformanceTest{ ShortName: "HTTPRouteDisallowedKind", - Description: "A single HTTPRoute in the gateway-conformance-infra namespace should fail to attach to a Listener that does not allow the HTTPRoute kind", + Description: "A single HTTPRoute in the gateway-conformance-infra namespace should fail to attach to a Gateway with no listeners that allow the HTTPRoute kind", Features: []suite.SupportedFeature{suite.SupportTLSRoute}, Manifests: []string{"tests/httproute-disallowed-kind.yaml"}, Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { @@ -39,14 +41,21 @@ var HTTPRouteDisallowedKind = suite.ConformanceTest{ // namespace so we have to wait for it to be ready. kubernetes.NamespacesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, []string{"gateway-conformance-infra"}) - routeName := types.NamespacedName{Name: "disallowed-kind", Namespace: "gateway-conformance-infra"} - gwName := types.NamespacedName{Name: "tlsroutes-only", Namespace: "gateway-conformance-infra"} + routeNN := types.NamespacedName{Name: "disallowed-kind", Namespace: "gateway-conformance-infra"} + gwNN := types.NamespacedName{Name: "tlsroutes-only", Namespace: "gateway-conformance-infra"} + t.Run("Route should not have been accepted with reason NotAllowedByListeners", func(t *testing.T) { + kubernetes.HTTPRouteMustHaveCondition(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN, metav1.Condition{ + Type: string(v1beta1.RouteConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.RouteReasonNotAllowedByListeners), + }) + }) t.Run("Route should not have Parents set in status", func(t *testing.T) { - kubernetes.HTTPRouteMustHaveNoAcceptedParents(t, suite.Client, suite.TimeoutConfig, routeName) + kubernetes.HTTPRouteMustHaveNoAcceptedParents(t, suite.Client, suite.TimeoutConfig, routeNN) }) t.Run("Gateway should have 0 Routes attached", func(t *testing.T) { - kubernetes.GatewayMustHaveZeroRoutes(t, suite.Client, suite.TimeoutConfig, gwName) + kubernetes.GatewayMustHaveZeroRoutes(t, suite.Client, suite.TimeoutConfig, gwNN) }) }, } diff --git a/conformance/tests/httproute-hostname-intersection.go b/conformance/tests/httproute-hostname-intersection.go index e873bdc981..cd52d4fede 100644 --- a/conformance/tests/httproute-hostname-intersection.go +++ b/conformance/tests/httproute-hostname-intersection.go @@ -190,8 +190,8 @@ var HTTPRouteHostnameIntersection = suite.ConformanceTest{ t.Run("HTTPRoutes that do not intersect with listener hostnames", func(t *testing.T) { gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN)) + routeNN := types.NamespacedName{Namespace: ns, Name: "no-intersecting-hosts"} - routeName := types.NamespacedName{Namespace: ns, Name: "no-intersecting-hosts"} parents := []v1beta1.RouteParentStatus{{ ParentRef: parentRefTo(gwNN), ControllerName: v1beta1.GatewayController(suite.ControllerName), @@ -204,7 +204,7 @@ var HTTPRouteHostnameIntersection = suite.ConformanceTest{ }, }} - kubernetes.HTTPRouteMustHaveParents(t, suite.Client, suite.TimeoutConfig, routeName, parents, true) + kubernetes.HTTPRouteMustHaveParents(t, suite.Client, suite.TimeoutConfig, routeNN, parents, true) testCases := []http.ExpectedResponse{ { diff --git a/conformance/tests/httproute-invalid-cross-namespace-parent-ref.go b/conformance/tests/httproute-invalid-cross-namespace-parent-ref.go index fee79b61df..3fcd6433eb 100644 --- a/conformance/tests/httproute-invalid-cross-namespace-parent-ref.go +++ b/conformance/tests/httproute-invalid-cross-namespace-parent-ref.go @@ -34,15 +34,15 @@ var HTTPRouteInvalidCrossNamespaceParentRef = suite.ConformanceTest{ Description: "A single HTTPRoute in the gateway-conformance-web-backend namespace should fail to attach to a Gateway in another namespace that it is not allowed to", Manifests: []string{"tests/httproute-invalid-cross-namespace-parent-ref.yaml"}, Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { - routeName := types.NamespacedName{Name: "invalid-cross-namespace-parent-ref", Namespace: "gateway-conformance-web-backend"} - gwName := types.NamespacedName{Name: "same-namespace", Namespace: "gateway-conformance-infra"} + gwNN := types.NamespacedName{Name: "same-namespace", Namespace: "gateway-conformance-infra"} + routeNN := types.NamespacedName{Name: "invalid-cross-namespace-parent-ref", Namespace: "gateway-conformance-web-backend"} t.Run("Route should not have Parents set in status", func(t *testing.T) { - kubernetes.HTTPRouteMustHaveNoAcceptedParents(t, suite.Client, suite.TimeoutConfig, routeName) + kubernetes.HTTPRouteMustHaveNoAcceptedParents(t, suite.Client, suite.TimeoutConfig, routeNN) }) t.Run("Gateway should have 0 Routes attached", func(t *testing.T) { - kubernetes.GatewayMustHaveZeroRoutes(t, suite.Client, suite.TimeoutConfig, gwName) + kubernetes.GatewayMustHaveZeroRoutes(t, suite.Client, suite.TimeoutConfig, gwNN) }) }, }