Skip to content

Commit

Permalink
RedisPassword for containers, optimize REDIS_ADDR
Browse files Browse the repository at this point in the history
Signed-off-by: muicoder <[email protected]>
RedisPassword for instance: REDISCLI_AUTH
RedisPassword for exporter: REDIS_PASSWORD
  • Loading branch information
muicoder committed Feb 22, 2023
1 parent 8ea2170 commit afe4b60
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions k8sutils/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down

0 comments on commit afe4b60

Please sign in to comment.