Skip to content

Commit 6af017c

Browse files
committed
conformance: Add zero weight backend tests
1 parent 42d61e2 commit 6af017c

File tree

4 files changed

+155
-0
lines changed

4 files changed

+155
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright 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 tests
18+
19+
import (
20+
"testing"
21+
22+
"google.golang.org/grpc/codes"
23+
"k8s.io/apimachinery/pkg/types"
24+
25+
v1 "sigs.k8s.io/gateway-api/apis/v1"
26+
pb "sigs.k8s.io/gateway-api/conformance/echo-basic/grpcechoserver"
27+
"sigs.k8s.io/gateway-api/conformance/utils/grpc"
28+
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
29+
confsuite "sigs.k8s.io/gateway-api/conformance/utils/suite"
30+
"sigs.k8s.io/gateway-api/pkg/features"
31+
)
32+
33+
func init() {
34+
ConformanceTests = append(ConformanceTests, GRPCRouteAllBackendsWeightZero)
35+
}
36+
37+
var GRPCRouteAllBackendsWeightZero = confsuite.ConformanceTest{
38+
ShortName: "GRPCRouteAllBackendsWeightZero",
39+
Description: "A GRPCRoute with all backend weights set to 0 returns UNAVAILABLE",
40+
Manifests: []string{"tests/grpcroute-all-backends-weight-zero.yaml"},
41+
Features: []features.FeatureName{
42+
features.SupportGateway,
43+
features.SupportGRPCRoute,
44+
},
45+
Test: func(t *testing.T, suite *confsuite.ConformanceTestSuite) {
46+
var (
47+
ns = confsuite.InfrastructureNamespace
48+
routeNN = types.NamespacedName{Name: "all-backends-weight-zero", Namespace: ns}
49+
gwNN = types.NamespacedName{Name: "same-namespace", Namespace: ns}
50+
gwAddr = kubernetes.GatewayAndRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), &v1.GRPCRoute{}, true, routeNN)
51+
)
52+
53+
t.Run("Requests should return UNAVAILABLE when all backend weights are 0", func(t *testing.T) {
54+
grpc.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.GRPCClient, suite.TimeoutConfig, gwAddr, grpc.ExpectedResponse{
55+
EchoRequest: &pb.EchoRequest{},
56+
Response: grpc.Response{
57+
Code: codes.Unavailable,
58+
},
59+
})
60+
})
61+
},
62+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: GRPCRoute
3+
metadata:
4+
name: all-backends-weight-zero
5+
namespace: gateway-conformance-infra
6+
spec:
7+
parentRefs:
8+
- name: same-namespace
9+
rules:
10+
- backendRefs:
11+
- name: grpc-infra-backend-v1
12+
port: 8080
13+
weight: 0
14+
- name: grpc-infra-backend-v2
15+
port: 8080
16+
weight: 0
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 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 tests
18+
19+
import (
20+
"testing"
21+
22+
"k8s.io/apimachinery/pkg/types"
23+
24+
"sigs.k8s.io/gateway-api/conformance/utils/http"
25+
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
26+
confsuite "sigs.k8s.io/gateway-api/conformance/utils/suite"
27+
"sigs.k8s.io/gateway-api/pkg/features"
28+
)
29+
30+
func init() {
31+
ConformanceTests = append(ConformanceTests, HTTPRouteAllBackendsWeightZero)
32+
}
33+
34+
var HTTPRouteAllBackendsWeightZero = confsuite.ConformanceTest{
35+
ShortName: "HTTPRouteAllBackendsWeightZero",
36+
Description: "An HTTPRoute with all backend weights set to 0 returns 500",
37+
Manifests: []string{"tests/httproute-all-backends-weight-zero.yaml"},
38+
Features: []features.FeatureName{
39+
features.SupportGateway,
40+
features.SupportHTTPRoute,
41+
},
42+
Test: func(t *testing.T, suite *confsuite.ConformanceTestSuite) {
43+
var (
44+
ns = confsuite.InfrastructureNamespace
45+
routeNN = types.NamespacedName{Name: "all-backends-weight-zero", Namespace: ns}
46+
gwNN = types.NamespacedName{Name: "same-namespace", Namespace: ns}
47+
gwAddr = kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
48+
)
49+
50+
kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)
51+
52+
t.Run("Requests should return 500 when all backend weights are 0", func(t *testing.T) {
53+
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, http.ExpectedResponse{
54+
Request: http.Request{Path: "/"},
55+
Response: http.Response{
56+
StatusCode: 500,
57+
},
58+
})
59+
})
60+
},
61+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: all-backends-weight-zero
5+
namespace: gateway-conformance-infra
6+
spec:
7+
parentRefs:
8+
- name: same-namespace
9+
rules:
10+
- backendRefs:
11+
- name: infra-backend-v1
12+
port: 8080
13+
weight: 0
14+
- name: infra-backend-v2
15+
port: 8080
16+
weight: 0

0 commit comments

Comments
 (0)