Skip to content
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
47 changes: 27 additions & 20 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,12 @@ func (t *Translator) processHTTPRouteRules(httpRoute *HTTPRouteContext, parentRe
err.Reason(),
))
failedProcessDestination = true
continue
}
if unstructuredRef != nil {
backendCustomRefs = append(backendCustomRefs, unstructuredRef)
}
// ds can be nil if the backendRef weight is 0
if ds == nil {
// skip backendRefs with weight 0 as they do not affect the traffic distribution
if ds.Weight != nil && *ds.Weight == 0 {
continue
}
allDs = append(allDs, ds)
Expand Down Expand Up @@ -266,7 +265,7 @@ func (t *Translator) processHTTPRouteRules(httpRoute *HTTPRouteContext, parentRe
case irRoute.DirectResponse != nil || irRoute.Redirect != nil:
// return 500 if any destination setting is invalid
// the error is already added to the error list when processing the destination
case failedProcessDestination:
case failedProcessDestination && destination.ToBackendWeights().Valid == 0:
irRoute.DirectResponse = &ir.CustomResponse{
StatusCode: ptr.To(uint32(500)),
}
Expand Down Expand Up @@ -686,10 +685,10 @@ func (t *Translator) processGRPCRouteRules(grpcRoute *GRPCRouteContext, parentRe
err.Reason(),
))
failedProcessDestination = true
continue
}

if ds == nil {
// skip backendRefs with weight 0 as they do not affect the traffic distribution
if ds.Weight != nil && *ds.Weight == 0 {
continue
}
allDs = append(allDs, ds)
Expand All @@ -711,7 +710,7 @@ func (t *Translator) processGRPCRouteRules(grpcRoute *GRPCRouteContext, parentRe
case irRoute.DirectResponse != nil || irRoute.Redirect != nil:
// return 500 if any destination setting is invalid
// the error is already added to the error list when processing the destination
case failedProcessDestination:
case failedProcessDestination && destination.ToBackendWeights().Valid == 0:
irRoute.DirectResponse = &ir.CustomResponse{
StatusCode: ptr.To(uint32(500)),
}
Expand Down Expand Up @@ -1138,7 +1137,7 @@ func (t *Translator) processUDPRouteParentRefs(udpRoute *UDPRouteContext, resour
}

// Skip nil destination settings
if ds != nil {
if ds.Weight != nil && *ds.Weight > 0 {
destSettings = append(destSettings, ds)
}
}
Expand Down Expand Up @@ -1287,7 +1286,7 @@ func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resour
continue
}
// Skip nil destination settings
if ds != nil {
if ds.Weight != nil && *ds.Weight > 0 {
destSettings = append(destSettings, ds)
}
}
Expand Down Expand Up @@ -1388,14 +1387,22 @@ func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resour
// processDestination translates a backendRef into a destination settings.
// If an error occurs during this conversion, an error is returned, and the associated routes are expected to become inactive.
// This will result in a direct 500 response for HTTP-based requests.
// If an error occurs during this conversion, an error is returned, and the associated routes are expected to become inactive.
// This will result in a direct 500 response for HTTP-based requests.
func (t *Translator) processDestination(name string, backendRefContext BackendRefContext,
parentRef *RouteParentContext, route RouteContext, resources *resource.Resources,
) (ds *ir.DestinationSetting, unstructuredRef *ir.UnstructuredRef, err status.Error) {
routeType := route.GetRouteType()
weight := uint32(1)
backendRef := backendRefContext.GetBackendRef()
if backendRef.Weight != nil {
weight = uint32(*backendRef.Weight)
var (
routeType = route.GetRouteType()
weight = (uint32(ptr.Deref(backendRefContext.GetBackendRef().Weight, int32(1))))
backendRef = backendRefContext.GetBackendRef()
)

// Create an empty DS without endpoints
// This represents an invalid DS.
emptyDS := &ir.DestinationSetting{
Name: name,
Weight: &weight,
}

backendNamespace := NamespaceDerefOr(backendRef.Namespace, route.GetNamespace())
Expand All @@ -1404,14 +1411,14 @@ func (t *Translator) processDestination(name string, backendRefContext BackendRe
{
// return with empty endpoint means the backend is invalid and an error to fail the associated route.
if err != nil {
return nil, nil, err
return emptyDS, nil, err
}
}
}

// Skip processing backends with 0 weight
if weight == 0 {
return nil, nil, nil
return emptyDS, nil, nil
}

var envoyProxy *egv1a1.EnvoyProxy
Expand Down Expand Up @@ -1442,7 +1449,7 @@ func (t *Translator) processDestination(name string, backendRefContext BackendRe

// Check if the custom backend resource was found
if unstructuredRef == nil {
return nil, nil, status.NewRouteStatusError(
return emptyDS, nil, status.NewRouteStatusError(
fmt.Errorf("custom backend %s %s/%s not found",
KindDerefOr(backendRef.Kind, resource.KindService),
backendNamespace,
Expand Down Expand Up @@ -1475,17 +1482,17 @@ func (t *Translator) processDestination(name string, backendRefContext BackendRe
envoyProxy,
)
if tlsErr != nil {
return nil, nil, status.NewRouteStatusError(tlsErr, status.RouteReasonInvalidBackendTLS)
return emptyDS, nil, status.NewRouteStatusError(tlsErr, status.RouteReasonInvalidBackendTLS)
}

var filtersErr error
ds.Filters, filtersErr = t.processDestinationFilters(routeType, backendRefContext, parentRef, route, resources)
if filtersErr != nil {
return nil, nil, status.NewRouteStatusError(filtersErr, status.RouteReasonInvalidBackendFilters)
return emptyDS, nil, status.NewRouteStatusError(filtersErr, status.RouteReasonInvalidBackendFilters)
}

if err := validateDestinationSettings(ds, t.IsEnvoyServiceRouting(envoyProxy), backendRef.Kind); err != nil {
return nil, nil, err
return emptyDS, nil, err
}

ds.Weight = &weight
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-1
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
grpcRoutes:
- apiVersion: gateway.networking.k8s.io/v1alpha2
kind: GRPCRoute
metadata:
namespace: default
name: grpcroute-1
spec:
parentRefs:
- namespace: envoy-gateway
name: gateway-1
sectionName: http
rules:
- matches:
- method:
method: ExampleExact
type: Exact
backendRefs:
- name: service-1
port: 8080
- name: service-not-exist
port: 8080
services:
- apiVersion: v1
kind: Service
metadata:
name: service-1
spec:
clusterIP: 7.7.7.7
ports:
- port: 8080
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
creationTimestamp: null
name: gateway-1
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
listeners:
- allowedRoutes:
namespaces:
from: All
name: http
port: 80
protocol: HTTP
status:
listeners:
- attachedRoutes: 1
conditions:
- lastTransitionTime: null
message: Sending translated listener configuration to the data plane
reason: Programmed
status: "True"
type: Programmed
- lastTransitionTime: null
message: Listener has been successfully translated
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: null
message: Listener references have been resolved
reason: ResolvedRefs
status: "True"
type: ResolvedRefs
name: http
supportedKinds:
- group: gateway.networking.k8s.io
kind: HTTPRoute
- group: gateway.networking.k8s.io
kind: GRPCRoute
grpcRoutes:
- apiVersion: gateway.networking.k8s.io/v1alpha2
kind: GRPCRoute
metadata:
creationTimestamp: null
name: grpcroute-1
namespace: default
spec:
parentRefs:
- name: gateway-1
namespace: envoy-gateway
sectionName: http
rules:
- backendRefs:
- name: service-1
port: 8080
- name: service-not-exist
port: 8080
matches:
- method:
method: ExampleExact
type: Exact
status:
parents:
- conditions:
- lastTransitionTime: null
message: Route is accepted
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: null
message: 'Failed to process route rule 0 backendRef 1: service default/service-not-exist
not found.'
reason: BackendNotFound
status: "False"
type: ResolvedRefs
controllerName: gateway.envoyproxy.io/gatewayclass-controller
parentRef:
name: gateway-1
namespace: envoy-gateway
sectionName: http
infraIR:
envoy-gateway/gateway-1:
proxy:
listeners:
- address: null
name: envoy-gateway/gateway-1/http
ports:
- containerPort: 10080
name: http-80
protocol: HTTP
servicePort: 80
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
ownerReference:
kind: GatewayClass
name: envoy-gateway-class
name: envoy-gateway/gateway-1
namespace: envoy-gateway-system
xdsIR:
envoy-gateway/gateway-1:
accessLog:
json:
- path: /dev/stdout
globalResources:
proxyServiceCluster:
name: envoy-gateway/gateway-1
settings:
- addressType: IP
endpoints:
- host: 7.6.5.4
port: 8080
zone: zone1
metadata:
name: envoy-envoy-gateway-gateway-1-196ae069
namespace: envoy-gateway-system
sectionName: "8080"
name: envoy-gateway/gateway-1
protocol: TCP
http:
- address: 0.0.0.0
externalPort: 80
hostnames:
- '*'
isHTTP2: true
metadata:
kind: Gateway
name: gateway-1
namespace: envoy-gateway
sectionName: http
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
mergeSlashes: true
port: 10080
routes:
- destination:
metadata:
kind: GRPCRoute
name: grpcroute-1
namespace: default
name: grpcroute/default/grpcroute-1/rule/0
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
metadata:
name: service-1
namespace: default
sectionName: "8080"
name: grpcroute/default/grpcroute-1/rule/0/backend/0
protocol: GRPC
weight: 1
- name: grpcroute/default/grpcroute-1/rule/0/backend/1
weight: 1
headerMatches:
- distinct: false
name: :path
suffix: /ExampleExact
hostname: '*'
isHTTP2: true
metadata:
kind: GRPCRoute
name: grpcroute-1
namespace: default
name: grpcroute/default/grpcroute-1/rule/0/match/0/*
readyListener:
address: 0.0.0.0
ipFamily: IPv4
path: /ready
port: 19003
Loading