Fix rate limit issue when more than 2 servers enabled in ingress
Signed-off-by: Tang Le <at28997146@163.com>
This commit is contained in:
parent
50297c8f47
commit
c0aca1833a
1 changed files with 11 additions and 5 deletions
|
@ -26,6 +26,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
text_template "text/template"
|
text_template "text/template"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
"k8s.io/ingress/controllers/nginx/pkg/config"
|
"k8s.io/ingress/controllers/nginx/pkg/config"
|
||||||
|
@ -328,11 +330,11 @@ func buildProxyPass(b interface{}, loc interface{}) string {
|
||||||
// rate limiting of request. Each Ingress rule could have up to two zones, one
|
// rate limiting of request. Each Ingress rule could have up to two zones, one
|
||||||
// for connection limit by IP address and other for limiting request per second
|
// for connection limit by IP address and other for limiting request per second
|
||||||
func buildRateLimitZones(input interface{}) []string {
|
func buildRateLimitZones(input interface{}) []string {
|
||||||
zones := []string{}
|
zones := sets.String{}
|
||||||
|
|
||||||
servers, ok := input.([]*ingress.Server)
|
servers, ok := input.([]*ingress.Server)
|
||||||
if !ok {
|
if !ok {
|
||||||
return zones
|
return zones.List()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, server := range servers {
|
for _, server := range servers {
|
||||||
|
@ -342,7 +344,9 @@ func buildRateLimitZones(input interface{}) []string {
|
||||||
zone := fmt.Sprintf("limit_conn_zone $binary_remote_addr zone=%v:%vm;",
|
zone := fmt.Sprintf("limit_conn_zone $binary_remote_addr zone=%v:%vm;",
|
||||||
loc.RateLimit.Connections.Name,
|
loc.RateLimit.Connections.Name,
|
||||||
loc.RateLimit.Connections.SharedSize)
|
loc.RateLimit.Connections.SharedSize)
|
||||||
zones = append(zones, zone)
|
if !zones.Has(zone) {
|
||||||
|
zones.Insert(zone)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if loc.RateLimit.RPS.Limit > 0 {
|
if loc.RateLimit.RPS.Limit > 0 {
|
||||||
|
@ -350,12 +354,14 @@ func buildRateLimitZones(input interface{}) []string {
|
||||||
loc.RateLimit.RPS.Name,
|
loc.RateLimit.RPS.Name,
|
||||||
loc.RateLimit.RPS.SharedSize,
|
loc.RateLimit.RPS.SharedSize,
|
||||||
loc.RateLimit.RPS.Limit)
|
loc.RateLimit.RPS.Limit)
|
||||||
zones = append(zones, zone)
|
if !zones.Has(zone) {
|
||||||
|
zones.Insert(zone)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return zones
|
return zones.List()
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildRateLimit produces an array of limit_req to be used inside the Path of
|
// buildRateLimit produces an array of limit_req to be used inside the Path of
|
||||||
|
|
Loading…
Reference in a new issue