diff --git a/k8sutils/statefulset.go b/k8sutils/statefulset.go index 280ef3c82..a4424bd48 100644 --- a/k8sutils/statefulset.go +++ b/k8sutils/statefulset.go @@ -301,8 +301,8 @@ func generateContainerDef(name string, containerParams containerParameters, enab containerParams.RedisExporterEnv, containerParams.TLSConfig, ), - ReadinessProbe: getProbeInfo(containerParams.ReadinessProbe), - LivenessProbe: getProbeInfo(containerParams.LivenessProbe), + ReadinessProbe: getProbeInfo(containerParams.Role, containerParams.ReadinessProbe, containerParams.TLSConfig), + LivenessProbe: getProbeInfo(containerParams.Role, containerParams.LivenessProbe, containerParams.TLSConfig), VolumeMounts: getVolumeMount(name, containerParams.PersistenceEnabled, externalConfig, mountpath, containerParams.TLSConfig), }, } @@ -437,7 +437,47 @@ func getVolumeMount(name string, persistenceEnabled *bool, externalConfig *strin } // getProbeInfo generate probe for Redis StatefulSet -func getProbeInfo(probe *redisv1beta1.Probe) *corev1.Probe { +func getProbeInfo(role string, probe *redisv1beta1.Probe, tlsConfig *redisv1beta1.TLSConfig) *corev1.Probe { + root := "/tls/" + + // get and set Defaults + caCert := "ca.crt" + tlsCert := "tls.crt" + tlsCertKey := "tls.key" + + if tlsConfig.CaKeyFile != "" { + caCert = tlsConfig.CaKeyFile + } + if tlsConfig.CertKeyFile != "" { + tlsCert = tlsConfig.CertKeyFile + } + if tlsConfig.KeyFile != "" { + tlsCertKey = tlsConfig.KeyFile + } + + var ProbeCommand []string + + probePort := redisPort + if role == "sentinel" { + probePort = sentinelPort + } + + if tlsConfig != nil { + ProbeCommand = []string{ + "redis-cli", "-p", strconv.Itoa(probePort), + "--tls", + "--cert", path.Join(root, tlsCert), + "--key", path.Join(root, caCert), + "--cacert", path.Join(root, tlsCertKey), + "ping", + } + } else { + ProbeCommand = []string{ + "redis-cli", "-p", strconv.Itoa(probePort), + "ping", + } + } + return &corev1.Probe{ InitialDelaySeconds: probe.InitialDelaySeconds, PeriodSeconds: probe.PeriodSeconds, @@ -446,10 +486,7 @@ func getProbeInfo(probe *redisv1beta1.Probe) *corev1.Probe { SuccessThreshold: probe.SuccessThreshold, ProbeHandler: corev1.ProbeHandler{ Exec: &corev1.ExecAction{ - Command: []string{ - "bash", - "/usr/bin/healthcheck.sh", - }, + Command: ProbeCommand, }, }, } @@ -508,7 +545,7 @@ func getEnvironmentVariables(role string, enabledMetric bool, enabledPassword *b envVars = append(envVars, corev1.EnvVar{Name: "PERSISTENCE_ENABLED", Value: "true"}) } - if exporterEnvVar != nil { + if enabledMetric && exporterEnvVar != nil { envVars = append(envVars, *exporterEnvVar...) } sort.SliceStable(envVars, func(i, j int) bool {