From 2d5fb8607a62450a38c37035fe9d4ef4bedd1571 Mon Sep 17 00:00:00 2001 From: kizuna-lek Date: Thu, 21 Nov 2024 19:06:46 +0800 Subject: [PATCH 1/2] chore: redis support hostnetwork in 0.9 --- pkg/lorry/engines/redis/manager.go | 5 +++++ pkg/lorry/engines/redis/redis.go | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/lorry/engines/redis/manager.go b/pkg/lorry/engines/redis/manager.go index 70a3610245d..ef3a87c4969 100644 --- a/pkg/lorry/engines/redis/manager.go +++ b/pkg/lorry/engines/redis/manager.go @@ -21,6 +21,7 @@ package redis import ( "context" + "fmt" "strings" "time" @@ -64,6 +65,10 @@ func NewManager(properties engines.Properties) (engines.DBManager, error) { redisPasswd = viper.GetString(constant.KBEnvServicePassword) } + if viper.IsSet(constant.KBEnvServicePort) { + properties["redisHost"] = fmt.Sprintf("127.0.0,1:%s", viper.GetString(constant.KBEnvServicePort)) + } + managerBase, err := engines.NewDBManagerBase(logger) if err != nil { return nil, err diff --git a/pkg/lorry/engines/redis/redis.go b/pkg/lorry/engines/redis/redis.go index 39e8b8a8c91..bf8a5ff76ec 100644 --- a/pkg/lorry/engines/redis/redis.go +++ b/pkg/lorry/engines/redis/redis.go @@ -145,10 +145,11 @@ func newClient(s *Settings) redis.UniversalClient { } func newSentinelClient(s *Settings, clusterCompName string) *redis.SentinelClient { - // TODO: use headless service directly - sentinelEnv := fmt.Sprintf("%s_SENTINEL_SERVICE", strings.ToUpper(strings.Join(strings.Split(clusterCompName, "-"), "_"))) - sentinelHost := viper.GetString(fmt.Sprintf("%s_HOST", sentinelEnv)) - sentinelPort := viper.GetString(fmt.Sprintf("%s_PORT", sentinelEnv)) + sentinelHost := fmt.Sprintf("%s-sentinel-headless", clusterCompName) + sentinelPort := "26379" + if viper.IsSet("REDIS_SENTINEL_HOST_NETWORK_PORT") { + sentinelPort = viper.GetString("REDIS_SENTINEL_HOST_NETWORK_PORT") + } opt := &redis.Options{ DB: s.DB, From e65498031ecec769c49c6636020bf1b0bae94448 Mon Sep 17 00:00:00 2001 From: kizuna-lek Date: Fri, 22 Nov 2024 11:12:33 +0800 Subject: [PATCH 2/2] fix --- pkg/lorry/engines/redis/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/lorry/engines/redis/manager.go b/pkg/lorry/engines/redis/manager.go index ef3a87c4969..e37bded9ac3 100644 --- a/pkg/lorry/engines/redis/manager.go +++ b/pkg/lorry/engines/redis/manager.go @@ -66,7 +66,7 @@ func NewManager(properties engines.Properties) (engines.DBManager, error) { } if viper.IsSet(constant.KBEnvServicePort) { - properties["redisHost"] = fmt.Sprintf("127.0.0,1:%s", viper.GetString(constant.KBEnvServicePort)) + properties["redisHost"] = fmt.Sprintf("127.0.0.1:%s", viper.GetString(constant.KBEnvServicePort)) } managerBase, err := engines.NewDBManagerBase(logger)