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

@ -599,6 +599,9 @@ func (n *NGINXController) createUpstreams(data []*extensions.Ingress, du *ingres
if upstreams[defBackend].UpstreamHashBy == "" {
upstreams[defBackend].UpstreamHashBy = anns.UpstreamHashBy
}
if upstreams[defBackend].LoadBalancing == "" {
upstreams[defBackend].LoadBalancing = anns.LoadBalancing
}
svcKey := fmt.Sprintf("%v/%v", ing.GetNamespace(), ing.Spec.Backend.ServiceName)
@ -654,6 +657,10 @@ func (n *NGINXController) createUpstreams(data []*extensions.Ingress, du *ingres
upstreams[name].UpstreamHashBy = anns.UpstreamHashBy
}
if upstreams[name].LoadBalancing == "" {
upstreams[name].LoadBalancing = anns.LoadBalancing
}
svcKey := fmt.Sprintf("%v/%v", ing.GetNamespace(), path.Backend.ServiceName)
// Add the service cluster endpoint as the upstream instead of individual endpoints

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