Skip to content

Commit 7fc7ba7

Browse files
Add support for ClientSideWeightedRoundRobin load balancer policy in Gateway CRDs, ensuring configurable parameters and validation rules are integrated. Includes e2e test for validation.
Signed-off-by: anurag.ag <[email protected]>
1 parent 3ba1db8 commit 7fc7ba7

21 files changed

+2915
-189
lines changed

api/v1alpha1/loadbalancer_types.go

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
1111
// +union
1212
//
1313
// +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."
14-
// +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."
15-
// +kubebuilder:validation:XValidation:rule="self.type == 'ConsistentHash' ? !has(self.zoneAware) : true ",message="Currently ZoneAware is only supported for LeastRequest, Random, and RoundRobin load balancers."
14+
// +kubebuilder:validation:XValidation:rule="self.type == 'ClientSideWeightedRoundRobin' ? has(self.clientSideWeightedRoundRobin) : !has(self.clientSideWeightedRoundRobin)",message="If LoadBalancer type is ClientSideWeightedRoundRobin, clientSideWeightedRoundRobin field needs to be set."
15+
// +kubebuilder:validation:XValidation:rule="self.type in ['Random', 'ConsistentHash', 'ClientSideWeightedRoundRobin'] ? !has(self.slowStart) : true ",message="Currently SlowStart is only supported for RoundRobin and LeastRequest load balancers."
16+
// +kubebuilder:validation:XValidation:rule="self.type in ['ConsistentHash', 'ClientSideWeightedRoundRobin'] ? !has(self.zoneAware) : true ",message="Currently ZoneAware is only supported for LeastRequest, Random, and RoundRobin load balancers."
1617
type LoadBalancer struct {
1718
// Type decides the type of Load Balancer policy.
1819
// Valid LoadBalancerType values are
1920
// "ConsistentHash",
2021
// "LeastRequest",
2122
// "Random",
22-
// "RoundRobin".
23+
// "RoundRobin",
24+
// "ClientSideWeightedRoundRobin".
2325
//
2426
// +unionDiscriminator
2527
Type LoadBalancerType `json:"type"`
@@ -29,6 +31,12 @@ type LoadBalancer struct {
2931
// +optional
3032
ConsistentHash *ConsistentHash `json:"consistentHash,omitempty"`
3133

34+
// ClientSideWeightedRoundRobin defines the configuration when the load balancer type is
35+
// set to ClientSideWeightedRoundRobin.
36+
//
37+
// +optional
38+
ClientSideWeightedRoundRobin *ClientSideWeightedRoundRobin `json:"clientSideWeightedRoundRobin,omitempty"`
39+
3240
// EndpointOverride defines the configuration for endpoint override.
3341
// When specified, the load balancer will attempt to route requests to endpoints
3442
// based on the override information extracted from request headers or metadata.
@@ -51,7 +59,7 @@ type LoadBalancer struct {
5159
}
5260

5361
// LoadBalancerType specifies the types of LoadBalancer.
54-
// +kubebuilder:validation:Enum=ConsistentHash;LeastRequest;Random;RoundRobin
62+
// +kubebuilder:validation:Enum=ConsistentHash;LeastRequest;Random;RoundRobin;ClientSideWeightedRoundRobin
5563
type LoadBalancerType string
5664

5765
const (
@@ -63,6 +71,8 @@ const (
6371
RandomLoadBalancerType LoadBalancerType = "Random"
6472
// RoundRobinLoadBalancerType load balancer policy.
6573
RoundRobinLoadBalancerType LoadBalancerType = "RoundRobin"
74+
// ClientSideWeightedRoundRobinLoadBalancerType load balancer policy.
75+
ClientSideWeightedRoundRobinLoadBalancerType LoadBalancerType = "ClientSideWeightedRoundRobin"
6676
)
6777

6878
// ConsistentHash defines the configuration related to the consistent hash
@@ -134,6 +144,45 @@ type Cookie struct {
134144
Attributes map[string]string `json:"attributes,omitempty"`
135145
}
136146

147+
// ClientSideWeightedRoundRobin defines configuration for Envoy's Client-Side Weighted Round Robin policy.
148+
// See Envoy proto: envoy.extensions.load_balancing_policies.client_side_weighted_round_robin.v3.ClientSideWeightedRoundRobin
149+
// Note: SlowStart is not supported for this policy in Envoy Gateway at this time.
150+
type ClientSideWeightedRoundRobin struct {
151+
// Whether to enable out-of-band utilization reporting collection from the endpoints.
152+
// By default, per-request utilization reporting is used.
153+
// +optional
154+
EnableOOBLoadReport *bool `json:"enableOOBLoadReport,omitempty"`
155+
156+
// Load reporting interval to request from the server. Used only when enableOOBLoadReport is true.
157+
// Default is 10s; server may not provide reports as frequently as requested.
158+
// +optional
159+
OOBReportingPeriod *gwapiv1.Duration `json:"oobReportingPeriod,omitempty"`
160+
161+
// A given endpoint must report load metrics continuously for at least this long before the endpoint weight will be used.
162+
// Default is 10s.
163+
// +optional
164+
BlackoutPeriod *gwapiv1.Duration `json:"blackoutPeriod,omitempty"`
165+
166+
// If a given endpoint has not reported load metrics in this long, stop using the reported weight. Defaults to 3m.
167+
// +optional
168+
WeightExpirationPeriod *gwapiv1.Duration `json:"weightExpirationPeriod,omitempty"`
169+
170+
// How often endpoint weights are recalculated. Values less than 100ms are capped at 100ms. Default 1s.
171+
// +optional
172+
WeightUpdatePeriod *gwapiv1.Duration `json:"weightUpdatePeriod,omitempty"`
173+
174+
// The multiplier used to adjust endpoint weights with the error rate calculated as eps/qps.
175+
// Must be non-negative. Default is 1.0.
176+
// +kubebuilder:validation:Minimum=0
177+
// +optional
178+
ErrorUtilizationPenalty *float32 `json:"errorUtilizationPenalty,omitempty"`
179+
180+
// Metric names used to compute utilization if application_utilization is not set.
181+
// For map fields in ORCA proto, use the form "<map_field>.<key>", e.g., "named_metrics.foo".
182+
// +optional
183+
MetricNamesForComputingUtilization []string `json:"metricNamesForComputingUtilization,omitempty"`
184+
}
185+
137186
// ConsistentHashType defines the type of input to hash on.
138187
// +kubebuilder:validation:Enum=SourceIP;Header;Headers;Cookie
139188
type ConsistentHashType string

api/v1alpha1/zz_generated.deepcopy.go

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

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,53 @@ spec:
677677
LoadBalancer policy to apply when routing traffic from the gateway to
678678
the backend endpoints. Defaults to `LeastRequest`.
679679
properties:
680+
clientSideWeightedRoundRobin:
681+
description: |-
682+
ClientSideWeightedRoundRobin defines the configuration when the load balancer type is
683+
set to ClientSideWeightedRoundRobin.
684+
properties:
685+
blackoutPeriod:
686+
description: |-
687+
A given endpoint must report load metrics continuously for at least this long before the endpoint weight will be used.
688+
Default is 10s.
689+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
690+
type: string
691+
enableOOBLoadReport:
692+
description: |-
693+
Whether to enable out-of-band utilization reporting collection from the endpoints.
694+
By default, per-request utilization reporting is used.
695+
type: boolean
696+
errorUtilizationPenalty:
697+
description: |-
698+
The multiplier used to adjust endpoint weights with the error rate calculated as eps/qps.
699+
Must be non-negative. Default is 1.0.
700+
minimum: 0
701+
type: number
702+
metricNamesForComputingUtilization:
703+
description: |-
704+
Metric names used to compute utilization if application_utilization is not set.
705+
For map fields in ORCA proto, use the form "<map_field>.<key>", e.g., "named_metrics.foo".
706+
items:
707+
type: string
708+
type: array
709+
oobReportingPeriod:
710+
description: |-
711+
Load reporting interval to request from the server. Used only when enableOOBLoadReport is true.
712+
Default is 10s; server may not provide reports as frequently as requested.
713+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
714+
type: string
715+
weightExpirationPeriod:
716+
description: If a given endpoint has not reported load metrics
717+
in this long, stop using the reported weight. Defaults to
718+
3m.
719+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
720+
type: string
721+
weightUpdatePeriod:
722+
description: How often endpoint weights are recalculated.
723+
Values less than 100ms are capped at 100ms. Default 1s.
724+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
725+
type: string
726+
type: object
680727
consistentHash:
681728
description: |-
682729
ConsistentHash defines the configuration when the load balancer type is
@@ -822,12 +869,14 @@ spec:
822869
"ConsistentHash",
823870
"LeastRequest",
824871
"Random",
825-
"RoundRobin".
872+
"RoundRobin",
873+
"ClientSideWeightedRoundRobin".
826874
enum:
827875
- ConsistentHash
828876
- LeastRequest
829877
- Random
830878
- RoundRobin
879+
- ClientSideWeightedRoundRobin
831880
type: string
832881
zoneAware:
833882
description: ZoneAware defines the configuration related to the
@@ -873,14 +922,18 @@ spec:
873922
field needs to be set.
874923
rule: 'self.type == ''ConsistentHash'' ? has(self.consistentHash)
875924
: !has(self.consistentHash)'
925+
- message: If LoadBalancer type is ClientSideWeightedRoundRobin, clientSideWeightedRoundRobin
926+
field needs to be set.
927+
rule: 'self.type == ''ClientSideWeightedRoundRobin'' ? has(self.clientSideWeightedRoundRobin)
928+
: !has(self.clientSideWeightedRoundRobin)'
876929
- message: Currently SlowStart is only supported for RoundRobin and
877930
LeastRequest load balancers.
878-
rule: 'self.type in [''Random'', ''ConsistentHash''] ? !has(self.slowStart)
879-
: true '
931+
rule: 'self.type in [''Random'', ''ConsistentHash'', ''ClientSideWeightedRoundRobin'']
932+
? !has(self.slowStart) : true '
880933
- message: Currently ZoneAware is only supported for LeastRequest,
881934
Random, and RoundRobin load balancers.
882-
rule: 'self.type == ''ConsistentHash'' ? !has(self.zoneAware) :
883-
true '
935+
rule: 'self.type in [''ConsistentHash'', ''ClientSideWeightedRoundRobin'']
936+
? !has(self.zoneAware) : true '
884937
mergeType:
885938
description: |-
886939
MergeType determines how this configuration is merged with existing BackendTrafficPolicy

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_envoyextensionpolicies.yaml

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,54 @@ spec:
716716
LoadBalancer policy to apply when routing traffic from the gateway to
717717
the backend endpoints. Defaults to `LeastRequest`.
718718
properties:
719+
clientSideWeightedRoundRobin:
720+
description: |-
721+
ClientSideWeightedRoundRobin defines the configuration when the load balancer type is
722+
set to ClientSideWeightedRoundRobin.
723+
properties:
724+
blackoutPeriod:
725+
description: |-
726+
A given endpoint must report load metrics continuously for at least this long before the endpoint weight will be used.
727+
Default is 10s.
728+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
729+
type: string
730+
enableOOBLoadReport:
731+
description: |-
732+
Whether to enable out-of-band utilization reporting collection from the endpoints.
733+
By default, per-request utilization reporting is used.
734+
type: boolean
735+
errorUtilizationPenalty:
736+
description: |-
737+
The multiplier used to adjust endpoint weights with the error rate calculated as eps/qps.
738+
Must be non-negative. Default is 1.0.
739+
minimum: 0
740+
type: number
741+
metricNamesForComputingUtilization:
742+
description: |-
743+
Metric names used to compute utilization if application_utilization is not set.
744+
For map fields in ORCA proto, use the form "<map_field>.<key>", e.g., "named_metrics.foo".
745+
items:
746+
type: string
747+
type: array
748+
oobReportingPeriod:
749+
description: |-
750+
Load reporting interval to request from the server. Used only when enableOOBLoadReport is true.
751+
Default is 10s; server may not provide reports as frequently as requested.
752+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
753+
type: string
754+
weightExpirationPeriod:
755+
description: If a given endpoint has not reported
756+
load metrics in this long, stop using the reported
757+
weight. Defaults to 3m.
758+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
759+
type: string
760+
weightUpdatePeriod:
761+
description: How often endpoint weights are recalculated.
762+
Values less than 100ms are capped at 100ms. Default
763+
1s.
764+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
765+
type: string
766+
type: object
719767
consistentHash:
720768
description: |-
721769
ConsistentHash defines the configuration when the load balancer type is
@@ -866,12 +914,14 @@ spec:
866914
"ConsistentHash",
867915
"LeastRequest",
868916
"Random",
869-
"RoundRobin".
917+
"RoundRobin",
918+
"ClientSideWeightedRoundRobin".
870919
enum:
871920
- ConsistentHash
872921
- LeastRequest
873922
- Random
874923
- RoundRobin
924+
- ClientSideWeightedRoundRobin
875925
type: string
876926
zoneAware:
877927
description: ZoneAware defines the configuration related
@@ -919,14 +969,18 @@ spec:
919969
field needs to be set.
920970
rule: 'self.type == ''ConsistentHash'' ? has(self.consistentHash)
921971
: !has(self.consistentHash)'
972+
- message: If LoadBalancer type is ClientSideWeightedRoundRobin,
973+
clientSideWeightedRoundRobin field needs to be set.
974+
rule: 'self.type == ''ClientSideWeightedRoundRobin'' ?
975+
has(self.clientSideWeightedRoundRobin) : !has(self.clientSideWeightedRoundRobin)'
922976
- message: Currently SlowStart is only supported for RoundRobin
923977
and LeastRequest load balancers.
924-
rule: 'self.type in [''Random'', ''ConsistentHash''] ?
925-
!has(self.slowStart) : true '
978+
rule: 'self.type in [''Random'', ''ConsistentHash'', ''ClientSideWeightedRoundRobin'']
979+
? !has(self.slowStart) : true '
926980
- message: Currently ZoneAware is only supported for LeastRequest,
927981
Random, and RoundRobin load balancers.
928-
rule: 'self.type == ''ConsistentHash'' ? !has(self.zoneAware)
929-
: true '
982+
rule: 'self.type in [''ConsistentHash'', ''ClientSideWeightedRoundRobin'']
983+
? !has(self.zoneAware) : true '
930984
proxyProtocol:
931985
description: ProxyProtocol enables the Proxy Protocol when
932986
communicating with the backend.

0 commit comments

Comments
 (0)