Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rate limit issue when more than 2 servers enabled in ingress #165

Merged
merged 1 commit into from
Jan 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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