feat(backendconfigpolicy): add zone-aware routing#13978
Conversation
There was a problem hiding this comment.
Pull request overview
Adds zone-aware routing support to BackendConfigPolicy load balancer settings, including an optional “force local zone” mode implemented via per-client endpoint prioritization, and wires proxy node locality into the Envoy bootstrap to enable Envoy’s zone-aware LB behavior. It also adjusts endpoint processing to rely on the backend’s already-resolved AttachedPolicies to preserve attachment semantics for ServiceEntry/hostname-alias backends.
Changes:
- Introduces
loadBalancer.zoneAware.preferLocal(and optionalforce) API + CRD schema, and translates it into Envoyzone_aware_lb_config(falling back to legacylb_policy/lb_configwhen required). - Adds per-client endpoint processing for BackendConfigPolicy zone-aware force mode, using resolved policy attachments instead of re-matching by endpoint resource names.
- Populates
bootstrap.node.localityfromKGATEWAY_NODE_REGION/ZONE/SUBZONEvia envoyinit downward API.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/pluginsdk/ir/model.go | Adds AttachedPolicies to EndpointsForBackend and propagates it through constructors/copies. |
| pkg/kgateway/translator/irtranslator/backend.go | Ensures inline endpoint inputs carry the backend’s resolved AttachedPolicies. |
| pkg/kgateway/translator/gateway/testutils/outputs/backendconfigpolicy/zone-aware-prefer-local.yaml | Adds golden output coverage for prefer-local zone-aware LB config. |
| pkg/kgateway/translator/gateway/testutils/outputs/backendconfigpolicy/zone-aware-force.yaml | Adds golden output coverage for force-mode + legacy lb_policy output. |
| pkg/kgateway/translator/gateway/testutils/inputs/backendconfigpolicy/zone-aware-prefer-local.yaml | Adds gateway translator input fixture for prefer-local. |
| pkg/kgateway/translator/gateway/testutils/inputs/backendconfigpolicy/zone-aware-force.yaml | Adds gateway translator input fixture for force mode. |
| pkg/kgateway/translator/gateway/gateway_translator_test.go | Registers new translator golden test cases for zone-aware BCP scenarios. |
| pkg/kgateway/proxy_syncer/effective_endpoints.go | Copies backend-resolved AttachedPolicies into final endpoint IR for per-client translation. |
| pkg/kgateway/extensions2/plugins/kubernetes/k8s.go | Maps Service topology-mode: Auto annotation to prefer-same-zone traffic distribution. |
| pkg/kgateway/extensions2/plugins/backendconfigpolicy/plugin.go | Adds BackendConfigPolicy endpoint plugin for zone-aware “force” endpoint prioritization. |
| pkg/kgateway/extensions2/plugins/backendconfigpolicy/plugin_test.go | Adds unit tests for force-mode priority assignment and policy-selection behavior. |
| pkg/kgateway/extensions2/plugins/backendconfigpolicy/lb.go | Adds zone-aware LB translation, legacy lb_policy conversion, and IR equality updates. |
| pkg/kgateway/extensions2/plugins/backendconfigpolicy/lb_test.go | Adds translation/equality tests for zone-aware config and force-mode IR. |
| internal/envoyinit/pkg/downward/transform.go | Initializes bootstrap.Node if nil and sets Node.Locality from env-derived downward API values. |
| internal/envoyinit/pkg/downward/transform_test.go | Adds tests verifying locality is set and node is initialized when needed. |
| internal/envoyinit/pkg/downward/template_test.go | Extends mock downward API with node locality getters. |
| internal/envoyinit/pkg/downward/interface.go | Extends the downward API interface with NodeZone/Region/Subzone. |
| internal/envoyinit/pkg/downward/downward.go | Reads KGATEWAY_NODE_REGION/ZONE/SUBZONE into the downward injectable implementation. |
| install/helm/kgateway-crds/templates/gateway.kgateway.dev_backendconfigpolicies.yaml | Updates CRD schema/validations/docs for the new zone-aware load balancer API. |
| api/v1alpha1/kgateway/zz_generated.deepcopy.go | Adds deep-copies for new zone-aware API types and LoadBalancer.ZoneAware. |
| api/v1alpha1/kgateway/backend_config_policy_types.go | Defines new zone-aware API types + validation constraints on LoadBalancer. |
de5de34 to
1a605c5
Compare
alexliu541
left a comment
There was a problem hiding this comment.
Had a problem when testing locally with 3 zones. I believe its due to Envoy requires the local cluster and upstream cluster to have the same number of localities, and a static local cluster only has 1 locality thus not working.
Move BackendConfigPolicy zone-aware load balancing to Envoy typed locality LB config and restore deterministic force-local behavior across all endpoint paths. - emit zone-aware and forceLocalZone through typed LB policies - remove the legacy cluster-level zone-aware fallback - run BackendConfigPolicy endpoint plugins last in a shared ordered irtranslator endpoint phase - apply the same ordering to inline endpoint backends so force mode overrides DestinationRule priority consistently - update envoyinit Transform to inject node locality in the production IO path and preserve typed configs - rebuild envoy-wrapper when internal envoyinit sources change - refresh tests, goldens, CRD descriptions, and KinD validation Signed-off-by: MayorFaj <[email protected]>
Signed-off-by: MayorFaj <[email protected]>
Signed-off-by: MayorFaj <[email protected]>
Signed-off-by: MayorFaj <[email protected]>
Signed-off-by: MayorFaj <[email protected]>
Signed-off-by: MayorFaj <[email protected]>
…tadata removal Signed-off-by: MayorFaj <[email protected]>
d4b85f6 to
c0af68a
Compare
alexliu541
left a comment
There was a problem hiding this comment.
a few minor comments, rest looks good and works on local testing. For these nits, feel free to skip them, I can handle them when I add e2e tests for zone aware feature.
Thanks for the update!
Signed-off-by: MayorFaj <[email protected]>
Signed-off-by: MayorFaj <[email protected]>
… xdsDumper to use it Signed-off-by: MayorFaj <[email protected]>
…yaml Signed-off-by: MayorFaj <[email protected]>
…t tests Signed-off-by: MayorFaj <[email protected]>
alexliu541
left a comment
There was a problem hiding this comment.
LGTM, thanks for the PR!
|
@MayorFaj sorry for the delay in this. Looks like merging with main brought in some new translator tests that do not have the new Once you merge with main again an regenerate the golden files, I will approve and address any follow up with @alexliu541 e2e PR to avoid keep fixing new tests. |
… main Signed-off-by: MayorFaj <[email protected]>
Signed-off-by: MayorFaj <[email protected]>
Description
Adds zone-aware routing support to
BackendConfigPolicyload balancer settings.This introduces a new
loadBalancer.zoneAware.preferLocalAPI that configures Envoy's native zone-aware load balancing for supported load balancer policies, including:The implementation also wires proxy locality into Envoy bootstrap through
KGATEWAY_NODE_REGION,KGATEWAY_NODE_ZONE, andKGATEWAY_NODE_SUBZONE, and configuresnode.cluster,cluster_manager.local_cluster_name, and a local static cluster so Envoy can make native zone-aware and force-local routing decisions.In addition, BackendConfigPolicy zone-aware settings now take precedence over Service
trafficDistribution, and endpoint processing uses the backend's resolvedAttachedPolicies, which preserves hostname and alias attachment semantics for ServiceEntry-style backends.Zone-aware routing requires proxy locality env vars to be present on the Envoy pod.
Fixes #13303
Note; users must configure locality env vars
Change Type
Changelog