Skip to content

Commit d317cd9

Browse files
authored
Support HTTPRoute destination port matching
1 parent eccfcc0 commit d317cd9

File tree

7 files changed

+24
-21
lines changed

7 files changed

+24
-21
lines changed

integration/conformance-reports/v1.2.0-rc2/experimental-v3.2-default-report.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ profiles:
3030
result: success
3131
statistics:
3232
Failed: 0
33-
Passed: 12
33+
Passed: 13
3434
Skipped: 0
3535
supportedFeatures:
3636
- GatewayPort8080
3737
- HTTPRouteBackendProtocolH2C
3838
- HTTPRouteBackendProtocolWebSocket
39+
- HTTPRouteDestinationPortMatching
3940
- HTTPRouteHostRewrite
4041
- HTTPRouteMethodMatching
4142
- HTTPRoutePathRedirect
@@ -50,7 +51,6 @@ profiles:
5051
- GatewayStaticAddresses
5152
- HTTPRouteBackendRequestHeaderModification
5253
- HTTPRouteBackendTimeout
53-
- HTTPRouteDestinationPortMatching
5454
- HTTPRouteParentRefPort
5555
- HTTPRouteRequestMirror
5656
- HTTPRouteRequestMultipleMirrors

pkg/provider/kubernetes/gateway/features.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func SupportedFeatures() []features.FeatureName {
1818
features.HTTPRouteResponseHeaderModificationFeature.Name,
1919
features.HTTPRouteBackendProtocolH2CFeature.Name,
2020
features.HTTPRouteBackendProtocolWebSocketFeature.Name,
21+
features.HTTPRouteDestinationPortMatchingFeature.Name,
2122
features.TLSRouteFeature.Name,
2223
}
2324
}

pkg/provider/kubernetes/gateway/grpcroute.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,16 @@ func (p *Provider) loadGRPCRoutes(ctx context.Context, gatewayListeners []gatewa
4949
}
5050

5151
for _, listener := range gatewayListeners {
52+
accepted := true
5253
if !matchListener(listener, route.Namespace, parentRef) {
53-
continue
54+
accepted = false
5455
}
55-
56-
accepted := true
57-
if !allowRoute(listener, route.Namespace, kindGRPCRoute) {
56+
if accepted && !allowRoute(listener, route.Namespace, kindGRPCRoute) {
5857
parentStatus.Conditions = updateRouteConditionAccepted(parentStatus.Conditions, string(gatev1.RouteReasonNotAllowedByListeners))
5958
accepted = false
6059
}
6160
hostnames, ok := findMatchingHostnames(listener.Hostname, route.Spec.Hostnames)
62-
if !ok {
61+
if accepted && !ok {
6362
parentStatus.Conditions = updateRouteConditionAccepted(parentStatus.Conditions, string(gatev1.RouteReasonNoMatchingListenerHostname))
6463
accepted = false
6564
}

pkg/provider/kubernetes/gateway/httproute.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,16 @@ func (p *Provider) loadHTTPRoutes(ctx context.Context, gatewayListeners []gatewa
5353
}
5454

5555
for _, listener := range gatewayListeners {
56+
accepted := true
5657
if !matchListener(listener, route.Namespace, parentRef) {
57-
continue
58+
accepted = false
5859
}
59-
60-
accepted := true
61-
if !allowRoute(listener, route.Namespace, kindHTTPRoute) {
60+
if accepted && !allowRoute(listener, route.Namespace, kindHTTPRoute) {
6261
parentStatus.Conditions = updateRouteConditionAccepted(parentStatus.Conditions, string(gatev1.RouteReasonNotAllowedByListeners))
6362
accepted = false
6463
}
6564
hostnames, ok := findMatchingHostnames(listener.Hostname, route.Spec.Hostnames)
66-
if !ok {
65+
if accepted && !ok {
6766
parentStatus.Conditions = updateRouteConditionAccepted(parentStatus.Conditions, string(gatev1.RouteReasonNoMatchingListenerHostname))
6867
accepted = false
6968
}

pkg/provider/kubernetes/gateway/kubernetes.go

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ type ExtensionBuilderRegistry interface {
112112
type gatewayListener struct {
113113
Name string
114114

115+
Port gatev1.PortNumber
115116
Protocol gatev1.ProtocolType
116117
TLS *gatev1.GatewayTLSConfig
117118
Hostname *gatev1.Hostname
@@ -429,6 +430,7 @@ func (p *Provider) loadGatewayListeners(ctx context.Context, gateway *gatev1.Gat
429430
GWName: gateway.Name,
430431
GWNamespace: gateway.Namespace,
431432
GWGeneration: gateway.Generation,
433+
Port: listener.Port,
432434
Protocol: listener.Protocol,
433435
TLS: listener.TLS,
434436
Hostname: listener.Hostname,
@@ -1118,6 +1120,10 @@ func matchListener(listener gatewayListener, routeNamespace string, parentRef ga
11181120
return false
11191121
}
11201122

1123+
if parentRef.Port != nil && *parentRef.Port != listener.Port {
1124+
return false
1125+
}
1126+
11211127
return true
11221128
}
11231129

pkg/provider/kubernetes/gateway/tcproute.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ func (p *Provider) loadTCPRoutes(ctx context.Context, gatewayListeners []gateway
4949
}
5050

5151
for _, listener := range gatewayListeners {
52+
accepted := true
5253
if !matchListener(listener, route.Namespace, parentRef) {
53-
continue
54+
accepted = false
5455
}
55-
56-
accepted := true
57-
if !allowRoute(listener, route.Namespace, kindTCPRoute) {
56+
if accepted && !allowRoute(listener, route.Namespace, kindTCPRoute) {
5857
parentStatus.Conditions = updateRouteConditionAccepted(parentStatus.Conditions, string(gatev1.RouteReasonNotAllowedByListeners))
5958
accepted = false
6059
}

pkg/provider/kubernetes/gateway/tlsroute.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,16 @@ func (p *Provider) loadTLSRoutes(ctx context.Context, gatewayListeners []gateway
4949
}
5050

5151
for _, listener := range gatewayListeners {
52+
accepted := true
5253
if !matchListener(listener, route.Namespace, parentRef) {
53-
continue
54+
accepted = false
5455
}
55-
56-
accepted := true
57-
if !allowRoute(listener, route.Namespace, kindTLSRoute) {
56+
if accepted && !allowRoute(listener, route.Namespace, kindTLSRoute) {
5857
parentStatus.Conditions = updateRouteConditionAccepted(parentStatus.Conditions, string(gatev1.RouteReasonNotAllowedByListeners))
5958
accepted = false
6059
}
6160
hostnames, ok := findMatchingHostnames(listener.Hostname, route.Spec.Hostnames)
62-
if !ok {
61+
if accepted && !ok {
6362
parentStatus.Conditions = updateRouteConditionAccepted(parentStatus.Conditions, string(gatev1.RouteReasonNoMatchingListenerHostname))
6463
accepted = false
6564
}

0 commit comments

Comments
 (0)