|
| 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 | + "github.com/stretchr/testify/require" |
| 24 | + "k8s.io/apimachinery/pkg/types" |
| 25 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 26 | + "sigs.k8s.io/gateway-api/pkg/features" |
| 27 | + |
| 28 | + "sigs.k8s.io/gateway-api-inference-extension/conformance/tests" |
| 29 | + k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes" |
| 30 | + trafficutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic" |
| 31 | +) |
| 32 | + |
| 33 | +func init() { |
| 34 | + tests.ConformanceTests = append(tests.ConformanceTests, EppUnAvailableFailOpen) |
| 35 | +} |
| 36 | + |
| 37 | +var EppUnAvailableFailOpen = suite.ConformanceTest{ |
| 38 | + ShortName: "EppUnAvailableFailOpen", |
| 39 | + Description: "Inference gateway should send traffic to backends even when the EPP is unavailable (fail-open)", |
| 40 | + Manifests: []string{"tests/basic/epp_unavailable_fail_open.yaml"}, |
| 41 | + Features: []features.FeatureName{ |
| 42 | + features.FeatureName("SupportInferencePool"), |
| 43 | + features.SupportGateway, |
| 44 | + }, |
| 45 | + Test: func(t *testing.T, s *suite.ConformanceTestSuite) { |
| 46 | + const ( |
| 47 | + appBackendNamespace = "gateway-conformance-app-backend" |
| 48 | + infraNamespace = "gateway-conformance-infra" |
| 49 | + hostname = "secondary.example.com" |
| 50 | + path = "/failopen-pool-test" |
| 51 | + expectedPodReplicas = 3 |
| 52 | + eppSelectionHeaderName = "test-epp-endpoint-selection" |
| 53 | + appPodBackendPrefix = "secondary-inference-model-server" |
| 54 | + requestBody = `{ |
| 55 | + "model": "conformance-fake-model", |
| 56 | + "prompt": "Write as if you were a critic: San Francisco" |
| 57 | + }` |
| 58 | + ) |
| 59 | + |
| 60 | + httpRouteNN := types.NamespacedName{Name: "httproute-for-failopen-pool-gw", Namespace: appBackendNamespace} |
| 61 | + gatewayNN := types.NamespacedName{Name: "conformance-secondary-gateway", Namespace: infraNamespace} |
| 62 | + poolNN := types.NamespacedName{Name: "secondary-inference-pool", Namespace: appBackendNamespace} |
| 63 | + eppDeploymentNN := types.NamespacedName{Name: "secondary-app-endpoint-picker", Namespace: appBackendNamespace} |
| 64 | + backendPodLabels := map[string]string{"app": "secondary-inference-model-server"} |
| 65 | + |
| 66 | + k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, httpRouteNN, gatewayNN) |
| 67 | + k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN) |
| 68 | + gwAddr := k8sutils.GetGatewayEndpoint(t, s.Client, s.TimeoutConfig, gatewayNN) |
| 69 | + |
| 70 | + pods, err := k8sutils.GetPodsWithLabel(t, s.Client, appBackendNamespace, backendPodLabels) |
| 71 | + require.NoError(t, err, "Failed to get backend pods") |
| 72 | + require.Len(t, pods, expectedPodReplicas, "Expected to find %d backend pod, but found %d.", expectedPodReplicas, len(pods)) |
| 73 | + |
| 74 | + targetPodIP := pods[0].Status.PodIP |
| 75 | + t.Run("Phase 1: Verify baseline connectivity with EPP available", func(t *testing.T) { |
| 76 | + t.Log("Sending request to ensure the Gateway and EPP are working correctly...") |
| 77 | + trafficutils.MakeRequestWithRequestParamAndExpectSuccess( |
| 78 | + t, |
| 79 | + s.RoundTripper, |
| 80 | + s.TimeoutConfig, |
| 81 | + gwAddr, |
| 82 | + trafficutils.Request{ |
| 83 | + Host: hostname, |
| 84 | + Path: path, |
| 85 | + Headers: map[string]string{eppSelectionHeaderName: targetPodIP}, |
| 86 | + Method: http.MethodPost, |
| 87 | + Body: requestBody, |
| 88 | + Backend: pods[0].Name, // Make sure the request is from the targetPod when the EPP is alive. |
| 89 | + Namespace: appBackendNamespace, |
| 90 | + }, |
| 91 | + ) |
| 92 | + }) |
| 93 | + |
| 94 | + t.Run("Phase 2: Verify fail-open behavior after EPP becomes unavailable", func(t *testing.T) { |
| 95 | + t.Log("Simulating an EPP failure by deleting its deployment...") |
| 96 | + deleteErr := k8sutils.DeleteDeployment(t, s.Client, s.TimeoutConfig, eppDeploymentNN) |
| 97 | + require.NoError(t, deleteErr, "Failed to delete the EPP deployment") |
| 98 | + |
| 99 | + t.Log("Sending request again, expecting success to verify fail-open...") |
| 100 | + trafficutils.MakeRequestWithRequestParamAndExpectSuccess( |
| 101 | + t, |
| 102 | + s.RoundTripper, |
| 103 | + s.TimeoutConfig, |
| 104 | + gwAddr, |
| 105 | + trafficutils.Request{ |
| 106 | + Host: hostname, |
| 107 | + Path: path, |
| 108 | + Headers: map[string]string{eppSelectionHeaderName: targetPodIP}, |
| 109 | + Method: http.MethodPost, |
| 110 | + Body: requestBody, |
| 111 | + Backend: appPodBackendPrefix, // Only checks the prefix since the EPP is not alive and the response can return from any Pod. |
| 112 | + Namespace: appBackendNamespace, |
| 113 | + }, |
| 114 | + ) |
| 115 | + }) |
| 116 | + }, |
| 117 | +} |
0 commit comments