Skip to content
Open
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
2 changes: 1 addition & 1 deletion internal/gatewayapi/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ func (t *Translator) processRequestMirrorFilter(
fmt.Errorf("failed to validate the RequestMirror filter: %w", err), err.Reason()).WithType(gwapiv1.RouteConditionResolvedRefs)
}

destName := fmt.Sprintf("%s-mirror-%d", irRouteDestinationName(filterContext.Route, filterContext.RuleIdx), filterIdx)
destName := fmt.Sprintf("%s-mirror-%d", irRouteDestinationName(t.XDSNameSchemeV2, filterContext.Route, filterContext.RuleIdx), filterIdx)
settingName := irDestinationSettingName(destName, -1 /*unused*/)
ds, _, err := t.processDestination(settingName, mirrorBackendRef, filterContext.ParentRef, filterContext.Route, resources)
if err != nil {
Expand Down
12 changes: 11 additions & 1 deletion internal/gatewayapi/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,21 @@ func irUDPRouteName(route RouteContext) string {
return irTCPRouteName(route)
}

func irRouteDestinationName(route RouteContext, ruleIdx int) string {
// irRouteDestinationName returns the name for a route destination in the IR.
// The format of the name depends on the xdsNameSchemeV2 flag:
// - If xdsNameSchemeV2 is true, the name will be "{routePrefix}rule/{ruleIdx}/backend/0"
// this will avoid naming changes for issue like https://github.com/envoyproxy/gateway/issues/6287.
// - If xdsNameSchemeV2 is false, the name will be "{routePrefix}rule/{ruleIdx}"
func irRouteDestinationName(xdsNameSchemeV2 bool, route RouteContext, ruleIdx int) string {
if xdsNameSchemeV2 {
return fmt.Sprintf("%srule/%d/backend/0", irRoutePrefix(route), ruleIdx)
}
return fmt.Sprintf("%srule/%d", irRoutePrefix(route), ruleIdx)
}

func irDestinationSettingName(destName string, backendIdx int) string {
// Trim the "/backend/0" suffix if it exists to avoid duplication when appending the backend index
destName = strings.TrimSuffix(destName, "/backend/0")
return fmt.Sprintf("%s/backend/%d", destName, backendIdx)
}

Expand Down
12 changes: 6 additions & 6 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (t *Translator) processHTTPRouteRules(httpRoute *HTTPRouteContext, parentRe
}

// process each backendRef, and calculate the destination settings for this rule
destName := irRouteDestinationName(httpRoute, ruleIdx)
destName := irRouteDestinationName(t.XDSNameSchemeV2, httpRoute, ruleIdx)
allDs := make([]*ir.DestinationSetting, 0, len(rule.BackendRefs))
var processDestinationError error
failedNoReadyEndpoints := false
Expand Down Expand Up @@ -586,7 +586,7 @@ func (t *Translator) processHTTPRouteRule(

// We generate a unique session name per route.
// `/` isn't allowed in the header key, so we just replace it with `-`.
sessionName = strings.ReplaceAll(irRouteDestinationName(httpRoute, ruleIdx), "/", "-")
sessionName = strings.ReplaceAll(irRouteDestinationName(t.XDSNameSchemeV2, httpRoute, ruleIdx), "/", "-")
} else {
sessionName = *rule.SessionPersistence.SessionName
}
Expand Down Expand Up @@ -980,7 +980,7 @@ func (t *Translator) processGRPCRouteRules(grpcRoute *GRPCRouteContext, parentRe
}

// process each backendRef, and calculate the destination settings for this rule
destName := irRouteDestinationName(grpcRoute, ruleIdx)
destName := irRouteDestinationName(t.XDSNameSchemeV2, grpcRoute, ruleIdx)
allDs := make([]*ir.DestinationSetting, 0, len(rule.BackendRefs))
var processDestinationError error
failedNoReadyEndpoints := false
Expand Down Expand Up @@ -1365,7 +1365,7 @@ func (t *Translator) processTLSRouteParentRefs(tlsRoute *TLSRouteContext, resour
var (
destSettings []*ir.DestinationSetting
resolveErrs = &status.MultiStatusError{}
destName = irRouteDestinationName(tlsRoute, -1 /*rule index*/)
destName = irRouteDestinationName(t.XDSNameSchemeV2, tlsRoute, -1 /*rule index*/)
)

// compute backends
Expand Down Expand Up @@ -1544,7 +1544,7 @@ func (t *Translator) processUDPRouteParentRefs(udpRoute *UDPRouteContext, resour
var (
destSettings []*ir.DestinationSetting
resolveErrs = &status.MultiStatusError{}
destName = irRouteDestinationName(udpRoute, -1 /*rule index*/)
destName = irRouteDestinationName(t.XDSNameSchemeV2, udpRoute, -1 /*rule index*/)
)

for i := range udpRoute.Spec.Rules[0].BackendRefs {
Expand Down Expand Up @@ -1695,7 +1695,7 @@ func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resour
var (
destSettings []*ir.DestinationSetting
resolveErrs = &status.MultiStatusError{}
destName = irRouteDestinationName(tcpRoute, -1 /*rule index*/)
destName = irRouteDestinationName(t.XDSNameSchemeV2, tcpRoute, -1 /*rule index*/)
)

for i := range tcpRoute.Spec.Rules[0].BackendRefs {
Expand Down
1 change: 1 addition & 0 deletions internal/gatewayapi/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func (r *Runner) subscribeAndTranslate(sub <-chan watchable.Snapshot[string, *re
RunningOnHost: r.EnvoyGateway.Provider != nil && r.EnvoyGateway.Provider.IsRunningOnHost(),
Logger: traceLogger,
LuaEnvoyExtensionPolicyDisabled: r.EnvoyGateway.ExtensionAPIs != nil && r.EnvoyGateway.ExtensionAPIs.DisableLua,
XDSNameSchemeV2: r.EnvoyGateway.RuntimeFlags != nil && r.EnvoyGateway.RuntimeFlags.IsEnabled(egv1a1.XDSNameSchemeV2),
}

// If an extension is loaded, pass its supported groups/kinds to the translator
Expand Down
76 changes: 76 additions & 0 deletions internal/gatewayapi/testdata/xds-name-scheme-v2.in.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-2
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: default
name: httproute-1
spec:
hostnames:
- gateway.envoyproxy.io
parentRefs:
- namespace: envoy-gateway
name: gateway-1
sectionName: http
rules:
- matches:
- path:
value: "/"
backendRefs:
- name: service-1
port: 8080
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: default
name: httproute-2
spec:
hostnames:
- gateway2.envoyproxy.io
parentRefs:
- namespace: envoy-gateway
name: gateway-2
sectionName: http
rules:
- matches:
- path:
value: "/"
backendRefs:
- name: service-1
port: 8080
- name: service-2
port: 8080
filters:
- type: ResponseHeaderModifier
responseHeaderModifier:
add:
- name: backend
value: service-2
Loading
Loading