|
| 1 | +/* |
| 2 | +Copyright 2025 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package basic |
| 18 | + |
| 19 | +import ( |
| 20 | + "net/http" |
| 21 | + "testing" |
| 22 | + |
| 23 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 24 | + "k8s.io/apimachinery/pkg/types" |
| 25 | + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" |
| 26 | + "sigs.k8s.io/gateway-api/conformance/utils/kubernetes" |
| 27 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 28 | + "sigs.k8s.io/gateway-api/pkg/features" |
| 29 | + |
| 30 | + gwapihttp "sigs.k8s.io/gateway-api/conformance/utils/http" |
| 31 | + |
| 32 | + // Local project imports |
| 33 | + "sigs.k8s.io/gateway-api-inference-extension/conformance/tests" |
| 34 | + k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes" |
| 35 | + trafficutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic" |
| 36 | +) |
| 37 | + |
| 38 | +func init() { |
| 39 | + tests.ConformanceTests = append(tests.ConformanceTests, InferencePoolHTTPRoutePortValidation) |
| 40 | +} |
| 41 | + |
| 42 | +var InferencePoolHTTPRoutePortValidation = suite.ConformanceTest{ |
| 43 | + ShortName: "InferencePoolHTTPRoutePortValidation", |
| 44 | + Description: "Validates HTTPRoute backendRef port configurations (unspecified, matching, non-matching) when referencing an InferencePool, and checks resulting status conditions.", |
| 45 | + Manifests: []string{"tests/basic/inferencepool_httproute_port_validation.yaml"}, |
| 46 | + Features: []features.FeatureName{ |
| 47 | + features.FeatureName("SupportInferencePool"), |
| 48 | + features.SupportGateway, |
| 49 | + }, |
| 50 | + Test: func(t *testing.T, s *suite.ConformanceTestSuite) { |
| 51 | + const ( |
| 52 | + appBackendNamespace = "gateway-conformance-app-backend" |
| 53 | + infraNamespace = "gateway-conformance-infra" |
| 54 | + gatewayName = "conformance-gateway" |
| 55 | + poolName = "target-pool-port-validation" |
| 56 | + // backendDeploymentName should be the metadata.name of the Deployment in the YAML. |
| 57 | + backendDeploymentName = "infra-backend-deployment-port-test" |
| 58 | + ) |
| 59 | + |
| 60 | + gatewayNN := types.NamespacedName{Name: gatewayName, Namespace: infraNamespace} |
| 61 | + poolNN := types.NamespacedName{Name: poolName, Namespace: appBackendNamespace} |
| 62 | + |
| 63 | + gatewayAddr := k8sutils.GetGatewayEndpoint(t, s.Client, s.TimeoutConfig, gatewayNN) |
| 64 | + |
| 65 | + t.Run("Scenario 1: HTTPRoute backendRef to InferencePool with Port Unspecified", func(t *testing.T) { |
| 66 | + routeNN := types.NamespacedName{Name: "httproute-pool-port-unspecified", Namespace: appBackendNamespace} |
| 67 | + hostname := "port-unspecified.example.com" |
| 68 | + path := "/test-port-unspecified" |
| 69 | + |
| 70 | + k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN) |
| 71 | + k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN) |
| 72 | + |
| 73 | + trafficutils.MakeRequestAndExpectSuccess( |
| 74 | + t, |
| 75 | + s.RoundTripper, |
| 76 | + s.TimeoutConfig, |
| 77 | + gatewayAddr, |
| 78 | + hostname, |
| 79 | + path, |
| 80 | + backendDeploymentName, // Use the correct Deployment name here |
| 81 | + appBackendNamespace, |
| 82 | + ) |
| 83 | + }) |
| 84 | + |
| 85 | + t.Run("Scenario 2: HTTPRoute backendRef to InferencePool with Port Specified and Matching", func(t *testing.T) { |
| 86 | + routeNN := types.NamespacedName{Name: "httproute-pool-port-matching", Namespace: appBackendNamespace} |
| 87 | + hostname := "port-matching.example.com" |
| 88 | + path := "/test-port-matching" |
| 89 | + |
| 90 | + k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN) |
| 91 | + k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN) |
| 92 | + |
| 93 | + trafficutils.MakeRequestAndExpectSuccess( |
| 94 | + t, |
| 95 | + s.RoundTripper, |
| 96 | + s.TimeoutConfig, |
| 97 | + gatewayAddr, |
| 98 | + hostname, |
| 99 | + path, |
| 100 | + backendDeploymentName, // Use the correct Deployment name here |
| 101 | + appBackendNamespace, |
| 102 | + ) |
| 103 | + }) |
| 104 | + |
| 105 | + t.Run("Scenario 3: HTTPRoute backendRef to InferencePool with Port Specified and Non-Matching", func(t *testing.T) { |
| 106 | + routeNN := types.NamespacedName{Name: "httproute-pool-port-non-matching", Namespace: appBackendNamespace} |
| 107 | + hostname := "port-non-matching.example.com" |
| 108 | + path := "/test-port-non-matching" |
| 109 | + |
| 110 | + acceptedCondition := metav1.Condition{ |
| 111 | + Type: string(gatewayv1.RouteConditionAccepted), |
| 112 | + Status: metav1.ConditionTrue, |
| 113 | + Reason: string(gatewayv1.RouteReasonAccepted), |
| 114 | + } |
| 115 | + kubernetes.HTTPRouteMustHaveCondition(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN, acceptedCondition) |
| 116 | + |
| 117 | + resolvedRefsCondition := metav1.Condition{ |
| 118 | + Type: string(gatewayv1.RouteConditionResolvedRefs), |
| 119 | + Status: metav1.ConditionFalse, |
| 120 | + Reason: string(gatewayv1.RouteReasonBackendNotFound), |
| 121 | + } |
| 122 | + kubernetes.HTTPRouteMustHaveCondition(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN, resolvedRefsCondition) |
| 123 | + k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN) |
| 124 | + |
| 125 | + expectedResponse := trafficutils.BuildExpectedHTTPResponse( |
| 126 | + hostname, |
| 127 | + path, |
| 128 | + http.StatusServiceUnavailable, |
| 129 | + "", |
| 130 | + "", |
| 131 | + ) |
| 132 | + gwapihttp.MakeRequestAndExpectEventuallyConsistentResponse(t, s.RoundTripper, s.TimeoutConfig, gatewayAddr, expectedResponse) |
| 133 | + |
| 134 | + t.Logf("Successfully verified HTTPRoute %s has conditions: Accepted=True and ResolvedRefs=False (Reason: %s) for Gateway %s due to port mismatch", |
| 135 | + routeNN.String(), resolvedRefsCondition.Reason, gatewayNN.String()) |
| 136 | + }) |
| 137 | + }, |
| 138 | +} |
0 commit comments