Skip to content

Commit

Permalink
Add status in HTTPRoute when Ratelimit is disabled (envoyproxy#982)
Browse files Browse the repository at this point in the history
* Add status in HTTPRoute when Ratelimit is disabled

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
(cherry picked from commit ebb902b)
Signed-off-by: bitliu <bitliu@tencent.com>
  • Loading branch information
arkodg authored and Xunzhuo committed Feb 10, 2023
1 parent c7cbef0 commit 25b24cc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions internal/gatewayapi/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
3 changes: 2 additions & 1 deletion internal/gatewayapi/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions internal/gatewayapi/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions internal/gatewayapi/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 25b24cc

Please sign in to comment.