File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
src/code.cloudfoundry.org/gorouter/route Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -667,7 +667,12 @@ func (p *EndpointPool) MarshalJSON() ([]byte, error) {
667667}
668668
669669// setPoolLoadBalancingAlgorithm overwrites the load balancing algorithm of a pool by that of a specified endpoint, if that is valid.
670+ // An empty algorithm (from a keepalive registration without algorithm field) is treated as "no change".
670671func (p * EndpointPool ) setPoolLoadBalancingAlgorithm (endpoint * Endpoint ) {
672+ if endpoint .LoadBalancingAlgorithm == "" {
673+ return
674+ }
675+
671676 if endpoint .LoadBalancingAlgorithm != p .LoadBalancingAlgorithm {
672677 if config .IsLoadBalancingAlgorithmValid (endpoint .LoadBalancingAlgorithm ) {
673678 previousAlgorithm := p .LoadBalancingAlgorithm
Original file line number Diff line number Diff line change @@ -505,6 +505,34 @@ var _ = Describe("EndpointPool", func() {
505505 Expect (pool .HashLookupTable ).To (BeNil ())
506506 Expect (pool .HashRoutingProperties ).To (BeNil ())
507507 })
508+
509+ It ("keeps the current algorithm when the endpoint does not specify one" , func () {
510+ pool := route .NewPool (& route.PoolOpts {
511+ Logger : logger .Logger ,
512+ LoadBalancingAlgorithm : config .LOAD_BALANCE_RR ,
513+ })
514+
515+ // Set up HB routing
516+ hbEndpoint := route .NewEndpoint (& route.EndpointOpts {
517+ Host : "host-1" ,
518+ Port : 1234 ,
519+ PrivateInstanceId : "id-1" ,
520+ LoadBalancingAlgorithm : config .LOAD_BALANCE_HB ,
521+ HashBalanceFactor : 1.25 ,
522+ HashHeaderName : "X-Tenant" ,
523+ })
524+ pool .Put (hbEndpoint )
525+ Expect (pool .LoadBalancingAlgorithm ).To (Equal (config .LOAD_BALANCE_HB ))
526+
527+ // Register with empty algorithm (keepalive, field not specified) — should NOT reset
528+ noAlgoEndpoint := route .NewEndpoint (& route.EndpointOpts {
529+ Host : "host-1" ,
530+ Port : 1234 ,
531+ PrivateInstanceId : "id-1" ,
532+ })
533+ pool .Put (noAlgoEndpoint )
534+ Expect (pool .LoadBalancingAlgorithm ).To (Equal (config .LOAD_BALANCE_HB ))
535+ })
508536 })
509537 It ("returns the route_service_url associated with the pool" , func () {
510538 endpoint := & route.Endpoint {}
You can’t perform that action at this time.
0 commit comments