|
| 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 | + "k8s.io/apimachinery/pkg/types" |
| 24 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 25 | + |
| 26 | + "sigs.k8s.io/gateway-api-inference-extension/conformance/tests" |
| 27 | + k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes" |
| 28 | + "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic" |
| 29 | +) |
| 30 | + |
| 31 | +func init() { |
| 32 | + tests.ConformanceTests = append(tests.ConformanceTests, HTTPRouteMultipleGatewaysDifferentPools) |
| 33 | +} |
| 34 | + |
| 35 | +var HTTPRouteMultipleGatewaysDifferentPools = suite.ConformanceTest{ |
| 36 | + ShortName: "HTTPRouteMultipleGatewaysDifferentPools", |
| 37 | + Description: "Validates two HTTPRoutes on different Gateways successfully referencing different InferencePools and routes traffic accordingly.", |
| 38 | + Manifests: []string{"tests/basic/httproute_multiple_gateways_different_pools.yaml"}, |
| 39 | + Test: func(t *testing.T, s *suite.ConformanceTestSuite) { |
| 40 | + const ( |
| 41 | + appBackendNamespace = "gateway-conformance-app-backend" |
| 42 | + infraNamespace = "gateway-conformance-infra" |
| 43 | + |
| 44 | + primaryGatewayName = "conformance-primary-gateway" |
| 45 | + routeForPrimaryGWName = "route-for-primary-gateway" |
| 46 | + primaryPoolName = "primary-inference-pool" |
| 47 | + primaryBackendPodName = "primary-inference-model-server" |
| 48 | + primaryRoutePath = "/test-primary-gateway" |
| 49 | + primaryRouteHostname = "primary.example.com" |
| 50 | + |
| 51 | + secondaryGatewayName = "conformance-secondary-gateway" |
| 52 | + routeForSecondaryGWName = "route-for-secondary-gateway" |
| 53 | + secondaryPoolName = "secondary-inference-pool" |
| 54 | + secondaryBackendPodName = "secondary-inference-model-server" |
| 55 | + secondaryRoutePath = "/test-secondary-gateway" |
| 56 | + secondaryRouteHostname = "secondary.example.com" |
| 57 | + ) |
| 58 | + |
| 59 | + routeForPrimaryGWNN := types.NamespacedName{Name: routeForPrimaryGWName, Namespace: appBackendNamespace} |
| 60 | + routeForSecondaryGWNN := types.NamespacedName{Name: routeForSecondaryGWName, Namespace: appBackendNamespace} |
| 61 | + primaryPoolNN := types.NamespacedName{Name: primaryPoolName, Namespace: appBackendNamespace} |
| 62 | + secondaryPoolNN := types.NamespacedName{Name: secondaryPoolName, Namespace: appBackendNamespace} |
| 63 | + primaryGatewayNN := types.NamespacedName{Name: primaryGatewayName, Namespace: infraNamespace} |
| 64 | + secondaryGatewayNN := types.NamespacedName{Name: secondaryGatewayName, Namespace: infraNamespace} |
| 65 | + |
| 66 | + t.Run("Primary HTTPRoute, InferencePool, and Gateway path: verify status and traffic", func(t *testing.T) { |
| 67 | + k8sutils.HTTPRouteAndInferencePoolMustBeAcceptedAndRouteAccepted( |
| 68 | + t, |
| 69 | + s.Client, |
| 70 | + routeForPrimaryGWNN, |
| 71 | + primaryGatewayNN, |
| 72 | + primaryPoolNN, |
| 73 | + ) |
| 74 | + |
| 75 | + primaryGwAddr := k8sutils.GetGatewayEndpoint(t, s.Client, s.TimeoutConfig, primaryGatewayNN) |
| 76 | + |
| 77 | + traffic.MakeRequestAndExpectEventuallyConsistentResponse( |
| 78 | + t, |
| 79 | + s.RoundTripper, |
| 80 | + s.TimeoutConfig, |
| 81 | + primaryGwAddr, |
| 82 | + traffic.Request{ |
| 83 | + Host: primaryRouteHostname, |
| 84 | + Path: primaryRoutePath, |
| 85 | + ExpectedStatusCode: http.StatusOK, |
| 86 | + Backend: primaryBackendPodName, |
| 87 | + Namespace: appBackendNamespace, |
| 88 | + }, |
| 89 | + ) |
| 90 | + }) |
| 91 | + |
| 92 | + t.Run("Secondary HTTPRoute, InferencePool, and Gateway path: verify status and traffic", func(t *testing.T) { |
| 93 | + k8sutils.HTTPRouteAndInferencePoolMustBeAcceptedAndRouteAccepted( |
| 94 | + t, |
| 95 | + s.Client, |
| 96 | + routeForSecondaryGWNN, |
| 97 | + secondaryGatewayNN, |
| 98 | + secondaryPoolNN, |
| 99 | + ) |
| 100 | + |
| 101 | + secondaryGwAddr := k8sutils.GetGatewayEndpoint(t, s.Client, s.TimeoutConfig, secondaryGatewayNN) |
| 102 | + |
| 103 | + traffic.MakeRequestAndExpectEventuallyConsistentResponse( |
| 104 | + t, |
| 105 | + s.RoundTripper, |
| 106 | + s.TimeoutConfig, |
| 107 | + secondaryGwAddr, |
| 108 | + traffic.Request{ |
| 109 | + Host: secondaryRouteHostname, |
| 110 | + Path: secondaryRoutePath, |
| 111 | + ExpectedStatusCode: http.StatusOK, |
| 112 | + Backend: secondaryBackendPodName, |
| 113 | + Namespace: appBackendNamespace, |
| 114 | + }, |
| 115 | + ) |
| 116 | + }) |
| 117 | + }, |
| 118 | +} |
0 commit comments