Skip to content

Commit 374131a

Browse files
authored
refactor(conformance): Relocate constants to minimize package dependencies (#1355)
* refactor: moving the const around to make sure conformance tests is depending on minimum pkgs. * add boilerplate header.
1 parent 7479e30 commit 374131a

File tree

6 files changed

+44
-22
lines changed

6 files changed

+44
-22
lines changed

conformance/resources/resourcename.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const (
3434

3535
ModelServerPodReplicas = 3
3636
EndPointPickerPodReplicas = 1
37+
38+
InferenceObjName = "conformance-fake-model-server"
3739
)
3840

3941
var (

conformance/tests/epp_unavailable_fail_open.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes"
3131
trafficutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic"
3232
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metadata"
33-
testfilter "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test/filter"
33+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test"
3434
)
3535

3636
func init() {
@@ -54,7 +54,6 @@ var EppUnAvailableFailOpen = suite.ConformanceTest{
5454
"model": "conformance-fake-model",
5555
"prompt": "Write as if you were a critic: San Francisco"
5656
}`
57-
inferenceObjName = "conformance-fake-model-server"
5857
)
5958

6059
httpRouteNN := types.NamespacedName{Name: "httproute-for-failopen-pool-gw", Namespace: resources.AppBackendNamespace}
@@ -80,8 +79,8 @@ var EppUnAvailableFailOpen = suite.ConformanceTest{
8079
Host: hostname,
8180
Path: path,
8281
Headers: map[string]string{
83-
testfilter.HeaderTestEppEndPointSelectionKey: targetPodIP,
84-
metadata.ObjectiveKey: inferenceObjName,
82+
test.HeaderTestEppEndPointSelectionKey: targetPodIP,
83+
metadata.ObjectiveKey: resources.InferenceObjName,
8584
},
8685
Method: http.MethodPost,
8786
Body: requestBody,
@@ -108,8 +107,8 @@ var EppUnAvailableFailOpen = suite.ConformanceTest{
108107
Host: hostname,
109108
Path: path,
110109
Headers: map[string]string{
111-
testfilter.HeaderTestEppEndPointSelectionKey: targetPodIP,
112-
metadata.ObjectiveKey: inferenceObjName,
110+
test.HeaderTestEppEndPointSelectionKey: targetPodIP,
111+
metadata.ObjectiveKey: resources.InferenceObjName,
113112
},
114113
Method: http.MethodPost,
115114
Body: requestBody,

conformance/tests/gateway_following_epp_routing.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes"
3535
"sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic"
3636
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metadata"
37-
testfilter "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test/filter"
37+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test"
3838
)
3939

4040
func init() {
@@ -55,7 +55,6 @@ var GatewayFollowingEPPRouting = suite.ConformanceTest{
5555
hostname = "primary.example.com"
5656
path = "/primary-gateway-test"
5757
appPodBackendPrefix = "primary-inference-model-server"
58-
inferenceObjName = "conformance-fake-model-server"
5958
)
6059

6160
httpRouteNN := types.NamespacedName{Name: "httproute-for-primary-gw", Namespace: resources.AppBackendNamespace}
@@ -97,8 +96,8 @@ var GatewayFollowingEPPRouting = suite.ConformanceTest{
9796
Host: hostname,
9897
Path: path,
9998
Headers: map[string]string{
100-
testfilter.HeaderTestEppEndPointSelectionKey: podIPs[i],
101-
metadata.ObjectiveKey: inferenceObjName,
99+
test.HeaderTestEppEndPointSelectionKey: podIPs[i],
100+
metadata.ObjectiveKey: resources.InferenceObjName,
102101
},
103102
Method: http.MethodPost,
104103
Body: requestBody,
@@ -134,11 +133,11 @@ var GatewayFollowingEPPRouting = suite.ConformanceTest{
134133
t.Run(tc.name, func(t *testing.T) {
135134
eppHeaderValue := strings.Join(tc.podIPsToBeReturnedByEPP, ",")
136135
headers := map[string]string{
137-
testfilter.HeaderTestEppEndPointSelectionKey: eppHeaderValue,
138-
metadata.ObjectiveKey: inferenceObjName,
136+
test.HeaderTestEppEndPointSelectionKey: eppHeaderValue,
137+
metadata.ObjectiveKey: resources.InferenceObjName,
139138
}
140139

141-
t.Logf("Sending request to %s with EPP header '%s: %s'", gwAddr, testfilter.HeaderTestEppEndPointSelectionKey, eppHeaderValue)
140+
t.Logf("Sending request to %s with EPP header '%s: %s'", gwAddr, test.HeaderTestEppEndPointSelectionKey, eppHeaderValue)
142141
t.Logf("Expecting traffic to be routed to pod: %v", tc.expectAllRequestsRoutedWithinPodNames)
143142

144143
assertTrafficOnlyReachesToExpectedPods(t, s, gwAddr, gwhttp.ExpectedResponse{
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 test
18+
19+
const (
20+
// HeaderTestEppEndPointSelectionKey is the header used for testing purposes to make EPP behavior controllable.
21+
// The header value should be a comma-separated list of endpoint IP addresses.
22+
// E.g., "test-epp-endpoint-selection": "10.0.0.7,10.0.0.8"
23+
// The returned order is the same as the order provided in the header.
24+
HeaderTestEppEndPointSelectionKey = "test-epp-endpoint-selection"
25+
)

pkg/epp/scheduling/framework/plugins/test/filter/filter_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/google/go-cmp/cmp"
2424

2525
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend"
26+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test"
2627
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
2728
)
2829

@@ -47,7 +48,7 @@ func TestFilter(t *testing.T) {
4748
},
4849
{
4950
name: "TestHeaderBasedFilter, header endpoint set in request but no match",
50-
req: &types.LLMRequest{Headers: map[string]string{HeaderTestEppEndPointSelectionKey: "test-endpoint"}},
51+
req: &types.LLMRequest{Headers: map[string]string{test.HeaderTestEppEndPointSelectionKey: "test-endpoint"}},
5152
input: []types.Pod{
5253
&types.PodMetrics{
5354
Pod: &backend.Pod{
@@ -59,7 +60,7 @@ func TestFilter(t *testing.T) {
5960
},
6061
{
6162
name: "TestHeaderBasedFilter, header endpoint set",
62-
req: &types.LLMRequest{Headers: map[string]string{HeaderTestEppEndPointSelectionKey: "test-endpoint"}},
63+
req: &types.LLMRequest{Headers: map[string]string{test.HeaderTestEppEndPointSelectionKey: "test-endpoint"}},
6364
input: []types.Pod{
6465
&types.PodMetrics{
6566
Pod: &backend.Pod{
@@ -77,7 +78,7 @@ func TestFilter(t *testing.T) {
7778
},
7879
{
7980
name: "TestHeaderBasedFilter, multiple header endpoints set and multiple matches",
80-
req: &types.LLMRequest{Headers: map[string]string{HeaderTestEppEndPointSelectionKey: "test-endpoint3,test-endpoint2"}},
81+
req: &types.LLMRequest{Headers: map[string]string{test.HeaderTestEppEndPointSelectionKey: "test-endpoint3,test-endpoint2"}},
8182
input: []types.Pod{
8283
&types.PodMetrics{
8384
Pod: &backend.Pod{

pkg/epp/scheduling/framework/plugins/test/filter/request_header_based_filter.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@ import (
2323

2424
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
2525
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
26+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test"
2627
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
2728
)
2829

2930
const (
30-
// HeaderTestEppEndPointSelectionKey is the header used for testing purposes to make EPP behavior controllable.
31-
// The header value should be a comma-separated list of endpoint IP addresses.
32-
// E.g., "test-epp-endpoint-selection": "10.0.0.7,10.0.0.8"
33-
// The returned order is the same as the order provided in the header.
34-
HeaderTestEppEndPointSelectionKey = "test-epp-endpoint-selection"
3531
// HeaderBasedTestingFilterType is the filter type that is used in plugins registry.
3632
HeaderBasedTestingFilterType = "header-based-testing-filter"
3733
)
@@ -70,7 +66,7 @@ func (f *HeaderBasedTestingFilter) WithName(name string) *HeaderBasedTestingFilt
7066

7167
// Filter selects pods that match the IP addresses specified in the request header.
7268
func (f *HeaderBasedTestingFilter) Filter(_ context.Context, _ *types.CycleState, request *types.LLMRequest, pods []types.Pod) []types.Pod {
73-
headerValue, ok := request.Headers[HeaderTestEppEndPointSelectionKey]
69+
headerValue, ok := request.Headers[test.HeaderTestEppEndPointSelectionKey]
7470
if !ok || headerValue == "" {
7571
return []types.Pod{}
7672
}

0 commit comments

Comments
 (0)