configuring load balancing per ingress (#2167)

* configure load balancing through a ingress annotation

* update docs
This commit is contained in:
Elvin Efendi 2018-03-09 13:09:41 -08:00 committed by Manuel Alejandro de Brito Fontes
parent 4a49d67adc
commit 36cce00fdd
11 changed files with 156 additions and 10 deletions

View file

@ -122,6 +122,7 @@ var (
"buildLocation": buildLocation,
"buildAuthLocation": buildAuthLocation,
"buildAuthResponseHeaders": buildAuthResponseHeaders,
"buildLoadBalancingConfig": buildLoadBalancingConfig,
"buildProxyPass": buildProxyPass,
"filterRateLimits": filterRateLimits,
"buildRateLimitZones": buildRateLimitZones,
@ -277,6 +278,31 @@ func buildLogFormatUpstream(input interface{}) string {
return cfg.BuildLogFormatUpstream()
}
func buildLoadBalancingConfig(b interface{}, fallbackLoadBalancing string) string {
backend, ok := b.(*ingress.Backend)
if !ok {
glog.Errorf("expected an '*ingress.Backend' type but %T was returned", b)
return ""
}
if backend.UpstreamHashBy != "" {
return "hash {{ $upstream.UpstreamHashBy }} consistent;"
}
if backend.LoadBalancing != "" {
if backend.LoadBalancing == "round_robin" {
return ""
}
return fmt.Sprintf("%s;", backend.LoadBalancing)
}
if fallbackLoadBalancing == "round_robin" {
return ""
}
return fmt.Sprintf("%s;", fallbackLoadBalancing)
}
// buildProxyPass produces the proxy pass string, if the ingress has redirects
// (specified through the nginx.ingress.kubernetes.io/rewrite-to annotation)
// If the annotation nginx.ingress.kubernetes.io/add-base-url:"true" is specified it will