Skip to content

Commit 0707d2f

Browse files
authored
Conformance:use gateway api utility functions from v1.4.0 and minor fix typos. (#1704)
* conformance:use the updated gateway api utility functions and fix some typos. * modify newly added test. * modify the namesapces of GatewayWeightedAcrossTwoInferencePools merged right before #1667
1 parent 2d25426 commit 0707d2f

10 files changed

+181
-463
lines changed

conformance/conformance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func RunConformanceWithOptions(t *testing.T, opts confsuite.ConformanceOptions)
208208
installedCRDs := &apiextensionsv1.CustomResourceDefinitionList{}
209209
err = opts.Client.List(ctx, installedCRDs)
210210
require.NoError(t, err, "error getting installedCRDs")
211-
apiVersion, err := getGatewayInferenceExtentionVersion(installedCRDs.Items)
211+
apiVersion, err := getGatewayInferenceExtensionVersion(installedCRDs.Items)
212212
if err != nil {
213213
if opts.AllowCRDsMismatch {
214214
apiVersion = "UNDEFINED"
@@ -266,7 +266,7 @@ func SetupConformanceTestSuite(ctx context.Context, t *testing.T, suite *confsui
266266
ensureGatewayAvailableAndReady(ctx, t, suite.Client, opts, resources.SecondaryGatewayNN)
267267
}
268268

269-
func getGatewayInferenceExtentionVersion(crds []apiextensionsv1.CustomResourceDefinition) (string, error) {
269+
func getGatewayInferenceExtensionVersion(crds []apiextensionsv1.CustomResourceDefinition) (string, error) {
270270
var inferenceVersion string
271271
for _, crd := range crds {
272272
v, okv := crd.Annotations[version.BundleVersionAnnotation]

conformance/tests/epp_unavailable_fail_open.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import (
2222

2323
"github.com/stretchr/testify/require"
2424
"k8s.io/apimachinery/pkg/types"
25+
gwhttp "sigs.k8s.io/gateway-api/conformance/utils/http"
2526
"sigs.k8s.io/gateway-api/conformance/utils/suite"
2627
"sigs.k8s.io/gateway-api/pkg/features"
2728

2829
"sigs.k8s.io/gateway-api-inference-extension/conformance/resources"
2930
"sigs.k8s.io/gateway-api-inference-extension/conformance/utils/config"
3031
k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes"
31-
trafficutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic"
3232
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test"
3333
)
3434

@@ -69,19 +69,24 @@ var EppUnAvailableFailOpen = suite.ConformanceTest{
6969
targetPodIP := pods[0].Status.PodIP
7070
t.Run("Phase 1: Verify baseline connectivity with EPP available", func(t *testing.T) {
7171
t.Log("Sending request to ensure the Gateway and EPP are working correctly...")
72-
trafficutils.MakeRequestAndExpectSuccess(
72+
gwhttp.MakeRequestAndExpectEventuallyConsistentResponse(
7373
t,
7474
s.RoundTripper,
7575
s.TimeoutConfig,
7676
gwAddr,
77-
trafficutils.Request{
78-
Host: hostname,
79-
Path: path,
80-
Headers: map[string]string{
81-
test.HeaderTestEppEndPointSelectionKey: targetPodIP,
77+
gwhttp.ExpectedResponse{
78+
Request: gwhttp.Request{
79+
Host: hostname,
80+
Path: path,
81+
Headers: map[string]string{
82+
test.HeaderTestEppEndPointSelectionKey: targetPodIP,
83+
},
84+
Method: http.MethodPost,
85+
Body: requestBody,
86+
},
87+
Response: gwhttp.Response{
88+
StatusCodes: []int{http.StatusOK},
8289
},
83-
Method: http.MethodPost,
84-
Body: requestBody,
8590
Backend: pods[0].Name, // Make sure the request is from the targetPod when the EPP is alive.
8691
Namespace: resources.AppBackendNamespace,
8792
},
@@ -96,19 +101,24 @@ var EppUnAvailableFailOpen = suite.ConformanceTest{
96101
require.NoError(t, err, "Failed to make the EPP service %v unavailable", resources.PrimaryEppServiceNN)
97102

98103
t.Log("Sending request again, expecting success to verify fail-open...")
99-
trafficutils.MakeRequestAndExpectSuccess(
104+
gwhttp.MakeRequestAndExpectEventuallyConsistentResponse(
100105
t,
101106
s.RoundTripper,
102107
s.TimeoutConfig,
103108
gwAddr,
104-
trafficutils.Request{
105-
Host: hostname,
106-
Path: path,
107-
Headers: map[string]string{
108-
test.HeaderTestEppEndPointSelectionKey: targetPodIP,
109+
gwhttp.ExpectedResponse{
110+
Request: gwhttp.Request{
111+
Host: hostname,
112+
Path: path,
113+
Headers: map[string]string{
114+
test.HeaderTestEppEndPointSelectionKey: targetPodIP,
115+
},
116+
Method: http.MethodPost,
117+
Body: requestBody,
118+
},
119+
Response: gwhttp.Response{
120+
StatusCodes: []int{http.StatusOK},
109121
},
110-
Method: http.MethodPost,
111-
Body: requestBody,
112122
Backend: appPodBackendPrefix, // Only checks the prefix since the EPP is not alive and the response can return from any Pod.
113123
Namespace: resources.AppBackendNamespace,
114124
},

conformance/tests/gateway_following_epp_routing.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232

3333
"sigs.k8s.io/gateway-api-inference-extension/conformance/resources"
3434
k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes"
35-
"sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic"
3635
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test"
3736
)
3837

@@ -86,19 +85,24 @@ var GatewayFollowingEPPRouting = suite.ConformanceTest{
8685
for i := 0; i < len(pods); i++ {
8786
// Send an initial request targeting a single pod and wait for it to be successful to ensure the Gateway and EPP
8887
// are functioning correctly before running the main test cases.
89-
traffic.MakeRequestAndExpectSuccess(
88+
gwhttp.MakeRequestAndExpectEventuallyConsistentResponse(
9089
t,
9190
s.RoundTripper,
9291
s.TimeoutConfig,
9392
gwAddr,
94-
traffic.Request{
95-
Host: hostname,
96-
Path: path,
97-
Headers: map[string]string{
98-
test.HeaderTestEppEndPointSelectionKey: podIPs[i],
93+
gwhttp.ExpectedResponse{
94+
Request: gwhttp.Request{
95+
Host: hostname,
96+
Path: path,
97+
Method: http.MethodPost,
98+
Body: requestBody,
99+
Headers: map[string]string{
100+
test.HeaderTestEppEndPointSelectionKey: podIPs[i],
101+
},
102+
},
103+
Response: gwhttp.Response{
104+
StatusCodes: []int{http.StatusOK},
99105
},
100-
Method: http.MethodPost,
101-
Body: requestBody,
102106
Backend: podNames[i],
103107
Namespace: resources.AppBackendNamespace,
104108
},
@@ -142,21 +146,21 @@ var GatewayFollowingEPPRouting = suite.ConformanceTest{
142146
Host: hostname,
143147
Path: path,
144148
Method: http.MethodPost,
149+
Body: requestBody,
145150
Headers: headers,
146151
},
147152
Response: gwhttp.Response{
148153
StatusCode: http.StatusOK,
149154
},
150-
// DO NOT SUBMIT
151155
Backend: appPodBackendPrefix,
152156
Namespace: resources.AppBackendNamespace,
153-
}, requestBody, tc.expectAllRequestsRoutedWithinPodNames)
157+
}, tc.expectAllRequestsRoutedWithinPodNames)
154158
})
155159
}
156160
},
157161
}
158162

159-
func assertTrafficOnlyReachesToExpectedPods(t *testing.T, suite *suite.ConformanceTestSuite, gwAddr string, expected gwhttp.ExpectedResponse, requestBody string, expectedPodNames []string) {
163+
func assertTrafficOnlyReachesToExpectedPods(t *testing.T, suite *suite.ConformanceTestSuite, gwAddr string, expected gwhttp.ExpectedResponse, expectedPodNames []string) {
160164
t.Helper()
161165
const (
162166
concurrentRequests = 10
@@ -170,7 +174,7 @@ func assertTrafficOnlyReachesToExpectedPods(t *testing.T, suite *suite.Conforman
170174
g.SetLimit(concurrentRequests)
171175
for i := 0; i < totalRequests; i++ {
172176
g.Go(func() error {
173-
cReq, cRes, err := traffic.MakeCallRoundTripper(t, roundTripper, &traffic.RequestWithBody{Request: req, Body: strings.NewReader(requestBody)})
177+
cReq, cRes, err := roundTripper.CaptureRoundTrip(req)
174178
if err != nil {
175179
return fmt.Errorf("failed to roundtrip request: %w", err)
176180
}

conformance/tests/gateway_weighted_two_pools.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333

3434
"sigs.k8s.io/gateway-api-inference-extension/conformance/resources"
3535
k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes"
36-
"sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic"
3736
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test"
3837
)
3938

@@ -113,19 +112,24 @@ var GatewayWeightedAcrossTwoInferencePools = suite.ConformanceTest{
113112
allIPs := append(append([]string{}, primaryPodIPs...), secondaryPodIPs...)
114113
allNames := append(append([]string{}, primaryPodNames...), secondaryPodNames...)
115114
for i := 0; i < len(allIPs); i++ {
116-
traffic.MakeRequestAndExpectSuccess(
115+
gwhttp.MakeRequestAndExpectEventuallyConsistentResponse(
117116
t,
118117
s.RoundTripper,
119118
s.TimeoutConfig,
120119
gwAddr,
121-
traffic.Request{
122-
Host: hostname,
123-
Path: path,
124-
Headers: map[string]string{
125-
test.HeaderTestEppEndPointSelectionKey: allIPs[i],
120+
gwhttp.ExpectedResponse{
121+
Request: gwhttp.Request{
122+
Host: hostname,
123+
Path: path,
124+
Method: http.MethodPost,
125+
Body: `{"model":"conformance-fake-model","prompt":"Warmup"}`,
126+
Headers: map[string]string{
127+
test.HeaderTestEppEndPointSelectionKey: allIPs[i],
128+
},
129+
},
130+
Response: gwhttp.Response{
131+
StatusCodes: []int{http.StatusOK},
126132
},
127-
Method: http.MethodPost,
128-
Body: `{"model":"conformance-fake-model","prompt":"Warmup"}`,
129133
Backend: allNames[i],
130134
Namespace: resources.AppBackendNamespace,
131135
},
@@ -160,6 +164,7 @@ var GatewayWeightedAcrossTwoInferencePools = suite.ConformanceTest{
160164
Path: path,
161165
Method: http.MethodPost,
162166
Headers: headers,
167+
Body: requestBody,
163168
},
164169
Response: gwhttp.Response{
165170
StatusCode: http.StatusOK,
@@ -174,10 +179,7 @@ var GatewayWeightedAcrossTwoInferencePools = suite.ConformanceTest{
174179

175180
for i := 0; i < totalRequests; i++ {
176181
g.Go(func() error {
177-
cReq, cRes, err := traffic.MakeCallRoundTripper(t, s.RoundTripper, &traffic.RequestWithBody{
178-
Request: req,
179-
Body: strings.NewReader(requestBody),
180-
})
182+
cReq, cRes, err := s.RoundTripper.CaptureRoundTrip(req)
181183
if err != nil {
182184
return fmt.Errorf("failed to roundtrip request: %w", err)
183185
}

conformance/tests/gateway_weighted_two_pools.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ apiVersion: gateway.networking.k8s.io/v1
22
kind: HTTPRoute
33
metadata:
44
name: httproute-weighted-two-pools
5-
namespace: gateway-conformance-app-backend
5+
namespace: inference-conformance-app-backend
66
spec:
77
parentRefs:
88
- group: gateway.networking.k8s.io
99
kind: Gateway
1010
name: conformance-primary
11-
namespace: gateway-conformance-infra
11+
namespace: inference-conformance-infra
1212
sectionName: http
1313
hostnames:
1414
- "primary.example.com"

conformance/tests/httproute_multiple_gateways_different_pools.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import (
2121
"testing"
2222

2323
"k8s.io/apimachinery/pkg/types"
24+
gwhttp "sigs.k8s.io/gateway-api/conformance/utils/http"
2425
"sigs.k8s.io/gateway-api/conformance/utils/suite"
2526

2627
"sigs.k8s.io/gateway-api-inference-extension/conformance/resources"
2728
k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes"
28-
"sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic"
2929
)
3030

3131
func init() {
@@ -65,17 +65,21 @@ var HTTPRouteMultipleGatewaysDifferentPools = suite.ConformanceTest{
6565

6666
primaryGwAddr := k8sutils.GetGatewayEndpoint(t, s.Client, s.TimeoutConfig, primaryGatewayNN)
6767

68-
traffic.MakeRequestAndExpectEventuallyConsistentResponse(
68+
gwhttp.MakeRequestAndExpectEventuallyConsistentResponse(
6969
t,
7070
s.RoundTripper,
7171
s.TimeoutConfig,
7272
primaryGwAddr,
73-
traffic.Request{
74-
Host: primaryRouteHostname,
75-
Path: primaryRoutePath,
76-
ExpectedStatusCode: http.StatusOK,
77-
Backend: primaryBackendPodName,
78-
Namespace: resources.AppBackendNamespace,
73+
gwhttp.ExpectedResponse{
74+
Request: gwhttp.Request{
75+
Host: primaryRouteHostname,
76+
Path: primaryRoutePath,
77+
},
78+
Response: gwhttp.Response{
79+
StatusCodes: []int{http.StatusOK},
80+
},
81+
Backend: primaryBackendPodName,
82+
Namespace: resources.AppBackendNamespace,
7983
},
8084
)
8185
})
@@ -91,17 +95,21 @@ var HTTPRouteMultipleGatewaysDifferentPools = suite.ConformanceTest{
9195

9296
secondaryGwAddr := k8sutils.GetGatewayEndpoint(t, s.Client, s.TimeoutConfig, secondaryGatewayNN)
9397

94-
traffic.MakeRequestAndExpectEventuallyConsistentResponse(
98+
gwhttp.MakeRequestAndExpectEventuallyConsistentResponse(
9599
t,
96100
s.RoundTripper,
97101
s.TimeoutConfig,
98102
secondaryGwAddr,
99-
traffic.Request{
100-
Host: secondaryRouteHostname,
101-
Path: secondaryRoutePath,
102-
ExpectedStatusCode: http.StatusOK,
103-
Backend: secondaryBackendPodName,
104-
Namespace: resources.AppBackendNamespace,
103+
gwhttp.ExpectedResponse{
104+
Request: gwhttp.Request{
105+
Host: secondaryRouteHostname,
106+
Path: secondaryRoutePath,
107+
},
108+
Response: gwhttp.Response{
109+
StatusCodes: []int{http.StatusOK},
110+
},
111+
Backend: secondaryBackendPodName,
112+
Namespace: resources.AppBackendNamespace,
105113
},
106114
)
107115
})

0 commit comments

Comments
 (0)