diff --git a/server/server.go b/server/server.go index 201368be9..b55c1d2b1 100644 --- a/server/server.go +++ b/server/server.go @@ -1438,7 +1438,7 @@ func configureBackends(backends map[string]*types.Backend) { } } } else { - log.Debugf("Validation of load balancer method for backend %s failed: %s. Using default method wrr.", backendName, err) + log.Debugf("Backend %s: %v", backendName, err) var stickiness *types.Stickiness if backend.LoadBalancer != nil { diff --git a/types/types.go b/types/types.go index 518d5a365..eed737bee 100644 --- a/types/types.go +++ b/types/types.go @@ -211,16 +211,21 @@ var loadBalancerMethodNames = []string{ // NewLoadBalancerMethod create a new LoadBalancerMethod from a given LoadBalancer. func NewLoadBalancerMethod(loadBalancer *LoadBalancer) (LoadBalancerMethod, error) { - var method string - if loadBalancer != nil { - method = loadBalancer.Method - for i, name := range loadBalancerMethodNames { - if strings.EqualFold(name, method) { - return LoadBalancerMethod(i), nil - } + if loadBalancer == nil { + return Wrr, errors.New("no load-balancer defined, fallback to 'wrr' method") + } + + if len(loadBalancer.Method) == 0 { + return Wrr, errors.New("no load-balancing method defined, fallback to 'wrr' method") + } + + for i, name := range loadBalancerMethodNames { + if strings.EqualFold(name, loadBalancer.Method) { + return LoadBalancerMethod(i), nil } } - return Wrr, fmt.Errorf("invalid load-balancing method '%s'", method) + + return Wrr, fmt.Errorf("invalid load-balancing method %q, fallback to 'wrr' method", loadBalancer.Method) } // Configurations is for currentConfigurations Map