From ee4fe1ffb3a72b07a72858cbc2250f018056f16c Mon Sep 17 00:00:00 2001 From: bmv126 Date: Sat, 17 Feb 2024 22:10:32 +0530 Subject: [PATCH] Update template.go --- .../ingress/controller/template/template.go | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index f08eee498..6098b1833 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -877,14 +877,38 @@ func buildRateLimit(input interface{}) []string { } if loc.RateLimit.RPS.Limit > 0 { - limit := fmt.Sprintf("limit_req zone=%v burst=%v nodelay;", - loc.RateLimit.RPS.Name, loc.RateLimit.RPS.Burst) + limit := fmt.Sprintf("limit_req zone=%v", loc.RateLimit.RPS.Name) + + if loc.RateLimit.RPS.Burst == 0 { + limit = fmt.Sprintf("%v", limit) + } else { + limit = fmt.Sprintf("%v burst=%v", limit, loc.RateLimit.RPS.Burst) + } + + if loc.RateLimit.RPS.Delay < 0 { + limit = fmt.Sprintf("%v nodelay;", limit) + } else { + limit = fmt.Sprintf("%v delay=%v;", limit, loc.RateLimit.RPS.Delay) + } + limits = append(limits, limit) } if loc.RateLimit.RPM.Limit > 0 { - limit := fmt.Sprintf("limit_req zone=%v burst=%v nodelay;", - loc.RateLimit.RPM.Name, loc.RateLimit.RPM.Burst) + limit := fmt.Sprintf("limit_req zone=%v", loc.RateLimit.RPM.Name) + + if loc.RateLimit.RPM.Burst == 0 { + limit = fmt.Sprintf("%v", limit) + } else { + limit = fmt.Sprintf("%v burst=%v", limit, loc.RateLimit.RPM.Burst) + } + + if loc.RateLimit.RPM.Delay < 0 { + limit = fmt.Sprintf("%v nodelay;", limit) + } else { + limit = fmt.Sprintf("%v delay=%v;", limit, loc.RateLimit.RPM.Delay) + } + limits = append(limits, limit) }