|
| 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 | + "context" |
| 21 | + "testing" |
| 22 | + "time" |
| 23 | + |
| 24 | + "github.com/stretchr/testify/require" |
| 25 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 26 | + "k8s.io/apimachinery/pkg/types" |
| 27 | + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" |
| 28 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 29 | + "sigs.k8s.io/gateway-api/pkg/features" |
| 30 | + |
| 31 | + "sigs.k8s.io/gateway-api-inference-extension/conformance/tests" |
| 32 | + k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes" |
| 33 | +) |
| 34 | + |
| 35 | +func init() { |
| 36 | + tests.ConformanceTests = append(tests.ConformanceTests, InferencePoolParentStatus) |
| 37 | +} |
| 38 | + |
| 39 | +var InferencePoolParentStatus = suite.ConformanceTest{ |
| 40 | + ShortName: "InferencePoolResolvedRefsCondition", |
| 41 | + Description: "Verify that an InferencePool correctly updates its parent-specific status (e.g., Accepted condition) when referenced by HTTPRoutes attached to shared Gateways, and clears parent statuses when no longer referenced.", |
| 42 | + Manifests: []string{"tests/basic/inferencepool_resolvedrefs_condition.yaml"}, |
| 43 | + Features: []features.FeatureName{ |
| 44 | + features.FeatureName("SupportInferencePool"), |
| 45 | + features.SupportGateway, |
| 46 | + }, |
| 47 | + Test: func(t *testing.T, s *suite.ConformanceTestSuite) { |
| 48 | + const ( |
| 49 | + appBackendNamespace = "gateway-conformance-app-backend" |
| 50 | + infraNamespace = "gateway-conformance-infra" |
| 51 | + poolName = "multi-gateway-pool" |
| 52 | + sharedGateway1Name = "conformance-gateway" |
| 53 | + sharedGateway2Name = "conformance-secondary-gateway" |
| 54 | + httpRoute1Name = "httproute-for-gw1" |
| 55 | + httpRoute2Name = "httproute-for-gw2" |
| 56 | + ) |
| 57 | + |
| 58 | + poolNN := types.NamespacedName{Name: poolName, Namespace: appBackendNamespace} |
| 59 | + httpRoute1NN := types.NamespacedName{Name: httpRoute1Name, Namespace: appBackendNamespace} |
| 60 | + httpRoute2NN := types.NamespacedName{Name: httpRoute2Name, Namespace: appBackendNamespace} |
| 61 | + gateway1NN := types.NamespacedName{Name: sharedGateway1Name, Namespace: infraNamespace} |
| 62 | + gateway2NN := types.NamespacedName{Name: sharedGateway2Name, Namespace: infraNamespace} |
| 63 | + |
| 64 | + k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, httpRoute1NN, gateway1NN) |
| 65 | + k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, httpRoute2NN, gateway2NN) |
| 66 | + |
| 67 | + t.Run("InferencePool should show Accepted:True by parents when referenced by multiple HTTPRoutes", func(t *testing.T) { |
| 68 | + k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN) |
| 69 | + // TODO(#865) ensure requests are correctly routed to this InferencePool. |
| 70 | + t.Logf("InferencePool %s has parent status Accepted:True as expected with two references.", poolNN.String()) |
| 71 | + }) |
| 72 | + |
| 73 | + t.Run("Delete httproute-for-gw1", func(t *testing.T) { |
| 74 | + httproute1 := &gatewayv1.HTTPRoute{ |
| 75 | + ObjectMeta: metav1.ObjectMeta{Name: httpRoute1NN.Name, Namespace: httpRoute1NN.Namespace}, |
| 76 | + } |
| 77 | + t.Logf("Deleting HTTPRoute %s", httpRoute1NN.String()) |
| 78 | + require.NoError(t, s.Client.Delete(context.TODO(), httproute1), "failed to delete httproute-for-gw1") |
| 79 | + time.Sleep(s.TimeoutConfig.GatewayMustHaveCondition) |
| 80 | + }) |
| 81 | + |
| 82 | + t.Run("InferencePool should still show Accepted:True by parent after one HTTPRoute is deleted", func(t *testing.T) { |
| 83 | + k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN) |
| 84 | + // TODO(#865) ensure requests are correctly routed to this InferencePool. |
| 85 | + t.Logf("InferencePool %s still has parent status Accepted:True as expected with one reference remaining.", poolNN.String()) |
| 86 | + }) |
| 87 | + |
| 88 | + t.Run("Delete httproute-for-gw2", func(t *testing.T) { |
| 89 | + httproute2 := &gatewayv1.HTTPRoute{ |
| 90 | + ObjectMeta: metav1.ObjectMeta{Name: httpRoute2NN.Name, Namespace: httpRoute2NN.Namespace}, |
| 91 | + } |
| 92 | + t.Logf("Deleting HTTPRoute %s", httpRoute2NN.String()) |
| 93 | + require.NoError(t, s.Client.Delete(context.TODO(), httproute2), "failed to delete httproute-for-gw2") |
| 94 | + }) |
| 95 | + |
| 96 | + t.Run("InferencePool should have no parent statuses after all HTTPRoutes are deleted", func(t *testing.T) { |
| 97 | + t.Logf("Waiting for InferencePool %s to have no parent statuses.", poolNN.String()) |
| 98 | + k8sutils.InferencePoolMustHaveNoParents(t, s.Client, poolNN) |
| 99 | + t.Logf("InferencePool %s correctly shows no parent statuses, indicating it's no longer referenced.", poolNN.String()) |
| 100 | + }) |
| 101 | + |
| 102 | + t.Logf("InferencePoolResolvedRefsCondition completed.") |
| 103 | + }, |
| 104 | +} |
0 commit comments