Skip to content

Commit

Permalink
Rate Limit Service config in EnvoyGateway API (#871)
Browse files Browse the repository at this point in the history
* Rate Limit Service config in EnvoyGateway API

* Defines the configuration needed to enable as well
as connect the rate limit service to a redis database backend
* This will be required to be set by the infrastructure admin
if the app developers want the global rate limiting feature using
`RateLimitFilter`

Relates to #670

Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* address comments

Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* make url string type

Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* change from pointer to struct type

Signed-off-by: Arko Dasgupta <arko@tetrate.io>

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg authored Jan 11, 2023
1 parent fb0c155 commit 7b6e1f1
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
50 changes: 50 additions & 0 deletions api/config/v1alpha1/envoygateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ type EnvoyGatewaySpec struct {
//
// +optional
Provider *Provider `json:"provider,omitempty"`

// RateLimit defines the configuration associated with the Rate Limit service
// deployed by Envoy Gateway required to implement the Global Rate limiting
// functionality. The specific rate limit service used here is the reference
// implementation in Envoy. For more details visit https://github.com/envoyproxy/ratelimit.
// This configuration will not be needed to enable Local Rate limiitng.
//
// +optional
RateLimit *RateLimit `json:"rateLimit,omitempty"`
}

// Gateway defines the desired Gateway API configuration of Envoy Gateway.
Expand Down Expand Up @@ -86,6 +95,47 @@ type FileProvider struct {
// TODO: Add config as use cases are better understood.
}

// RateLimit defines the configuration associated with the Rate Limit Service
// used for Global Rate Limiting.
type RateLimit struct {
// Backend holds the configuration associated with the
// database backend used by the rate limit service to store
// state associated with global ratelimiting.
Backend RateLimitDatabaseBackend `json:"backend"`
}

// RateLimitDatabaseBackend defines the configuration associated with
// the database backend used by the rate limit service.
// +union
type RateLimitDatabaseBackend struct {
// Type is the type of database backend to use. Supported types are:
// * Redis: Connects to a Redis database.
//
// +unionDiscriminator
Type RateLimitDatabaseBackendType `json:"type"`
// Redis defines the settings needed to connect to a Redis database.
//
// +optional
Redis *RateLimitRedisSettings `json:"redis,omitempty"`
}

// RateLimitDatabaseBackendType specifies the types of database backend
// to be used by the rate limit service.
// +kubebuilder:validation:Enum=Redis
type RateLimitDatabaseBackendType string

const (
// RedisBackendType uses a redis database for the rate limit service.
RedisBackendType RateLimitDatabaseBackendType = "Redis"
)

// RateLimitRedisSettings defines the configuration for connecting to
// a Redis database.
type RateLimitRedisSettings struct {
// URL of the Redis Database.
URL string `json:"url"`
}

func init() {
SchemeBuilder.Register(&EnvoyGateway{})
}
56 changes: 56 additions & 0 deletions api/config/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b6e1f1

Please sign in to comment.