diff --git a/k8sutils/statefulset.go b/k8sutils/statefulset.go index a853bc468..1ae3ed744 100644 --- a/k8sutils/statefulset.go +++ b/k8sutils/statefulset.go @@ -497,9 +497,7 @@ func getEnvironmentVariables(role string, enabledMetric bool, enabledPassword *b {Name: "SETUP_MODE", Value: role}, } - redisHost := "redis://localhost:6379" if tlsConfig != nil { - redisHost = "rediss://localhost:6379" envVars = append(envVars, GenerateTLSEnvironmentVariables(tlsConfig)...) if enabledMetric { envVars = append(envVars, corev1.EnvVar{ @@ -521,14 +519,28 @@ func getEnvironmentVariables(role string, enabledMetric bool, enabledPassword *b } } - envVars = append(envVars, corev1.EnvVar{ - Name: "REDIS_ADDR", - Value: redisHost, - }) + RedisPassword := "REDISCLI_AUTH" + if enabledMetric { + envVars = append(envVars, corev1.EnvVar{ + Name: "REDIS_ADDR", + Value: func(role string, tls *redisv1beta1.TLSConfig) string { + prefix := "redis://localhost:" + if tls != nil { + prefix = "rediss://localhost:" + } + if role == "sentinel" { + return prefix + strconv.Itoa(sentinelPort) + } else { + return prefix + strconv.Itoa(redisPort) + } + }(role, tlsConfig), + }) + RedisPassword = "REDIS_PASSWORD" + } if enabledPassword != nil && *enabledPassword { envVars = append(envVars, corev1.EnvVar{ - Name: "REDIS_PASSWORD", + Name: RedisPassword, ValueFrom: &corev1.EnvVarSource{ SecretKeyRef: &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{