mirror of
https://github.com/containous/traefik.git
synced 2024-10-27 10:25:21 +03:00
extract lb configuration steps into method
This commit is contained in:
parent
a2d68ed881
commit
58ffea6627
@ -735,16 +735,7 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
|||||||
rebalancer, _ = roundrobin.NewRebalancer(rr, roundrobin.RebalancerLogger(oxyLogger), roundrobin.RebalancerStickySession(sticky))
|
rebalancer, _ = roundrobin.NewRebalancer(rr, roundrobin.RebalancerLogger(oxyLogger), roundrobin.RebalancerStickySession(sticky))
|
||||||
}
|
}
|
||||||
lb = rebalancer
|
lb = rebalancer
|
||||||
for serverName, server := range configuration.Backends[frontend.Backend].Servers {
|
if err := configureLBServers(rebalancer, configuration, frontend); err != nil {
|
||||||
url, err := url.Parse(server.URL)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Error parsing server URL %s: %v", server.URL, err)
|
|
||||||
log.Errorf("Skipping frontend %s...", frontendName)
|
|
||||||
continue frontend
|
|
||||||
}
|
|
||||||
log.Debugf("Creating server %s at %s with weight %d", serverName, url.String(), server.Weight)
|
|
||||||
if err := rebalancer.UpsertServer(url, roundrobin.Weight(server.Weight)); err != nil {
|
|
||||||
log.Errorf("Error adding server %s to load balancer: %v", server.URL, err)
|
|
||||||
log.Errorf("Skipping frontend %s...", frontendName)
|
log.Errorf("Skipping frontend %s...", frontendName)
|
||||||
continue frontend
|
continue frontend
|
||||||
}
|
}
|
||||||
@ -753,7 +744,6 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
|||||||
log.Debugf("Setting up backend health check %s", *hcOpts)
|
log.Debugf("Setting up backend health check %s", *hcOpts)
|
||||||
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(*hcOpts)
|
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(*hcOpts)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
case types.Wrr:
|
case types.Wrr:
|
||||||
log.Debugf("Creating load-balancer wrr")
|
log.Debugf("Creating load-balancer wrr")
|
||||||
if stickysession {
|
if stickysession {
|
||||||
@ -765,20 +755,10 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
lb = rr
|
lb = rr
|
||||||
for serverName, server := range configuration.Backends[frontend.Backend].Servers {
|
if err := configureLBServers(rr, configuration, frontend); err != nil {
|
||||||
url, err := url.Parse(server.URL)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Error parsing server URL %s: %v", server.URL, err)
|
|
||||||
log.Errorf("Skipping frontend %s...", frontendName)
|
log.Errorf("Skipping frontend %s...", frontendName)
|
||||||
continue frontend
|
continue frontend
|
||||||
}
|
}
|
||||||
log.Debugf("Creating server %s at %s with weight %d", serverName, url.String(), server.Weight)
|
|
||||||
if err := rr.UpsertServer(url, roundrobin.Weight(server.Weight)); err != nil {
|
|
||||||
log.Errorf("Error adding server %s to load balancer: %v", server.URL, err)
|
|
||||||
log.Errorf("Skipping frontend %s...", frontendName)
|
|
||||||
continue frontend
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hcOpts := parseHealthCheckOptions(rr, frontend.Backend, configuration.Backends[frontend.Backend].HealthCheck, globalConfiguration.HealthCheck)
|
hcOpts := parseHealthCheckOptions(rr, frontend.Backend, configuration.Backends[frontend.Backend].HealthCheck, globalConfiguration.HealthCheck)
|
||||||
if hcOpts != nil {
|
if hcOpts != nil {
|
||||||
log.Debugf("Setting up backend health check %s", *hcOpts)
|
log.Debugf("Setting up backend health check %s", *hcOpts)
|
||||||
@ -901,6 +881,22 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
|||||||
return serverEntryPoints, nil
|
return serverEntryPoints, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func configureLBServers(lb healthcheck.LoadBalancer, config *types.Configuration, frontend *types.Frontend) error {
|
||||||
|
for serverName, server := range config.Backends[frontend.Backend].Servers {
|
||||||
|
u, err := url.Parse(server.URL)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Error parsing server URL %s: %v", server.URL, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debugf("Creating server %s at %s with weight %d", serverName, u, server.Weight)
|
||||||
|
if err := lb.UpsertServer(u, roundrobin.Weight(server.Weight)); err != nil {
|
||||||
|
log.Errorf("Error adding server %s to load balancer: %v", server.URL, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func configureIPWhitelistMiddleware(whitelistSourceRanges []string) (negroni.Handler, error) {
|
func configureIPWhitelistMiddleware(whitelistSourceRanges []string) (negroni.Handler, error) {
|
||||||
if len(whitelistSourceRanges) > 0 {
|
if len(whitelistSourceRanges) > 0 {
|
||||||
ipSourceRanges := whitelistSourceRanges
|
ipSourceRanges := whitelistSourceRanges
|
||||||
|
Loading…
Reference in New Issue
Block a user