spotahome / redis-operator

Redis Operator creates/configures/manages high availability redis with sentinel automatic failover atop Kubernetes.
Apache License 2.0
1.48k stars 355 forks source link

When a password is configured for the Redis cluster, retrieving Redis metrics encounters failure #680

Closed elrondwong closed 6 months ago

elrondwong commented 6 months ago

curl xxxx:9121/metrics

...
redis_exporter_last_scrape_connect_time_seconds 0.000510195
redis_exporter_last_scrape_duration_seconds 0.000986078
redis_exporter_last_scrape_error{err="NOAUTH Authentication required."} 1
redis_exporter_scrape_duration_seconds_sum 1.7018189939999993
...
elrondwong commented 6 months ago
diff --git a/k8sutils/statefulset.go b/k8sutils/statefulset.go
index 7df1aa3a..6333c10b 100644
--- a/k8sutils/statefulset.go
+++ b/k8sutils/statefulset.go
@@ -477,6 +477,19 @@ func enableRedisMonitoring(params containerParameters) corev1.Container {
        if params.RedisExporterResources != nil {
                exporterDefinition.Resources = *params.RedisExporterResources
        }
+       if params.EnabledPassword != nil && *params.EnabledPassword {
+               exporterDefinition.Env = append(exporterDefinition.Env, corev1.EnvVar{
+                       Name: "REDIS_PASSWORD",
+                       ValueFrom: &corev1.EnvVarSource{
+                               SecretKeyRef: &corev1.SecretKeySelector{
+                                       LocalObjectReference: corev1.LocalObjectReference{
+                                               Name: *params.SecretName,
+                                       },
+                                       Key: *params.SecretKey,
+                               },
+                       },
+               })
+       }
        return exporterDefinition
 }

Do this, manual test pass.