Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 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
25 changes: 24 additions & 1 deletion api/v1alpha1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
//
// +kubebuilder:validation:XValidation:rule="self.type == 'ConsistentHash' ? has(self.consistentHash) : !has(self.consistentHash)",message="If LoadBalancer type is consistentHash, consistentHash field needs to be set."
// +kubebuilder:validation:XValidation:rule="self.type in ['Random', 'ConsistentHash'] ? !has(self.slowStart) : true ",message="Currently SlowStart is only supported for RoundRobin and LeastRequest load balancers."
// +kubebuilder:validation:XValidation:rule="self.type == 'ConsistentHash' ? !has(self.zoneAware) : true ",message="Currently ZoneAware is only supported for LeastRequest, Random, and RoundRobin load balancers."
// +kubebuilder:validation:XValidation:rule="self.type == 'ConsistentHash' && has(self.zoneAware) ? !has(self.zoneAware.preferLocal) : true",message="PreferLocal zone-aware routing is not supported for ConsistentHash load balancers. Use weightedZones instead."
// +kubebuilder:validation:XValidation:rule="has(self.zoneAware) ? !(has(self.zoneAware.preferLocal) && has(self.zoneAware.weightedZones)) : true",message="ZoneAware PreferLocal and WeightedZones cannot be specified together."
type LoadBalancer struct {
// Type decides the type of Load Balancer policy.
// Valid LoadBalancerType values are
Expand Down Expand Up @@ -184,6 +185,14 @@ type ZoneAware struct {
//
// +optional
PreferLocal *PreferLocalZone `json:"preferLocal,omitempty"`

// WeightedZones configures weight-based traffic distribution across locality zones.
// Traffic is distributed proportionally based on the sum of all zone weights.
//
// +optional
// +listType=map
// +listMapKey=zone
WeightedZones []WeightedZoneConfig `json:"weightedZones,omitempty"`
}

// PreferLocalZone configures zone-aware routing to prefer sending traffic to the local locality zone.
Expand Down Expand Up @@ -217,6 +226,20 @@ type ForceLocalZone struct {
MinEndpointsInZoneThreshold *uint32 `json:"minEndpointsInZoneThreshold,omitempty"`
}

// WeightedZoneConfig defines the weight for a specific locality zone.
type WeightedZoneConfig struct {
// Zone specifies the topology zone this weight applies to.
// The value should match the topology.kubernetes.io/zone label
// of the nodes where endpoints are running.
// Zones not listed in the configuration receive a default weight of 1.
Copy link
Copy Markdown
Contributor Author

@jukie jukie Feb 8, 2026

Choose a reason for hiding this comment

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

This is a design choice, if preferred we could default to zero or even add another field here to configure default weight directly but it seemed unnecessary.

Zone string `json:"zone"`

// Weight defines the weight for this locality.
// Higher values receive more traffic. The actual traffic distribution
// is proportional to this value relative to other localities.
Weight uint32 `json:"weight"`
}

// EndpointOverride defines the configuration for endpoint override.
// This allows endpoint picking to be implemented based on request headers or metadata.
// It extracts selected override endpoints from the specified sources (request headers, metadata, etc.).
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,36 @@ spec:
minimum: 0
type: integer
type: object
weightedZones:
description: |-
WeightedZones configures weight-based traffic distribution across locality zones.
Traffic is distributed proportionally based on the sum of all zone weights.
items:
description: WeightedZoneConfig defines the weight for a
specific locality zone.
properties:
weight:
description: |-
Weight defines the weight for this locality.
Higher values receive more traffic. The actual traffic distribution
is proportional to this value relative to other localities.
format: int32
type: integer
zone:
description: |-
Zone specifies the topology zone this weight applies to.
The value should match the topology.kubernetes.io/zone label
of the nodes where endpoints are running.
Zones not listed in the configuration receive a default weight of 1.
type: string
required:
- weight
- zone
type: object
type: array
x-kubernetes-list-map-keys:
- zone
x-kubernetes-list-type: map
type: object
required:
- type
Expand All @@ -944,10 +974,14 @@ spec:
LeastRequest load balancers.
rule: 'self.type in [''Random'', ''ConsistentHash''] ? !has(self.slowStart)
: true '
- message: Currently ZoneAware is only supported for LeastRequest,
Random, and RoundRobin load balancers.
rule: 'self.type == ''ConsistentHash'' ? !has(self.zoneAware) :
true '
- message: PreferLocal zone-aware routing is not supported for ConsistentHash
load balancers. Use weightedZones instead.
rule: 'self.type == ''ConsistentHash'' && has(self.zoneAware) ?
!has(self.zoneAware.preferLocal) : true'
- message: ZoneAware PreferLocal and WeightedZones cannot be specified
together.
rule: 'has(self.zoneAware) ? !(has(self.zoneAware.preferLocal) &&
has(self.zoneAware.weightedZones)) : true'
mergeType:
description: |-
MergeType determines how this configuration is merged with existing BackendTrafficPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,36 @@ spec:
minimum: 0
type: integer
type: object
weightedZones:
description: |-
WeightedZones configures weight-based traffic distribution across locality zones.
Traffic is distributed proportionally based on the sum of all zone weights.
items:
description: WeightedZoneConfig defines the weight
for a specific locality zone.
properties:
weight:
description: |-
Weight defines the weight for this locality.
Higher values receive more traffic. The actual traffic distribution
is proportional to this value relative to other localities.
format: int32
type: integer
zone:
description: |-
Zone specifies the topology zone this weight applies to.
The value should match the topology.kubernetes.io/zone label
of the nodes where endpoints are running.
Zones not listed in the configuration receive a default weight of 1.
type: string
required:
- weight
- zone
type: object
type: array
x-kubernetes-list-map-keys:
- zone
x-kubernetes-list-type: map
type: object
required:
- type
Expand All @@ -982,10 +1012,15 @@ spec:
and LeastRequest load balancers.
rule: 'self.type in [''Random'', ''ConsistentHash''] ?
!has(self.slowStart) : true '
- message: Currently ZoneAware is only supported for LeastRequest,
Random, and RoundRobin load balancers.
rule: 'self.type == ''ConsistentHash'' ? !has(self.zoneAware)
: true '
- message: PreferLocal zone-aware routing is not supported
for ConsistentHash load balancers. Use weightedZones
instead.
rule: 'self.type == ''ConsistentHash'' && has(self.zoneAware)
? !has(self.zoneAware.preferLocal) : true'
- message: ZoneAware PreferLocal and WeightedZones cannot
be specified together.
rule: 'has(self.zoneAware) ? !(has(self.zoneAware.preferLocal)
&& has(self.zoneAware.weightedZones)) : true'
proxyProtocol:
description: ProxyProtocol enables the Proxy Protocol when
communicating with the backend.
Expand Down
Loading