Skip to content

Commit 4c4c0d5

Browse files
k8s-ci-robotshaneutt
authored andcommitted
Merge pull request #1624 from ChaningHwang/addAttachedRoutes
conformance: add attachedRoutes to conformance tests
1 parent e8d3558 commit 4c4c0d5

8 files changed

+172
-0
lines changed

conformance/tests/gateway-invalid-route-kind.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var GatewayInvalidRouteKind = suite.ConformanceTest{
4646
Status: metav1.ConditionFalse,
4747
Reason: string(v1beta1.ListenerReasonInvalidRouteKinds),
4848
}},
49+
AttachedRoutes: 0,
4950
}}
5051

5152
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners)
@@ -64,6 +65,7 @@ var GatewayInvalidRouteKind = suite.ConformanceTest{
6465
Status: metav1.ConditionFalse,
6566
Reason: string(v1beta1.ListenerReasonInvalidRouteKinds),
6667
}},
68+
AttachedRoutes: 0,
6769
}}
6870

6971
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners)

conformance/tests/gateway-invalid-tls-certificateref.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var GatewayInvalidTLSConfiguration = suite.ConformanceTest{
4747
Status: metav1.ConditionFalse,
4848
Reason: string(v1beta1.ListenerReasonInvalidCertificateRef),
4949
}},
50+
AttachedRoutes: 0,
5051
}}
5152

5253
testCases := []struct {

conformance/tests/gateway-secret-invalid-reference-grant.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ var GatewaySecretInvalidReferenceGrant = suite.ConformanceTest{
5151
Status: metav1.ConditionFalse,
5252
Reason: string(v1beta1.ListenerReasonRefNotPermitted),
5353
}},
54+
AttachedRoutes: 0,
5455
}}
5556

5657
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners)

conformance/tests/gateway-secret-missing-reference-grant.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ var GatewaySecretMissingReferenceGrant = suite.ConformanceTest{
5151
Status: metav1.ConditionFalse,
5252
Reason: string(v1beta1.ListenerReasonRefNotPermitted),
5353
}},
54+
AttachedRoutes: 0,
5455
}}
5556

5657
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners)

conformance/tests/gateway-secret-reference-grant-all-in-namespace.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var GatewaySecretReferenceGrantAllInNamespace = suite.ConformanceTest{
5353
Reason: string(v1beta1.ListenerConditionProgrammed),
5454
},
5555
},
56+
AttachedRoutes: 0,
5657
}}
5758

5859
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners)

conformance/tests/gateway-secret-reference-grant-specific.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var GatewaySecretReferenceGrantSpecific = suite.ConformanceTest{
5353
Reason: string(v1beta1.ListenerReasonProgrammed),
5454
},
5555
},
56+
AttachedRoutes: 0,
5657
}}
5758

5859
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Copyright 2022 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+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/apimachinery/pkg/types"
24+
25+
"sigs.k8s.io/gateway-api/apis/v1beta1"
26+
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
27+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
28+
)
29+
30+
func init() {
31+
ConformanceTests = append(ConformanceTests, GatewayWithAttachedRoutes)
32+
}
33+
34+
var GatewayWithAttachedRoutes = suite.ConformanceTest{
35+
ShortName: "GatewayWithAttachedRoutes",
36+
Description: "A Gateway in the gateway-conformance-infra namespace should be attached to routes.",
37+
Manifests: []string{"tests/gateway-with-attached-routes.yaml"},
38+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
39+
t.Run("Gateway listener should have one valid http routes attached", func(t *testing.T) {
40+
gwNN := types.NamespacedName{Name: "gateway-with-one-attached-route", Namespace: "gateway-conformance-infra"}
41+
listeners := []v1beta1.ListenerStatus{{
42+
Name: v1beta1.SectionName("http"),
43+
SupportedKinds: []v1beta1.RouteGroupKind{{
44+
Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group),
45+
Kind: v1beta1.Kind("HTTPRoute"),
46+
}},
47+
Conditions: []metav1.Condition{{
48+
Type: string(v1beta1.RouteConditionAccepted),
49+
Status: metav1.ConditionTrue,
50+
Reason: "", //any reason
51+
}},
52+
AttachedRoutes: 1,
53+
}}
54+
55+
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners)
56+
})
57+
58+
t.Run("Gateway listener should have two valid http routes attached", func(t *testing.T) {
59+
gwNN := types.NamespacedName{Name: "gateway-with-two-attached-routes", Namespace: "gateway-conformance-infra"}
60+
listeners := []v1beta1.ListenerStatus{{
61+
Name: v1beta1.SectionName("http"),
62+
SupportedKinds: []v1beta1.RouteGroupKind{{
63+
Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group),
64+
Kind: v1beta1.Kind("HTTPRoute"),
65+
}},
66+
Conditions: []metav1.Condition{{
67+
Type: string(v1beta1.RouteConditionAccepted),
68+
Status: metav1.ConditionTrue,
69+
Reason: "", //any reason
70+
}},
71+
AttachedRoutes: 2,
72+
}}
73+
74+
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners)
75+
})
76+
},
77+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
apiVersion: gateway.networking.k8s.io/v1beta1
2+
kind: Gateway
3+
metadata:
4+
name: gateway-with-one-attached-route
5+
namespace: gateway-conformance-infra
6+
spec:
7+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
8+
listeners:
9+
- name: http
10+
port: 80
11+
protocol: HTTP
12+
allowedRoutes:
13+
kinds:
14+
- kind: HTTPRoute
15+
namespaces:
16+
from: Selector
17+
selector:
18+
matchLabels:
19+
# This label is added automatically as of K8s 1.22
20+
# to all namespaces
21+
kubernetes.io/metadata.name: gateway-conformance-infra
22+
---
23+
apiVersion: gateway.networking.k8s.io/v1beta1
24+
kind: HTTPRoute
25+
metadata:
26+
name: http-route-1
27+
namespace: gateway-conformance-infra
28+
spec:
29+
parentRefs:
30+
- kind: Gateway
31+
name: gateway-with-one-attached-route
32+
namespace: gateway-conformance-infra
33+
rules:
34+
- backendRefs:
35+
- name: foo-svc
36+
port: 8080
37+
---
38+
apiVersion: gateway.networking.k8s.io/v1beta1
39+
kind: Gateway
40+
metadata:
41+
name: gateway-with-two-attached-routes
42+
namespace: gateway-conformance-infra
43+
spec:
44+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
45+
listeners:
46+
- name: http
47+
port: 80
48+
protocol: HTTP
49+
allowedRoutes:
50+
kinds:
51+
- kind: HTTPRoute
52+
namespaces:
53+
from: Selector
54+
selector:
55+
matchLabels:
56+
# This label is added automatically as of K8s 1.22
57+
# to all namespaces
58+
kubernetes.io/metadata.name: gateway-conformance-infra
59+
---
60+
apiVersion: gateway.networking.k8s.io/v1beta1
61+
kind: HTTPRoute
62+
metadata:
63+
name: http-route-2
64+
namespace: gateway-conformance-infra
65+
spec:
66+
parentRefs:
67+
- kind: Gateway
68+
name: gateway-with-two-attached-routes
69+
namespace: gateway-conformance-infra
70+
rules:
71+
- backendRefs:
72+
- name: foo-svc
73+
port: 8080
74+
---
75+
apiVersion: gateway.networking.k8s.io/v1beta1
76+
kind: HTTPRoute
77+
metadata:
78+
name: http-route-3
79+
namespace: gateway-conformance-infra
80+
spec:
81+
parentRefs:
82+
- kind: Gateway
83+
name: gateway-with-two-attached-routes
84+
namespace: gateway-conformance-infra
85+
rules:
86+
- backendRefs:
87+
- name: foo-svc
88+
port: 8080

0 commit comments

Comments
 (0)