@@ -233,8 +233,9 @@ func buildXdsCluster(args *xdsClusterArgs) (*buildClusterResult, error) {
233233
234234 // Set Load Balancer policy
235235 //nolint:gocritic
236- // Check if EndpointOverride is specified
237- if args .loadBalancer != nil && args .loadBalancer .EndpointOverride != nil {
236+ // Use traditional load balancer policies
237+ switch {
238+ case args .loadBalancer != nil && args .loadBalancer .EndpointOverride != nil :
238239 // For EndpointOverride, we use LoadBalancingPolicy with HostOverride
239240 // and the configured load balancer type as fallback policy
240241 endpointOverridePolicy , err := buildEndpointOverrideLoadBalancingPolicy (args .loadBalancer )
@@ -249,107 +250,103 @@ func buildXdsCluster(args *xdsClusterArgs) (*buildClusterResult, error) {
249250 if cluster .CommonLbConfig != nil {
250251 cluster .CommonLbConfig .LocalityConfigSpecifier = nil
251252 }
252- } else {
253- // Use traditional load balancer policies
254- switch {
255- case args .loadBalancer == nil :
256- cluster .LbPolicy = clusterv3 .Cluster_LEAST_REQUEST
257- leastRequest := & least_requestv3.LeastRequest {
258- LocalityLbConfig : localityLbConfig ,
259- }
260- typedLeastRequest , err := proto .ToAnyWithValidation (leastRequest )
261- if err != nil {
262- return nil , err
263- }
264- cluster .LoadBalancingPolicy = & clusterv3.LoadBalancingPolicy {
265- Policies : []* clusterv3.LoadBalancingPolicy_Policy {{
266- TypedExtensionConfig : & corev3.TypedExtensionConfig {
267- Name : "envoy.load_balancing_policies.least_request" ,
268- TypedConfig : typedLeastRequest ,
269- },
270- }},
271- }
272- case args .loadBalancer .LeastRequest != nil :
273- cluster .LbPolicy = clusterv3 .Cluster_LEAST_REQUEST
253+ case args .loadBalancer == nil :
254+ cluster .LbPolicy = clusterv3 .Cluster_LEAST_REQUEST
255+ leastRequest := & least_requestv3.LeastRequest {
256+ LocalityLbConfig : localityLbConfig ,
257+ }
258+ typedLeastRequest , err := proto .ToAnyWithValidation (leastRequest )
259+ if err != nil {
260+ return nil , err
261+ }
262+ cluster .LoadBalancingPolicy = & clusterv3.LoadBalancingPolicy {
263+ Policies : []* clusterv3.LoadBalancingPolicy_Policy {{
264+ TypedExtensionConfig : & corev3.TypedExtensionConfig {
265+ Name : "envoy.load_balancing_policies.least_request" ,
266+ TypedConfig : typedLeastRequest ,
267+ },
268+ }},
269+ }
270+ case args .loadBalancer .LeastRequest != nil :
271+ cluster .LbPolicy = clusterv3 .Cluster_LEAST_REQUEST
274272
275- leastRequest := & least_requestv3.LeastRequest {
276- LocalityLbConfig : localityLbConfig ,
277- }
278- if args .loadBalancer .LeastRequest .SlowStart != nil && args .loadBalancer .LeastRequest .SlowStart .Window != nil {
279- leastRequest .SlowStartConfig = & commonv3.SlowStartConfig {
280- SlowStartWindow : durationpb .New (args .loadBalancer .LeastRequest .SlowStart .Window .Duration ),
281- }
282- }
283- typedLeastRequest , err := proto .ToAnyWithValidation (leastRequest )
284- if err != nil {
285- return nil , err
286- }
287- cluster .LoadBalancingPolicy = & clusterv3.LoadBalancingPolicy {
288- Policies : []* clusterv3.LoadBalancingPolicy_Policy {{
289- TypedExtensionConfig : & corev3.TypedExtensionConfig {
290- Name : "envoy.load_balancing_policies.least_request" ,
291- TypedConfig : typedLeastRequest ,
292- },
293- }},
294- }
295- case args .loadBalancer .RoundRobin != nil :
296- cluster .LbPolicy = clusterv3 .Cluster_ROUND_ROBIN
297- roundRobin := & round_robinv3.RoundRobin {
298- LocalityLbConfig : localityLbConfig ,
299- }
300- if args .loadBalancer .RoundRobin .SlowStart != nil && args .loadBalancer .RoundRobin .SlowStart .Window != nil {
301- roundRobin .SlowStartConfig = & commonv3.SlowStartConfig {
302- SlowStartWindow : durationpb .New (args .loadBalancer .RoundRobin .SlowStart .Window .Duration ),
303- }
304- }
305- typedRoundRobin , err := proto .ToAnyWithValidation (roundRobin )
306- if err != nil {
307- return nil , err
308- }
309- cluster .LoadBalancingPolicy = & clusterv3.LoadBalancingPolicy {
310- Policies : []* clusterv3.LoadBalancingPolicy_Policy {{
311- TypedExtensionConfig : & corev3.TypedExtensionConfig {
312- Name : "envoy.load_balancing_policies.round_robin" ,
313- TypedConfig : typedRoundRobin ,
314- },
315- }},
316- }
317- case args .loadBalancer .Random != nil :
318- cluster .LbPolicy = clusterv3 .Cluster_RANDOM
319- random := & randomv3.Random {
320- LocalityLbConfig : localityLbConfig ,
321- }
322- typeRandom , err := proto .ToAnyWithValidation (random )
323- if err != nil {
324- return nil , err
325- }
326- cluster .LoadBalancingPolicy = & clusterv3.LoadBalancingPolicy {
327- Policies : []* clusterv3.LoadBalancingPolicy_Policy {{
328- TypedExtensionConfig : & corev3.TypedExtensionConfig {
329- Name : "envoy.load_balancing_policies.random" ,
330- TypedConfig : typeRandom ,
331- },
332- }},
333- }
334- case args .loadBalancer .ConsistentHash != nil :
335- cluster .LbPolicy = clusterv3 .Cluster_MAGLEV
336- consistentHash := & maglevv3.Maglev {}
337- if args .loadBalancer .ConsistentHash .TableSize != nil {
338- consistentHash .TableSize = wrapperspb .UInt64 (* args .loadBalancer .ConsistentHash .TableSize )
339- }
340- typedConsistentHash , err := proto .ToAnyWithValidation (consistentHash )
341- if err != nil {
342- return nil , err
273+ leastRequest := & least_requestv3.LeastRequest {
274+ LocalityLbConfig : localityLbConfig ,
275+ }
276+ if args .loadBalancer .LeastRequest .SlowStart != nil && args .loadBalancer .LeastRequest .SlowStart .Window != nil {
277+ leastRequest .SlowStartConfig = & commonv3.SlowStartConfig {
278+ SlowStartWindow : durationpb .New (args .loadBalancer .LeastRequest .SlowStart .Window .Duration ),
343279 }
344- cluster .LoadBalancingPolicy = & clusterv3.LoadBalancingPolicy {
345- Policies : []* clusterv3.LoadBalancingPolicy_Policy {{
346- TypedExtensionConfig : & corev3.TypedExtensionConfig {
347- Name : "envoy.load_balancing_policies.maglev" ,
348- TypedConfig : typedConsistentHash ,
349- },
350- }},
280+ }
281+ typedLeastRequest , err := proto .ToAnyWithValidation (leastRequest )
282+ if err != nil {
283+ return nil , err
284+ }
285+ cluster .LoadBalancingPolicy = & clusterv3.LoadBalancingPolicy {
286+ Policies : []* clusterv3.LoadBalancingPolicy_Policy {{
287+ TypedExtensionConfig : & corev3.TypedExtensionConfig {
288+ Name : "envoy.load_balancing_policies.least_request" ,
289+ TypedConfig : typedLeastRequest ,
290+ },
291+ }},
292+ }
293+ case args .loadBalancer .RoundRobin != nil :
294+ cluster .LbPolicy = clusterv3 .Cluster_ROUND_ROBIN
295+ roundRobin := & round_robinv3.RoundRobin {
296+ LocalityLbConfig : localityLbConfig ,
297+ }
298+ if args .loadBalancer .RoundRobin .SlowStart != nil && args .loadBalancer .RoundRobin .SlowStart .Window != nil {
299+ roundRobin .SlowStartConfig = & commonv3.SlowStartConfig {
300+ SlowStartWindow : durationpb .New (args .loadBalancer .RoundRobin .SlowStart .Window .Duration ),
351301 }
352302 }
303+ typedRoundRobin , err := proto .ToAnyWithValidation (roundRobin )
304+ if err != nil {
305+ return nil , err
306+ }
307+ cluster .LoadBalancingPolicy = & clusterv3.LoadBalancingPolicy {
308+ Policies : []* clusterv3.LoadBalancingPolicy_Policy {{
309+ TypedExtensionConfig : & corev3.TypedExtensionConfig {
310+ Name : "envoy.load_balancing_policies.round_robin" ,
311+ TypedConfig : typedRoundRobin ,
312+ },
313+ }},
314+ }
315+ case args .loadBalancer .Random != nil :
316+ cluster .LbPolicy = clusterv3 .Cluster_RANDOM
317+ random := & randomv3.Random {
318+ LocalityLbConfig : localityLbConfig ,
319+ }
320+ typeRandom , err := proto .ToAnyWithValidation (random )
321+ if err != nil {
322+ return nil , err
323+ }
324+ cluster .LoadBalancingPolicy = & clusterv3.LoadBalancingPolicy {
325+ Policies : []* clusterv3.LoadBalancingPolicy_Policy {{
326+ TypedExtensionConfig : & corev3.TypedExtensionConfig {
327+ Name : "envoy.load_balancing_policies.random" ,
328+ TypedConfig : typeRandom ,
329+ },
330+ }},
331+ }
332+ case args .loadBalancer .ConsistentHash != nil :
333+ cluster .LbPolicy = clusterv3 .Cluster_MAGLEV
334+ consistentHash := & maglevv3.Maglev {}
335+ if args .loadBalancer .ConsistentHash .TableSize != nil {
336+ consistentHash .TableSize = wrapperspb .UInt64 (* args .loadBalancer .ConsistentHash .TableSize )
337+ }
338+ typedConsistentHash , err := proto .ToAnyWithValidation (consistentHash )
339+ if err != nil {
340+ return nil , err
341+ }
342+ cluster .LoadBalancingPolicy = & clusterv3.LoadBalancingPolicy {
343+ Policies : []* clusterv3.LoadBalancingPolicy_Policy {{
344+ TypedExtensionConfig : & corev3.TypedExtensionConfig {
345+ Name : "envoy.load_balancing_policies.maglev" ,
346+ TypedConfig : typedConsistentHash ,
347+ },
348+ }},
349+ }
353350 }
354351
355352 if args .healthCheck != nil && args .healthCheck .Active != nil {
0 commit comments