From 25b24cce83a13bddfdd25464000a7074ff6df18c Mon Sep 17 00:00:00 2001 From: Arko Dasgupta Date: Sat, 4 Feb 2023 13:17:07 -0800 Subject: [PATCH] Add status in HTTPRoute when Ratelimit is disabled (#982) * Add status in HTTPRoute when Ratelimit is disabled Signed-off-by: Arko Dasgupta (cherry picked from commit ebb902bb2c6054ddbba402f10b4a764eb3ae6542) Signed-off-by: bitliu --- internal/gatewayapi/filters.go | 6 ++++++ internal/gatewayapi/runner/runner.go | 3 ++- internal/gatewayapi/translator.go | 4 ++++ internal/gatewayapi/translator_test.go | 5 +++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/gatewayapi/filters.go b/internal/gatewayapi/filters.go index 98b8eea816d..b48beafc1ad 100644 --- a/internal/gatewayapi/filters.go +++ b/internal/gatewayapi/filters.go @@ -684,6 +684,12 @@ func (t *Translator) processExtensionRefHTTPFilter(extFilter *v1beta1.LocalObjec t.processUnresolvedHTTPFilter(errMsg, filterContext) return } + if !t.GlobalRateLimitEnabled { + errMsg := fmt.Sprintf("Enable Ratelimit in the EnvoyGateway config to configure RateLimitFilter: %s/%s", + filterNs, extFilter.Name) + t.processUnresolvedHTTPFilter(errMsg, filterContext) + return + } rateLimit := &ir.RateLimit{ Global: &ir.GlobalRateLimit{ Rules: make([]*ir.RateLimitRule, len(rateLimitFilter.Spec.Global.Rules)), diff --git a/internal/gatewayapi/runner/runner.go b/internal/gatewayapi/runner/runner.go index 24769c00197..36baacb2d0f 100644 --- a/internal/gatewayapi/runner/runner.go +++ b/internal/gatewayapi/runner/runner.go @@ -55,7 +55,8 @@ func (r *Runner) subscribeAndTranslate(ctx context.Context) { // Translate and publish IRs. t := &gatewayapi.Translator{ - GatewayClassName: v1beta1.ObjectName(update.Key), + GatewayClassName: v1beta1.ObjectName(update.Key), + GlobalRateLimitEnabled: r.EnvoyGateway.RateLimit != nil, } // Translate to IR result := t.Translate(val) diff --git a/internal/gatewayapi/translator.go b/internal/gatewayapi/translator.go index 2d2e3126640..9f6084fa00b 100644 --- a/internal/gatewayapi/translator.go +++ b/internal/gatewayapi/translator.go @@ -57,6 +57,10 @@ type Translator struct { // the Infra IR. If unspecified, the default proxy // image will be used. ProxyImage string + + // GlobalRateLimitEnabled is true when global + // ratelimiting has been configured by the admin. + GlobalRateLimitEnabled bool } type TranslateResult struct { diff --git a/internal/gatewayapi/translator_test.go b/internal/gatewayapi/translator_test.go index 8651fa41068..9b3238c6828 100644 --- a/internal/gatewayapi/translator_test.go +++ b/internal/gatewayapi/translator_test.go @@ -47,8 +47,9 @@ func TestTranslate(t *testing.T) { mustUnmarshal(t, string(output), want) translator := &Translator{ - GatewayClassName: "envoy-gateway-class", - ProxyImage: "envoyproxy/envoy:translator-tests", + GatewayClassName: "envoy-gateway-class", + ProxyImage: "envoyproxy/envoy:translator-tests", + GlobalRateLimitEnabled: true, } // Add common test fixtures