Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor UDP IR #3373

Merged
merged 6 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ xds:
'@type': type.googleapis.com/envoy.extensions.filters.udp.udp_proxy.v3.Route
cluster: udproute/default/backend/rule/-1
statPrefix: service
name: default/eg/udp/backend
name: default/eg/udp
- '@type': type.googleapis.com/envoy.admin.v3.RoutesConfigDump
dynamicRouteConfigs:
- routeConfig:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@
}
}
],
"name": "default/eg/udp/backend"
"name": "default/eg/udp"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ xds:
'@type': type.googleapis.com/envoy.extensions.filters.udp.udp_proxy.v3.Route
cluster: udproute/default/backend/rule/-1
statPrefix: service
name: default/eg/udp/backend
name: default/eg/udp
- '@type': type.googleapis.com/envoy.admin.v3.RoutesConfigDump
dynamicRouteConfigs:
- routeConfig:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,4 @@ xds:
'@type': type.googleapis.com/envoy.extensions.filters.udp.udp_proxy.v3.Route
cluster: udproute/default/backend/rule/-1
statPrefix: service
name: default/eg/udp/backend
name: default/eg/udp
24 changes: 17 additions & 7 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,13 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(policy *egv1a1.Backen
}

for _, udp := range x.UDP {
if strings.HasPrefix(udp.Destination.Name, prefix) {
udp.LoadBalancer = lb
udp.Timeout = to
if udp.Route != nil {
route := udp.Route

if strings.HasPrefix(route.Destination.Name, prefix) {
route.LoadBalancer = lb
route.Timeout = to
}
}
}

Expand Down Expand Up @@ -490,14 +494,20 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(policy *egv1a1.Back
continue
}

if udp.Route == nil {
continue
}

route := udp.Route

// policy(targeting xRoute) has already set it, so we skip it.
if udp.LoadBalancer != nil || udp.Timeout != nil {
if route.LoadBalancer != nil || route.Timeout != nil {
continue
}

udp.LoadBalancer = lb
if udp.Timeout == nil {
udp.Timeout = ct
route.LoadBalancer = lb
if route.Timeout == nil {
route.Timeout = ct
}
}

Expand Down
8 changes: 4 additions & 4 deletions internal/gatewayapi/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,6 @@ func irListenerName(listener *ListenerContext) string {
return fmt.Sprintf("%s/%s/%s", listener.gateway.Namespace, listener.gateway.Name, listener.Name)
}

func irUDPListenerName(listener *ListenerContext, udpRoute *UDPRouteContext) string {
return fmt.Sprintf("%s/%s/%s/%s", listener.gateway.Namespace, listener.gateway.Name, listener.Name, udpRoute.Name)
}

func irListenerPortName(proto ir.ProtocolType, port int32) string {
return strings.ToLower(fmt.Sprintf("%s-%d", proto, port))
}
Expand All @@ -369,6 +365,10 @@ func irTCPRouteName(route RouteContext) string {
return fmt.Sprintf("%s/%s/%s", strings.ToLower(string(GetRouteType(route))), route.GetNamespace(), route.GetName())
}

func irUDPRouteName(route RouteContext) string {
return irTCPRouteName(route)
}

func irRouteDestinationName(route RouteContext, ruleIdx int) string {
return fmt.Sprintf("%srule/%d", irRoutePrefix(route), ruleIdx)
}
Expand Down
7 changes: 7 additions & 0 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR XdsIRMap
Port: uint32(containerPort),
}
xdsIR[irKey].TCP = append(xdsIR[irKey].TCP, irListener)
case gwapiv1.UDPProtocolType:
irListener := &ir.UDPListener{
Name: irListenerName(listener),
Address: "0.0.0.0",
Port: uint32(containerPort),
}
xdsIR[irKey].UDP = append(xdsIR[irKey].UDP, irListener)
}

// Add the listener to the Infra IR. Infra IR ports must have a unique port number per layer-4 protocol
Expand Down
25 changes: 11 additions & 14 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,21 +929,18 @@ func (t *Translator) processUDPRouteParentRefs(udpRoute *UDPRouteContext, resour

irKey := t.getIRKey(listener.gateway)

containerPort := servicePortToContainerPort(int32(listener.Port))
// Create the UDP Listener while parsing the UDPRoute since
// the listener directly links to a routeDestination.
irListener := &ir.UDPListener{
Name: irUDPListenerName(listener, udpRoute),
Address: "0.0.0.0",
Port: uint32(containerPort),
Destination: &ir.RouteDestination{
Name: irRouteDestinationName(udpRoute, -1 /*rule index*/),
Settings: destSettings,
},
}
gwXdsIR := xdsIR[irKey]
gwXdsIR.UDP = append(gwXdsIR.UDP, irListener)

irListener := gwXdsIR.GetUDPListener(irListenerName(listener))
if irListener != nil {
irRoute := &ir.UDPRoute{
Name: irUDPRouteName(udpRoute),
Destination: &ir.RouteDestination{
Name: irRouteDestinationName(udpRoute, -1 /*rule index*/),
Settings: destSettings,
},
}
irListener.Route = irRoute
}
}

// If no negative conditions have been set, the route is considered "Accepted=True".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,23 +293,25 @@ xdsIR:
connectTimeout: 15s
udp:
- address: 0.0.0.0
destination:
name: udproute/default/udp-app-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
loadBalancer:
consistentHash:
sourceIP: true
name: default/tcp-gateway/foo/udp-app-1
name: default/tcp-gateway/foo
port: 8162
timeout:
http:
connectionIdleTimeout: 16s
maxConnectionDuration: 17s
tcp:
connectTimeout: 15s
route:
destination:
name: udproute/default/udp-app-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
loadBalancer:
consistentHash:
sourceIP: true
name: udproute/default/udp-app-1
timeout:
http:
connectionIdleTimeout: 16s
maxConnectionDuration: 17s
tcp:
connectTimeout: 15s
Original file line number Diff line number Diff line change
Expand Up @@ -366,23 +366,25 @@ xdsIR:
connectTimeout: 15s
udp:
- address: 0.0.0.0
destination:
name: udproute/default/udp-app-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
loadBalancer:
consistentHash:
sourceIP: true
name: default/tcp-gateway/foo/udp-app-1
name: default/tcp-gateway/foo
port: 8162
timeout:
http:
connectionIdleTimeout: 16s
maxConnectionDuration: 17s
tcp:
connectTimeout: 15s
route:
destination:
name: udproute/default/udp-app-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
loadBalancer:
consistentHash:
sourceIP: true
name: udproute/default/udp-app-1
timeout:
http:
connectionIdleTimeout: 16s
maxConnectionDuration: 17s
tcp:
connectTimeout: 15s
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ xdsIR:
- path: /dev/stdout
udp:
- address: 0.0.0.0
destination:
name: udproute/default/udproute-1/rule/-1
settings:
- weight: 1
name: envoy-gateway/gateway-1/udp/udproute-1
name: envoy-gateway/gateway-1/udp
port: 10162
route:
destination:
name: udproute/default/udproute-1/rule/-1
settings:
- weight: 1
name: udproute/default/udproute-1
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,22 @@ xdsIR:
- path: /dev/stdout
udp:
- address: 0.0.0.0
destination:
name: udproute/default/udproute-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 50
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 50
name: envoy-gateway/gateway-1/udp/udproute-1
name: envoy-gateway/gateway-1/udp
port: 10080
route:
destination:
name: udproute/default/udproute-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 50
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 50
name: udproute/default/udproute-1
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@ xdsIR:
accessLog:
text:
- path: /dev/stdout
udp:
- address: 0.0.0.0
name: envoy-gateway/gateway-1/udp
port: 10080
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ xdsIR:
accessLog:
text:
- path: /dev/stdout
udp:
- address: 0.0.0.0
name: envoy-gateway/gateway-1/udp
port: 10080
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ xdsIR:
- path: /dev/stdout
udp:
- address: 0.0.0.0
destination:
name: udproute/default/udproute-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: envoy-gateway/gateway-1/udp/udproute-1
name: envoy-gateway/gateway-1/udp
port: 10162
route:
destination:
name: udproute/default/udproute-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: udproute/default/udproute-1
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ xdsIR:
- path: /dev/stdout
udp:
- address: 0.0.0.0
destination:
name: udproute/default/udproute-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: envoy-gateway/gateway-1/udp1/udproute-1
name: envoy-gateway/gateway-1/udp1
port: 10162
route:
destination:
name: udproute/default/udproute-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: udproute/default/udproute-1
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,16 @@ xdsIR:
prefix: /
udp:
- address: 0.0.0.0
destination:
name: udproute/default/udproute-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: envoy-gateway/gateway-1/udp/udproute-1
name: envoy-gateway/gateway-1/udp
port: 10080
route:
destination:
name: udproute/default/udproute-1/rule/-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8162
protocol: UDP
weight: 1
name: udproute/default/udproute-1
Loading
Loading