Skip to content

Commit e469248

Browse files
authored
ZoneAwareRouting: Differentiate between TrafficDistribution and TopologyAwareRouting (envoyproxy#5882)
* ZoneAwareRouting: Differentiate between TrafficDistribution and TopologyAwareRouting Signed-off-by: Jukie <10012479+Jukie@users.noreply.github.com>
1 parent 96d5062 commit e469248

File tree

17 files changed

+127
-85
lines changed

17 files changed

+127
-85
lines changed

examples/extension-server/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.24.4
44

55
require (
66
github.com/envoyproxy/gateway v1.3.1
7-
github.com/envoyproxy/go-control-plane v0.13.5-0.20250408134212-157c26b62099
8-
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250408134212-157c26b62099
7+
github.com/envoyproxy/go-control-plane v0.13.5-0.20250430092421-68a532e11403
8+
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250430092421-68a532e11403
99
github.com/urfave/cli/v2 v2.27.7
1010
google.golang.org/grpc v1.73.0
1111
google.golang.org/protobuf v1.36.6

examples/extension-server/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
99
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1010
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
1111
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12-
github.com/envoyproxy/go-control-plane v0.13.5-0.20250408134212-157c26b62099 h1:Shucu2sY2a/KjKzO10Y0st2iN0Flzj5QsTEgMFtd0MY=
13-
github.com/envoyproxy/go-control-plane v0.13.5-0.20250408134212-157c26b62099/go.mod h1:Kf4hNGzgvzKhoKdlSXD+IZtG55h9r2SOpO1kRKLI03o=
14-
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250408134212-157c26b62099 h1:LFmrrIXbGktG4DrXsvFFyvZLe+HnimGn6Ed+xuiP6TU=
15-
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250408134212-157c26b62099/go.mod h1:pY0vLp032ToSdejxKtzWZs/TzoAtdK0+50ELjTkXiYA=
12+
github.com/envoyproxy/go-control-plane v0.13.5-0.20250430092421-68a532e11403 h1:FjMl4h6bOc7ZZz0t90qi0UEEWEga8+XHsrKjff34NNo=
13+
github.com/envoyproxy/go-control-plane v0.13.5-0.20250430092421-68a532e11403/go.mod h1:D8/0gVH79cd9cXse2nAwJ7K0GujYzJ63JR0IEoWuu2M=
14+
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250430092421-68a532e11403 h1:hkrqmqBqYmHhisHsi1rDZ7tbnVGjxdiyM9pSbE7v3Tw=
15+
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250430092421-68a532e11403/go.mod h1:2dn73jFhVMBsgVCq7Z/jsPsTzhDKwYZOHLf3Uz8Rj0s=
1616
github.com/envoyproxy/protoc-gen-validate v1.2.1 h1:DEo3O99U8j4hBFwbJfrz9VtgcDfUKS7KJ7spH3d86P8=
1717
github.com/envoyproxy/protoc-gen-validate v1.2.1/go.mod h1:d/C80l/jxXLdfEIhX1W2TmLfsJ31lvEjwamM4DxlWXU=
1818
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ require (
1515
github.com/docker/cli v28.2.2+incompatible
1616
github.com/docker/docker v27.5.1+incompatible
1717
github.com/dominikbraun/graph v0.23.0
18-
github.com/envoyproxy/go-control-plane v0.13.5-0.20250408134212-157c26b62099
19-
github.com/envoyproxy/go-control-plane/contrib v1.32.5-0.20250408134212-157c26b62099
20-
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250408134212-157c26b62099
18+
github.com/envoyproxy/go-control-plane v0.13.5-0.20250430092421-68a532e11403
19+
github.com/envoyproxy/go-control-plane/contrib v1.32.5-0.20250430092421-68a532e11403
20+
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250430092421-68a532e11403
2121
github.com/envoyproxy/go-control-plane/ratelimit v0.1.0
2222
github.com/envoyproxy/ratelimit v1.4.1-0.20230427142404-e2a87f41d3a7
2323
github.com/evanphx/json-patch v5.9.11+incompatible

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,12 @@ github.com/emicklei/go-restful/v3 v3.12.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRr
373373
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
374374
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
375375
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
376-
github.com/envoyproxy/go-control-plane v0.13.5-0.20250408134212-157c26b62099 h1:Shucu2sY2a/KjKzO10Y0st2iN0Flzj5QsTEgMFtd0MY=
377-
github.com/envoyproxy/go-control-plane v0.13.5-0.20250408134212-157c26b62099/go.mod h1:Kf4hNGzgvzKhoKdlSXD+IZtG55h9r2SOpO1kRKLI03o=
378-
github.com/envoyproxy/go-control-plane/contrib v1.32.5-0.20250408134212-157c26b62099 h1:YCkhFxkFlN1h7QVwZTo3a14QlxXf0p1MrycEBuE3wJc=
379-
github.com/envoyproxy/go-control-plane/contrib v1.32.5-0.20250408134212-157c26b62099/go.mod h1:zD9QKAwQBnb9DWvRrkMa7cOuuMOt+ITrm4ZLoZ0aa30=
380-
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250408134212-157c26b62099 h1:LFmrrIXbGktG4DrXsvFFyvZLe+HnimGn6Ed+xuiP6TU=
381-
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250408134212-157c26b62099/go.mod h1:pY0vLp032ToSdejxKtzWZs/TzoAtdK0+50ELjTkXiYA=
376+
github.com/envoyproxy/go-control-plane v0.13.5-0.20250430092421-68a532e11403 h1:FjMl4h6bOc7ZZz0t90qi0UEEWEga8+XHsrKjff34NNo=
377+
github.com/envoyproxy/go-control-plane v0.13.5-0.20250430092421-68a532e11403/go.mod h1:D8/0gVH79cd9cXse2nAwJ7K0GujYzJ63JR0IEoWuu2M=
378+
github.com/envoyproxy/go-control-plane/contrib v1.32.5-0.20250430092421-68a532e11403 h1:5wPocL1bGYhA4TtKZwcdVI5fsXo1JatkbcxPBcFQswc=
379+
github.com/envoyproxy/go-control-plane/contrib v1.32.5-0.20250430092421-68a532e11403/go.mod h1:Xkwx/TGvEKRCL2mitdiuQWOD1ECvfM5krWWVo2vI2Zk=
380+
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250430092421-68a532e11403 h1:hkrqmqBqYmHhisHsi1rDZ7tbnVGjxdiyM9pSbE7v3Tw=
381+
github.com/envoyproxy/go-control-plane/envoy v1.32.5-0.20250430092421-68a532e11403/go.mod h1:2dn73jFhVMBsgVCq7Z/jsPsTzhDKwYZOHLf3Uz8Rj0s=
382382
github.com/envoyproxy/go-control-plane/ratelimit v0.1.0 h1:/G9QYbddjL25KvtKTv3an9lx6VBE2cnb8wp1vEGNYGI=
383383
github.com/envoyproxy/go-control-plane/ratelimit v0.1.0/go.mod h1:Wk+tMFAFbCXaJPzVVHnPgRKdUdwW/KdbRt94AzgRee4=
384384
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=

internal/gatewayapi/route.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ func (t *Translator) processDestination(name string, backendRefContext BackendRe
14091409
ds = t.processServiceDestinationSetting(name, backendRef.BackendObjectReference, backendNamespace, protocol, resources, envoyProxy)
14101410
svc := resources.GetService(backendNamespace, string(backendRef.Name))
14111411
ds.IPFamily = getServiceIPFamily(svc)
1412-
ds.ZoneAwareRoutingEnabled = isZoneAwareRoutingEnabled(svc)
1412+
ds.ZoneAwareRouting = processZoneAwareRouting(svc)
14131413

14141414
case egv1a1.KindBackend:
14151415
ds = t.processBackendDestinationSetting(name, backendRef.BackendObjectReference, backendNamespace, protocol, resources)
@@ -1571,12 +1571,12 @@ func (t *Translator) processServiceDestinationSetting(
15711571
}
15721572

15731573
return &ir.DestinationSetting{
1574-
Name: name,
1575-
Protocol: protocol,
1576-
Endpoints: endpoints,
1577-
AddressType: addrType,
1578-
ZoneAwareRoutingEnabled: isZoneAwareRoutingEnabled(service),
1579-
Metadata: buildResourceMetadata(service, ptr.To(gwapiv1.SectionName(strconv.Itoa(int(*backendRef.Port))))),
1574+
Name: name,
1575+
Protocol: protocol,
1576+
Endpoints: endpoints,
1577+
AddressType: addrType,
1578+
ZoneAwareRouting: processZoneAwareRouting(service),
1579+
Metadata: buildResourceMetadata(service, ptr.To(gwapiv1.SectionName(strconv.Itoa(int(*backendRef.Port))))),
15801580
}
15811581
}
15821582

@@ -1596,24 +1596,28 @@ func getBackendFilters(routeType gwapiv1.Kind, backendRefContext BackendRefConte
15961596
return nil
15971597
}
15981598

1599-
func isZoneAwareRoutingEnabled(svc *corev1.Service) bool {
1599+
func processZoneAwareRouting(svc *corev1.Service) *ir.ZoneAwareRouting {
16001600
if svc == nil {
1601-
return false
1601+
return nil
16021602
}
16031603

16041604
if trafficDist := svc.Spec.TrafficDistribution; trafficDist != nil {
1605-
return *trafficDist == corev1.ServiceTrafficDistributionPreferClose
1605+
return &ir.ZoneAwareRouting{
1606+
MinSize: 1,
1607+
}
16061608
}
16071609

16081610
// Allows annotation values that align with Kubernetes defaults.
16091611
// Ref:
16101612
// https://kubernetes.io/docs/concepts/services-networking/topology-aware-routing/#enabling-topology-aware-routing
16111613
// https://github.com/kubernetes/kubernetes/blob/9d9e1afdf78bce0a517cc22557457f942040ca19/staging/src/k8s.io/endpointslice/utils.go#L355-L368
1612-
if val, ok := svc.Annotations[corev1.AnnotationTopologyMode]; ok {
1613-
return val == "Auto" || val == "auto"
1614+
if val, ok := svc.Annotations[corev1.AnnotationTopologyMode]; ok && val == "Auto" || val == "auto" {
1615+
return &ir.ZoneAwareRouting{
1616+
MinSize: 3,
1617+
}
16141618
}
16151619

1616-
return false
1620+
return nil
16171621
}
16181622

16191623
func (t *Translator) processDestinationFilters(routeType gwapiv1.Kind, backendRefContext BackendRefContext, parentRef *RouteParentContext, route RouteContext, resources *resource.Resources) (*ir.DestinationFilters, error) {

internal/gatewayapi/testdata/httproute-with-enable-zone-discovery.out.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ xdsIR:
159159
name: httproute/default/httproute-1/rule/1/backend/0
160160
protocol: HTTP
161161
weight: 1
162-
zoneAwareRoutingEnabled: true
162+
zoneAwareRouting:
163+
minSize: 1
163164
headerMatches:
164165
- distinct: false
165166
exact: bar
@@ -196,7 +197,8 @@ xdsIR:
196197
name: httproute/default/httproute-1/rule/0/backend/0
197198
protocol: HTTP
198199
weight: 1
199-
zoneAwareRoutingEnabled: true
200+
zoneAwareRouting:
201+
minSize: 1
200202
hostname: '*'
201203
isHTTP2: false
202204
metadata:

internal/ir/xds.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ func (r *RouteDestination) HasFiltersInSettings() bool {
15711571
// HasZoneAwareRouting returns true if any setting in the destination has ZoneAwareRoutingEnabled set
15721572
func (r *RouteDestination) HasZoneAwareRouting() bool {
15731573
for _, setting := range r.Settings {
1574-
if setting.ZoneAwareRoutingEnabled {
1574+
if setting.ZoneAwareRouting != nil {
15751575
return true
15761576
}
15771577
}
@@ -1629,9 +1629,11 @@ type DestinationSetting struct {
16291629
IPFamily *egv1a1.IPFamily `json:"ipFamily,omitempty" yaml:"ipFamily,omitempty"`
16301630
TLS *TLSUpstreamConfig `json:"tls,omitempty" yaml:"tls,omitempty"`
16311631
Filters *DestinationFilters `json:"filters,omitempty" yaml:"filters,omitempty"`
1632-
// ZoneAwareRoutingEnabled specifies whether to enable Zone Aware Routing for this destination's endpoints.
1632+
// ZoneAwareRouting specifies whether to enable Zone Aware Routing for this destination's endpoints.
16331633
// This is derived from the backend service and depends on having Kubernetes Topology Aware Routing or Traffic Distribution enabled.
1634-
ZoneAwareRoutingEnabled bool `json:"zoneAwareRoutingEnabled,omitempty" yaml:"zoneAwareRoutingEnabled,omitempty"`
1634+
//
1635+
// +optional
1636+
ZoneAwareRouting *ZoneAwareRouting `json:"zoneAwareRouting,omitempty" yaml:"zoneAwareRouting,omitempty"`
16351637
// Metadata is used to enrich envoy route metadata with user and provider-specific information
16361638
// The primary metadata for DestinationSettings comes from the Backend resource reference in BackendRef
16371639
Metadata *ResourceMetadata `json:"metadata,omitempty" yaml:"metadata,omitempty"`
@@ -3145,3 +3147,9 @@ type RequestBuffer struct {
31453147
// Limit defines the maximum buffer size for requests
31463148
Limit resource.Quantity `json:"limit" yaml:"limit"`
31473149
}
3150+
3151+
// ZoneAwareRouting holds the zone aware routing configuration
3152+
// +k8s:deepcopy-gen=true
3153+
type ZoneAwareRouting struct {
3154+
MinSize int `json:"minSize" yaml:"minSize"`
3155+
}

internal/ir/xds_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,8 +1124,8 @@ func TestRouteDestination_NeedsClusterPerSetting(t *testing.T) {
11241124
Port: 8080,
11251125
},
11261126
},
1127-
AddressType: ptr.To(FQDN),
1128-
ZoneAwareRoutingEnabled: true,
1127+
AddressType: ptr.To(FQDN),
1128+
ZoneAwareRouting: &ZoneAwareRouting{MinSize: 1},
11291129
},
11301130
{
11311131
Endpoints: []*DestinationEndpoint{
@@ -1152,8 +1152,8 @@ func TestRouteDestination_NeedsClusterPerSetting(t *testing.T) {
11521152
Port: 8080,
11531153
},
11541154
},
1155-
AddressType: ptr.To(FQDN),
1156-
ZoneAwareRoutingEnabled: true,
1155+
AddressType: ptr.To(FQDN),
1156+
ZoneAwareRouting: &ZoneAwareRouting{MinSize: 1},
11571157
},
11581158
},
11591159
},

internal/ir/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/xds/extensions/extensions.gen.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ import (
140140
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/oauth2/v3"
141141
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/on_demand/v3"
142142
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/original_src/v3"
143+
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/proto_api_scrubber/v3"
143144
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/proto_message_extraction/v3"
144145
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/rate_limit_quota/v3"
145146
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ratelimit/v3"
@@ -266,6 +267,7 @@ import (
266267
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/retry/host/previous_hosts/v3"
267268
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/retry/priority/previous_priorities/v3"
268269
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/router/cluster_specifiers/lua/v3"
270+
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/router/cluster_specifiers/matcher/v3"
269271
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/stat_sinks/graphite_statsd/v3"
270272
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/stat_sinks/open_telemetry/v3"
271273
_ "github.com/envoyproxy/go-control-plane/envoy/extensions/stat_sinks/wasm/v3"

0 commit comments

Comments
 (0)