Skip to content

Commit 393e2b4

Browse files
authored
fix: fix validation errors that occur when the redis url contains valid sentinel or cluster config (#6394)
* Update redis url validations to accept comma delimited list of names/hosts. Signed-off-by: keithfz <kzeto4@gmail.com>
1 parent 3aee7a6 commit 393e2b4

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

api/v1alpha1/envoygateway_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ type RedisTLSSettings struct {
505505
// RateLimitRedisSettings defines the configuration for connecting to redis database.
506506
type RateLimitRedisSettings struct {
507507
// URL of the Redis Database.
508+
// This can reference a single Redis host or a comma delimited list for Sentinel and Cluster deployments of Redis.
508509
URL string `json:"url"`
509510

510511
// TLS defines TLS configuration for connecting to redis database.

api/v1alpha1/validation/envoygateway_validate.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package validation
88
import (
99
"fmt"
1010
"net/url"
11+
"strings"
1112

1213
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
1314
)
@@ -167,8 +168,11 @@ func validateEnvoyGatewayRateLimit(rateLimit *egv1a1.RateLimit) error {
167168
if rateLimit.Backend.Redis == nil || rateLimit.Backend.Redis.URL == "" {
168169
return fmt.Errorf("empty ratelimit redis settings")
169170
}
170-
if _, err := url.Parse(rateLimit.Backend.Redis.URL); err != nil {
171-
return fmt.Errorf("unknown ratelimit redis url format: %w", err)
171+
redisHosts := strings.Split(rateLimit.Backend.Redis.URL, ",")
172+
for _, host := range redisHosts {
173+
if _, err := url.Parse(host); err != nil {
174+
return fmt.Errorf("unknown ratelimit redis url format: %w", err)
175+
}
172176
}
173177
return nil
174178
}

api/v1alpha1/validation/envoygateway_validate_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,42 @@ func TestValidateEnvoyGateway(t *testing.T) {
302302
},
303303
expect: true,
304304
},
305+
{
306+
name: "happy ratelimit redis sentinel settings",
307+
eg: &egv1a1.EnvoyGateway{
308+
EnvoyGatewaySpec: egv1a1.EnvoyGatewaySpec{
309+
Gateway: egv1a1.DefaultGateway(),
310+
Provider: egv1a1.DefaultEnvoyGatewayProvider(),
311+
RateLimit: &egv1a1.RateLimit{
312+
Backend: egv1a1.RateLimitDatabaseBackend{
313+
Type: egv1a1.RedisBackendType,
314+
Redis: &egv1a1.RateLimitRedisSettings{
315+
URL: "primary_.-,node-0:26379,node-1:26379",
316+
},
317+
},
318+
},
319+
},
320+
},
321+
expect: true,
322+
},
323+
{
324+
name: "happy ratelimit redis cluster settings",
325+
eg: &egv1a1.EnvoyGateway{
326+
EnvoyGatewaySpec: egv1a1.EnvoyGatewaySpec{
327+
Gateway: egv1a1.DefaultGateway(),
328+
Provider: egv1a1.DefaultEnvoyGatewayProvider(),
329+
RateLimit: &egv1a1.RateLimit{
330+
Backend: egv1a1.RateLimitDatabaseBackend{
331+
Type: egv1a1.RedisBackendType,
332+
Redis: &egv1a1.RateLimitRedisSettings{
333+
URL: "node-0:6376,node-1:6376,node-2:6376",
334+
},
335+
},
336+
},
337+
},
338+
},
339+
expect: true,
340+
},
305341
{
306342
name: "happy extension settings",
307343
eg: &egv1a1.EnvoyGateway{

release-notes/current.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bug fixes: |
4444
Fixed validation issue where EnvoyExtensionPolicy ExtProc failOpen is true, and body processing mode FullDuplexStreamed is not rejected.
4545
Add ConfigMap indexers for EnvoyExtensionPolicies to reconcile Lua changes
4646
Fixed issue that default accesslog format not working.
47-
47+
Fixed validation errors when the rateLimit url for Redis in the EnvoyGateway API includes multiple comma separated hosts.
4848
4949
# Enhancements that improve performance.
5050
performance improvements: |

site/content/en/latest/api/extension_types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4009,7 +4009,7 @@ _Appears in:_
40094009

40104010
| Field | Type | Required | Default | Description |
40114011
| --- | --- | --- | --- | --- |
4012-
| `url` | _string_ | true | | URL of the Redis Database. |
4012+
| `url` | _string_ | true | | URL of the Redis Database.<br />This can reference a single Redis host or a comma delimited list for Sentinel and Cluster deployments of Redis. |
40134013
| `tls` | _[RedisTLSSettings](#redistlssettings)_ | false | | TLS defines TLS configuration for connecting to redis database. |
40144014

40154015

0 commit comments

Comments
 (0)