Skip to content

Commit c9528c8

Browse files
aledbfroboquat
authored andcommitted
Remove redis sentinel and add TLS support
1 parent ec73a64 commit c9528c8

File tree

4 files changed

+32
-50
lines changed

4 files changed

+32
-50
lines changed

components/registry-facade-api/go/config/config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ type RedisCacheConfig struct {
8080

8181
SingleHostAddress string `json:"singleHostAddr,omitempty"`
8282

83-
MasterName string `json:"masterName,omitempty"`
84-
SentinelAddrs []string `json:"sentinelAddrs,omitempty"`
85-
Username string `json:"username,omitempty"`
86-
Password string `json:"-" env:"REDIS_PASSWORD"`
83+
Username string `json:"username,omitempty"`
84+
Password string `json:"-" env:"REDIS_PASSWORD"`
85+
86+
UseTLS bool `json:"useTLS,omitempty"`
87+
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
8788
}
8889

8990
type IPFSCacheConfig struct {

components/registry-facade/pkg/registry/registry.go

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package registry
66

77
import (
88
"context"
9+
"crypto/tls"
910
"encoding/json"
1011
"fmt"
1112
"io/ioutil"
@@ -253,51 +254,29 @@ func NewRegistry(cfg config.Config, newResolver ResolverProvider, reg prometheus
253254
}
254255

255256
func getRedisClient(cfg *config.RedisCacheConfig) (*redis.Client, error) {
256-
if cfg.SingleHostAddress != "" {
257-
log.WithField("addr", cfg.SingleHostAddress).WithField("username", cfg.Username).Info("connecting to single Redis host")
258-
rdc := redis.NewClient(&redis.Options{
259-
Addr: cfg.SingleHostAddress,
260-
Username: cfg.Username,
261-
Password: cfg.Password,
262-
})
263-
264-
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
265-
defer cancel()
266-
267-
_, err := rdc.Ping(ctx).Result()
268-
if err != nil {
269-
return nil, xerrors.Errorf("cannot check Redis connection: %w", err)
270-
}
271-
272-
return rdc, nil
257+
if cfg.SingleHostAddress == "" {
258+
return nil, xerrors.Errorf("registry-facade setting 'singleHostAddr' is missing")
273259
}
274260

275-
if cfg.MasterName == "" {
276-
return nil, fmt.Errorf("redis masterName must not be empty")
277-
}
278-
if len(cfg.SentinelAddrs) == 0 {
279-
return nil, fmt.Errorf("redis sentinelAddrs must not be empty")
261+
opts := &redis.Options{
262+
Addr: cfg.SingleHostAddress,
263+
Username: cfg.Username,
264+
Password: cfg.Password,
280265
}
281266

282-
rdc := redis.NewFailoverClient(&redis.FailoverOptions{
283-
MasterName: cfg.MasterName,
284-
SentinelAddrs: cfg.SentinelAddrs,
285-
Username: cfg.Username,
286-
Password: cfg.Password,
287-
288-
SentinelUsername: cfg.Username,
289-
SentinelPassword: cfg.Password,
267+
if cfg.UseTLS {
268+
opts.TLSConfig = &tls.Config{
269+
// golang tls does not support verify certificate without any SANs
270+
InsecureSkipVerify: cfg.InsecureSkipVerify,
271+
}
272+
}
290273

291-
MaxRetries: 10,
292-
MinRetryBackoff: time.Millisecond * 100,
293-
MaxRetryBackoff: time.Minute * 1,
294-
ReadTimeout: time.Second * 30,
295-
WriteTimeout: time.Second * 5,
296-
})
274+
log.WithField("addr", cfg.SingleHostAddress).WithField("tls", cfg.UseTLS).Info("connecting to single Redis host")
297275

298-
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
276+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
299277
defer cancel()
300278

279+
rdc := redis.NewClient(opts)
301280
_, err := rdc.Ping(ctx).Result()
302281
if err != nil {
303282
return nil, xerrors.Errorf("cannot check Redis connection: %w", err)

install/installer/pkg/components/registry-facade/configmap.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
3838
if ucfg.Workspace.RegistryFacade.RedisCache.Enabled {
3939
cacheCfg := ucfg.Workspace.RegistryFacade.RedisCache
4040
redisCache = &regfac.RedisCacheConfig{
41-
Enabled: true,
42-
MasterName: cacheCfg.MasterName,
43-
SentinelAddrs: cacheCfg.SentinelAddrs,
44-
Username: cacheCfg.Username,
41+
Enabled: true,
42+
SingleHostAddress: cacheCfg.SingleHostAddress,
43+
Username: cacheCfg.Username,
44+
UseTLS: cacheCfg.UseTLS,
45+
InsecureSkipVerify: cacheCfg.InsecureSkipVerify,
4546
}
4647
}
4748

install/installer/pkg/config/v1/experimental/experimental.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ type WorkspaceConfig struct {
9292
IPFSAddr string `json:"ipfsAddr"`
9393
} `json:"ipfsCache"`
9494
RedisCache struct {
95-
Enabled bool `json:"enabled"`
96-
MasterName string `json:"masterName"`
97-
SentinelAddrs []string `json:"sentinelAddrs"`
98-
Username string `json:"username"`
99-
PasswordSecret string `json:"passwordSecret"`
95+
Enabled bool `json:"enabled"`
96+
SingleHostAddress string `json:"singleHostAddr"`
97+
Username string `json:"username"`
98+
PasswordSecret string `json:"passwordSecret"`
99+
UseTLS bool `json:"useTLS"`
100+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
100101
} `json:"redisCache"`
101102
} `json:"registryFacade"`
102103

0 commit comments

Comments
 (0)