Skip to content

Commit

Permalink
Fix rate limit issue when more than 2 servers enabled in ingress
Browse files Browse the repository at this point in the history
Signed-off-by: Tang Le <at28997146@163.com>
  • Loading branch information
tangle329 committed Jan 24, 2017
1 parent 50297c8 commit c0aca18
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions controllers/nginx/pkg/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"strings"
text_template "text/template"

"k8s.io/kubernetes/pkg/util/sets"

"github.com/golang/glog"

"k8s.io/ingress/controllers/nginx/pkg/config"
Expand Down Expand Up @@ -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
// for connection limit by IP address and other for limiting request per second
func buildRateLimitZones(input interface{}) []string {
zones := []string{}
zones := sets.String{}

servers, ok := input.([]*ingress.Server)
if !ok {
return zones
return zones.List()
}

for _, server := range servers {
Expand All @@ -342,20 +344,24 @@ func buildRateLimitZones(input interface{}) []string {
zone := fmt.Sprintf("limit_conn_zone $binary_remote_addr zone=%v:%vm;",
loc.RateLimit.Connections.Name,
loc.RateLimit.Connections.SharedSize)
zones = append(zones, zone)
if !zones.Has(zone) {
zones.Insert(zone)
}
}

if loc.RateLimit.RPS.Limit > 0 {
zone := fmt.Sprintf("limit_req_zone $binary_remote_addr zone=%v:%vm rate=%vr/s;",
loc.RateLimit.RPS.Name,
loc.RateLimit.RPS.SharedSize,
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
Expand Down

0 comments on commit c0aca18

Please sign in to comment.