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

tcproute/udproute support multiple backends #3212

Merged
merged 18 commits into from
May 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/envoy-gateway-system/backend/rule/0
settings:
- endpoints:
Expand Down
101 changes: 41 additions & 60 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,27 +175,27 @@

for _, backendRef := range rule.BackendRefs {
backendRef := backendRef
ds, backendWeight := t.processDestination(backendRef, parentRef, httpRoute, resources)
ds, _ := t.processDestination(backendRef, parentRef, httpRoute, resources)
if !t.EndpointRoutingDisabled && ds != nil && len(ds.Endpoints) > 0 && ds.AddressType != nil {
dstAddrTypeMap[*ds.AddressType]++
}
if ds == nil {
continue
}

for _, route := range ruleRoutes {
// If the route already has a direct response or redirect configured, then it was from a filter so skip
// processing any destinations for this route.
if route.DirectResponse == nil && route.Redirect == nil {
if ds != nil && len(ds.Endpoints) > 0 {
if route.Destination == nil {
route.Destination = &ir.RouteDestination{
Name: irRouteDestinationName(httpRoute, ruleIdx),
}
}
route.Destination.Settings = append(route.Destination.Settings, ds)
route.BackendWeights.Valid += backendWeight
} else {
route.BackendWeights.Invalid += backendWeight
if route.DirectResponse != nil || route.Redirect != nil {
continue
}

if route.Destination == nil {
route.Destination = &ir.RouteDestination{
Name: irRouteDestinationName(httpRoute, ruleIdx),
}
}
route.Destination.Settings = append(route.Destination.Settings, ds)
}
}

Expand Down Expand Up @@ -464,24 +464,24 @@

for _, backendRef := range rule.BackendRefs {
backendRef := backendRef
ds, backendWeight := t.processDestination(backendRef, parentRef, grpcRoute, resources)
ds, _ := t.processDestination(backendRef, parentRef, grpcRoute, resources)
if ds == nil {
continue
}

for _, route := range ruleRoutes {
// If the route already has a direct response or redirect configured, then it was from a filter so skip
// processing any destinations for this route.
if route.DirectResponse == nil && route.Redirect == nil {
if ds != nil && len(ds.Endpoints) > 0 {
if route.Destination == nil {
route.Destination = &ir.RouteDestination{
Name: irRouteDestinationName(grpcRoute, ruleIdx),
}
}
route.Destination.Settings = append(route.Destination.Settings, ds)
route.BackendWeights.Valid += backendWeight
if route.DirectResponse != nil || route.Redirect != nil {
continue
}

} else {
route.BackendWeights.Invalid += backendWeight
if route.Destination == nil {
route.Destination = &ir.RouteDestination{
Name: irRouteDestinationName(grpcRoute, ruleIdx),
}
}
route.Destination.Settings = append(route.Destination.Settings, ds)
}
}

Expand Down Expand Up @@ -658,10 +658,6 @@
Retry: routeRoute.Retry,
IsHTTP2: routeRoute.IsHTTP2,
}
// Don't bother copying over the weights unless the route has invalid backends.
if routeRoute.BackendWeights.Invalid > 0 {
hostRoute.BackendWeights = routeRoute.BackendWeights
}
perHostRoutes = append(perHostRoutes, hostRoute)
}
}
Expand Down Expand Up @@ -846,24 +842,16 @@
)
continue
}
if len(udpRoute.Spec.Rules[0].BackendRefs) != 1 {
parentRef.SetCondition(udpRoute,
gwapiv1.RouteConditionResolvedRefs,
metav1.ConditionFalse,
"InvalidBackend",
"One and only one backend is supported",
)
continue
}

backendRef := udpRoute.Spec.Rules[0].BackendRefs[0]
ds, _ := t.processDestination(backendRef, parentRef, udpRoute, resources)
// Skip further processing if route destination is not valid
if ds == nil || len(ds.Endpoints) == 0 {
continue
for _, backendRef := range udpRoute.Spec.Rules[0].BackendRefs {
ds, _ := t.processDestination(backendRef, parentRef, udpRoute, resources)
if ds == nil {
continue
}

destSettings = append(destSettings, ds)
}

destSettings = append(destSettings, ds)
// If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True"
if !parentRef.HasCondition(udpRoute, gwapiv1.RouteConditionResolvedRefs, metav1.ConditionFalse) {
parentRef.SetCondition(udpRoute,
Expand Down Expand Up @@ -963,7 +951,6 @@

func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resources *Resources, xdsIR XdsIRMap) {
for _, parentRef := range tcpRoute.ParentRefs {

// Need to compute Route rules within the parentRef loop because
// any conditions that come out of it have to go on each RouteParentStatus,
// not on the Route as a whole.
Expand All @@ -979,23 +966,17 @@
)
continue
}
if len(tcpRoute.Spec.Rules[0].BackendRefs) != 1 {
parentRef.SetCondition(tcpRoute,
gwapiv1.RouteConditionResolvedRefs,
metav1.ConditionFalse,
"InvalidBackend",
"One and only one backend is supported",
)
continue
}

backendRef := tcpRoute.Spec.Rules[0].BackendRefs[0]
ds, _ := t.processDestination(backendRef, parentRef, tcpRoute, resources)
// Skip further processing if route destination is not valid
if ds == nil || len(ds.Endpoints) == 0 {
continue
for _, backendRef := range tcpRoute.Spec.Rules[0].BackendRefs {
backendRef := backendRef
ds, _ := t.processDestination(backendRef, parentRef, tcpRoute, resources)
if ds == nil {
continue
}

destSettings = append(destSettings, ds)
}
destSettings = append(destSettings, ds)

// If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True"
if !parentRef.HasCondition(tcpRoute, gwapiv1.RouteConditionResolvedRefs, metav1.ConditionFalse) {
parentRef.SetCondition(tcpRoute,
Expand Down Expand Up @@ -1070,7 +1051,7 @@
parentRef *RouteParentContext,
route RouteContext,
resources *Resources,
) (ds *ir.DestinationSetting, backendWeight uint32) {

Check failure on line 1054 in internal/gatewayapi/route.go

View workflow job for this annotation

GitHub Actions / lint

(*Translator).processDestination - result backendWeight is never used (unparam)
routeType := GetRouteType(route)
weight := uint32(1)
backendRef := GetBackendRef(backendRefContext)
Expand All @@ -1080,7 +1061,7 @@

backendNamespace := NamespaceDerefOr(backendRef.Namespace, route.GetNamespace())
if !t.validateBackendRef(backendRefContext, parentRef, route, resources, backendNamespace, routeType) {
return nil, weight
return &ir.DestinationSetting{Weight: &weight}, weight
}

// Skip processing backends with 0 weight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/envoy-gateway/httproute-btls/rule/0
settings:
- addressType: IP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/envoy-gateway/httproute-btls/rule/0
settings:
- addressType: IP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/envoy-gateway/httproute-btls/rule/0
settings:
- addressType: IP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/envoy-gateway/httproute-btls/rule/0
settings:
- addressType: IP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/envoy-gateway/httproute-btls/rule/0
settings:
- addressType: IP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/default/httproute-1/rule/0
settings:
- addressType: IP
Expand All @@ -242,10 +239,7 @@ xdsIR:
distinct: false
name: ""
prefix: /foo
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/default/httproute-2/rule/0
settings:
- addressType: IP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,10 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 1
valid: 0
directResponse:
statusCode: 500
- destination:
name: httproute/envoy-gateway/httproute-1/rule/0
settings:
- weight: 1
hostname: '*'
isHTTP2: false
name: httproute/envoy-gateway/httproute-1/rule/0/match/0/*
Expand All @@ -607,11 +606,10 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 1
valid: 0
directResponse:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is directResponse getting removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, see 115fdb1

statusCode: 500
- destination:
name: grpcroute/envoy-gateway/grpcroute-1/rule/0
settings:
- weight: 1
headerMatches:
- distinct: false
exact: foo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: grpcroute/default/grpcroute-1/rule/0
settings:
- addressType: IP
Expand Down Expand Up @@ -379,10 +376,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/default/httproute-2/rule/0
settings:
- addressType: IP
Expand All @@ -402,10 +396,7 @@ xdsIR:
distinct: false
name: ""
prefix: /route2
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/default/httproute-1/rule/0
settings:
- addressType: IP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/default/httproute-1/rule/0
settings:
- addressType: IP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: grpcroute/default/grpcroute-1/rule/0
settings:
- addressType: IP
Expand All @@ -354,10 +351,7 @@ xdsIR:
mergeSlashes: true
port: 10080
routes:
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/default/httproute-2/rule/0
settings:
- addressType: IP
Expand All @@ -373,10 +367,7 @@ xdsIR:
distinct: false
name: ""
prefix: /foo
- backendWeights:
invalid: 0
valid: 0
destination:
- destination:
name: httproute/default/httproute-1/rule/0
settings:
- addressType: IP
Expand Down
Loading
Loading