Skip to content

Commit cb6dff4

Browse files
committed
conformance:use the updated gateway api utility functions and fix some typos.
1 parent 9286c12 commit cb6dff4

8 files changed

+164
-448
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/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
})

conformance/tests/inferencepool_httproute_port_validation.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ limitations under the License.
1717
package tests
1818

1919
import (
20+
"net/http"
2021
"testing"
2122

2223
"k8s.io/apimachinery/pkg/types"
24+
gwhttp "sigs.k8s.io/gateway-api/conformance/utils/http"
2325
"sigs.k8s.io/gateway-api/conformance/utils/suite"
2426
"sigs.k8s.io/gateway-api/pkg/features"
2527

2628
"sigs.k8s.io/gateway-api-inference-extension/conformance/resources"
2729
k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes"
28-
trafficutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic"
2930
)
3031

3132
func init() {
@@ -54,14 +55,19 @@ var InferencePoolHTTPRoutePortValidation = suite.ConformanceTest{
5455
k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN)
5556
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN, gatewayNN)
5657

57-
trafficutils.MakeRequestAndExpectSuccess(
58+
gwhttp.MakeRequestAndExpectEventuallyConsistentResponse(
5859
t,
5960
s.RoundTripper,
6061
s.TimeoutConfig,
6162
gatewayAddr,
62-
trafficutils.Request{
63-
Host: hostname,
64-
Path: path,
63+
gwhttp.ExpectedResponse{
64+
Request: gwhttp.Request{
65+
Host: hostname,
66+
Path: path,
67+
},
68+
Response: gwhttp.Response{
69+
StatusCodes: []int{http.StatusOK},
70+
},
6571
Backend: resources.PrimaryModelServerDeploymentName,
6672
Namespace: resources.AppBackendNamespace,
6773
},
@@ -76,14 +82,19 @@ var InferencePoolHTTPRoutePortValidation = suite.ConformanceTest{
7682
k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN)
7783
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN, gatewayNN)
7884

79-
trafficutils.MakeRequestAndExpectSuccess(
85+
gwhttp.MakeRequestAndExpectEventuallyConsistentResponse(
8086
t,
8187
s.RoundTripper,
8288
s.TimeoutConfig,
8389
gatewayAddr,
84-
trafficutils.Request{
85-
Host: hostname,
86-
Path: path,
90+
gwhttp.ExpectedResponse{
91+
Request: gwhttp.Request{
92+
Host: hostname,
93+
Path: path,
94+
},
95+
Response: gwhttp.Response{
96+
StatusCodes: []int{http.StatusOK},
97+
},
8798
Backend: resources.PrimaryModelServerDeploymentName,
8899
Namespace: resources.AppBackendNamespace,
89100
},
@@ -99,14 +110,19 @@ var InferencePoolHTTPRoutePortValidation = suite.ConformanceTest{
99110
k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN)
100111
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN, gatewayNN)
101112

102-
trafficutils.MakeRequestAndExpectSuccess(
113+
gwhttp.MakeRequestAndExpectEventuallyConsistentResponse(
103114
t,
104115
s.RoundTripper,
105116
s.TimeoutConfig,
106117
gatewayAddr,
107-
trafficutils.Request{
108-
Host: hostname,
109-
Path: path,
118+
gwhttp.ExpectedResponse{
119+
Request: gwhttp.Request{
120+
Host: hostname,
121+
Path: path,
122+
},
123+
Response: gwhttp.Response{
124+
StatusCodes: []int{http.StatusOK},
125+
},
110126
Backend: resources.PrimaryModelServerDeploymentName,
111127
Namespace: resources.AppBackendNamespace,
112128
},

conformance/tests/inferencepool_invalid_epp_service.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ limitations under the License.
1717
package tests
1818

1919
import (
20+
"net/http"
2021
"testing"
2122

2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/types"
2425
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
26+
gwhttp "sigs.k8s.io/gateway-api/conformance/utils/http"
2527
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
2628
"sigs.k8s.io/gateway-api/conformance/utils/suite"
2729
"sigs.k8s.io/gateway-api/pkg/features"
2830

2931
inferenceapi "sigs.k8s.io/gateway-api-inference-extension/api/v1"
3032
"sigs.k8s.io/gateway-api-inference-extension/conformance/resources"
3133
k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes"
32-
trafficutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic"
3334
)
3435

3536
func init() {
@@ -59,7 +60,7 @@ var InferencePoolInvalidEPPService = suite.ConformanceTest{
5960
Reason: string(gatewayv1.RouteReasonAccepted),
6061
}
6162
kubernetes.HTTPRouteMustHaveCondition(t, s.Client, s.TimeoutConfig, routeNN, gwNN, acceptedCondition)
62-
t.Run("InferecePool has a ResolvedRefs Condition with status False", func(t *testing.T) {
63+
t.Run("InferencePool has a ResolvedRefs Condition with status False", func(t *testing.T) {
6364
acceptedCondition := metav1.Condition{
6465
Type: string(inferenceapi.InferencePoolConditionResolvedRefs), // Standard condition type
6566
Status: metav1.ConditionFalse,
@@ -69,10 +70,21 @@ var InferencePoolInvalidEPPService = suite.ConformanceTest{
6970
})
7071

7172
t.Run("Request to a route with an invalid backend reference receives a 500 response", func(t *testing.T) {
72-
trafficutils.MakeRequestAndExpectEventuallyConsistentResponse(t, s.RoundTripper, s.TimeoutConfig, gwAddr, trafficutils.Request{
73-
Path: routePath,
74-
ExpectedStatusCode: 5, // Expecting response status code 5XX.
75-
})
73+
gwhttp.MakeRequestAndExpectEventuallyConsistentResponse(
74+
t,
75+
s.RoundTripper,
76+
s.TimeoutConfig,
77+
gwAddr,
78+
gwhttp.ExpectedResponse{
79+
Request: gwhttp.Request{
80+
Path: routePath,
81+
},
82+
Response: gwhttp.Response{
83+
StatusCodes: []int{http.StatusInternalServerError, http.StatusNotImplemented, http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout}, // Expecting response status code 5XX.
84+
},
85+
Namespace: resources.AppBackendNamespace,
86+
},
87+
)
7688
})
7789
},
7890
}

0 commit comments

Comments
 (0)