Skip to content

Commit a919f8b

Browse files
authored
Merge pull request #2582 from tao12345666333/cmt-section-name-not-match-port-value
conformance: missmatch `SectionName` and `Port` will trigger `NoMatchingParent`
2 parents 95a6b8a + c56677f commit a919f8b

2 files changed

+99
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Copyright 2023 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+
v1 "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+
)
29+
30+
func init() {
31+
ConformanceTests = append(ConformanceTests, HTTPRouteInvalidParentRefSectionNameNotMatchingPort)
32+
}
33+
34+
var HTTPRouteInvalidParentRefSectionNameNotMatchingPort = suite.ConformanceTest{
35+
ShortName: "HTTPRouteInvalidParentRefSectionNameNotMatchingPort",
36+
Description: "A single HTTPRoute in the gateway-conformance-infra namespace should set the Accepted status to False with reason NoMatchingParent when attempting to bind to a Gateway that SectionName does not match Port value.",
37+
Features: []suite.SupportedFeature{
38+
suite.SupportGateway,
39+
suite.SupportHTTPRoute,
40+
},
41+
Manifests: []string{"tests/httproute-invalid-parentref-section-name-not-matching-port.yaml"},
42+
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
43+
routeNN := types.NamespacedName{Name: "httproute-listener-section-name-not-matching-port", Namespace: "gateway-conformance-infra"}
44+
gwNN := types.NamespacedName{Name: "gateway-with-one-not-matching-port-and-section-name-route", Namespace: "gateway-conformance-infra"}
45+
46+
// The Route must have an Accepted Condition with a NoMatchingParent Reason.
47+
t.Run("HTTPRoute with sectionName does not match Port in ParentRef has an Accepted Condition with status False and Reason NoMatchingParent", func(t *testing.T) {
48+
acceptedCond := metav1.Condition{
49+
Type: string(v1.RouteConditionAccepted),
50+
Status: metav1.ConditionFalse,
51+
Reason: string(v1.RouteReasonNoMatchingParent),
52+
}
53+
54+
kubernetes.HTTPRouteMustHaveCondition(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN, acceptedCond)
55+
})
56+
57+
t.Run("Route should not have Parents accepted in status", func(t *testing.T) {
58+
kubernetes.HTTPRouteMustHaveNoAcceptedParents(t, suite.Client, suite.TimeoutConfig, routeNN)
59+
})
60+
61+
t.Run("Gateway should have 0 Routes attached", func(t *testing.T) {
62+
kubernetes.GatewayMustHaveZeroRoutes(t, suite.Client, suite.TimeoutConfig, gwNN)
63+
})
64+
},
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: Gateway
3+
metadata:
4+
name: gateway-with-one-not-matching-port-and-section-name-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: All
17+
---
18+
apiVersion: gateway.networking.k8s.io/v1
19+
kind: HTTPRoute
20+
metadata:
21+
name: httproute-listener-section-name-not-matching-port
22+
namespace: gateway-conformance-infra
23+
spec:
24+
parentRefs:
25+
- name: gateway-with-one-not-matching-port-and-section-name-route
26+
namespace: gateway-conformance-infra
27+
sectionName: http
28+
# mismatched port value here (81 does not match gateway http listener's port) triggers NoMatchingParent reason
29+
port: 81
30+
rules:
31+
- backendRefs:
32+
- name: infra-backend-v1
33+
kind: Service
34+
port: 8080

0 commit comments

Comments
 (0)