Skip to content

Commit

Permalink
Add status in HTTPRoute when Ratelimit is disabled (#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>
  • Loading branch information
arkodg committed Feb 4, 2023
1 parent 82e7672 commit ebb902b
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 ebb902b

Please sign in to comment.