Skip to content

Commit 3c68844

Browse files
committed
initial test setup
1 parent bb257fd commit 3c68844

File tree

2 files changed

+286
-0
lines changed

2 files changed

+286
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# conformance/tests/basic/inferencepool_httproute_port_validation.yaml
2+
3+
# --- Backend Deployment (reusing standard echoserver) ---
4+
5+
apiVersion: apps/v1
6+
kind: Deployment
7+
metadata:
8+
name: infra-backend-deployment-port-test
9+
namespace: gateway-conformance-app-backend
10+
labels:
11+
app: infra-backend-port-test
12+
spec:
13+
replicas: 1
14+
selector:
15+
matchLabels:
16+
app: infra-backend-port-test
17+
template:
18+
metadata:
19+
labels:
20+
app: infra-backend-port-test
21+
spec:
22+
containers:
23+
- name: echoserver
24+
image: gcr.io/k8s-staging-gateway-api/echo-basic:v20240412-v1.0.0-394-g40c666fd
25+
ports:
26+
- containerPort: 3000
27+
readinessProbe:
28+
httpGet:
29+
path: /
30+
port: 3000
31+
initialDelaySeconds: 3
32+
periodSeconds: 5
33+
failureThreshold: 2
34+
env:
35+
- name: POD_NAME
36+
valueFrom:
37+
fieldRef:
38+
fieldPath: metadata.name
39+
- name: NAMESPACE
40+
valueFrom:
41+
fieldRef:
42+
fieldPath: metadata.namespace
43+
---
44+
# --- Backend Service ---
45+
# Service for the infra-backend-deployment-port-test.
46+
apiVersion: v1
47+
kind: Service
48+
metadata:
49+
name: infra-backend-svc-port-test
50+
namespace: gateway-conformance-app-backend
51+
spec:
52+
selector:
53+
app: infra-backend-port-test
54+
ports:
55+
- name: http
56+
port: 3000
57+
targetPort: 3000
58+
---
59+
# --- InferencePool Definition ---
60+
apiVersion: inference.networking.x-k8s.io/v1alpha2
61+
kind: InferencePool
62+
metadata:
63+
name: target-pool-port-validation
64+
namespace: gateway-conformance-app-backend
65+
spec:
66+
selector:
67+
app: "infra-backend-port-test"
68+
targetPortNumber: 3000
69+
extensionRef:
70+
name: target-pool-port-validation-epp
71+
---
72+
# --- HTTPRoute Scenario 1: Port Unspecified ---
73+
apiVersion: gateway.networking.k8s.io/v1
74+
kind: HTTPRoute
75+
metadata:
76+
name: httproute-pool-port-unspecified
77+
namespace: gateway-conformance-app-backend
78+
spec:
79+
parentRefs:
80+
- group: gateway.networking.k8s.io
81+
kind: Gateway
82+
name: conformance-gateway
83+
namespace: gateway-conformance-infra
84+
sectionName: http
85+
hostnames:
86+
- "port-unspecified.example.com"
87+
rules:
88+
- backendRefs:
89+
- group: inference.networking.x-k8s.io
90+
kind: InferencePool
91+
name: target-pool-port-validation
92+
# Port is intentionally unspecified here
93+
matches:
94+
- path:
95+
type: PathPrefix
96+
value: /test-port-unspecified
97+
---
98+
# --- HTTPRoute Scenario 2: Port Matching ---
99+
apiVersion: gateway.networking.k8s.io/v1
100+
kind: HTTPRoute
101+
metadata:
102+
name: httproute-pool-port-matching
103+
namespace: gateway-conformance-app-backend
104+
spec:
105+
parentRefs:
106+
- group: gateway.networking.k8s.io
107+
kind: Gateway
108+
name: conformance-gateway
109+
namespace: gateway-conformance-infra
110+
sectionName: http
111+
hostnames:
112+
- "port-matching.example.com"
113+
rules:
114+
- backendRefs:
115+
- group: inference.networking.x-k8s.io
116+
kind: InferencePool
117+
name: target-pool-port-validation
118+
port: 3000 # Port matches InferencePool's targetPortNumber
119+
matches:
120+
- path:
121+
type: PathPrefix
122+
value: /test-port-matching
123+
---
124+
# --- HTTPRoute Scenario 3: Port Non-Matching ---
125+
apiVersion: gateway.networking.k8s.io/v1
126+
kind: HTTPRoute
127+
metadata:
128+
name: httproute-pool-port-non-matching
129+
namespace: gateway-conformance-app-backend
130+
spec:
131+
parentRefs:
132+
- group: gateway.networking.k8s.io
133+
kind: Gateway
134+
name: conformance-gateway
135+
namespace: gateway-conformance-infra
136+
sectionName: http
137+
hostnames:
138+
- "port-non-matching.example.com"
139+
rules:
140+
- backendRefs:
141+
- group: inference.networking.x-k8s.io
142+
kind: InferencePool
143+
name: target-pool-port-validation
144+
port: 8888 # Port does NOT match InferencePool's targetPortNumber
145+
matches:
146+
- path:
147+
type: PathPrefix
148+
value: /test-port-non-matching

0 commit comments

Comments
 (0)