From 9190770699bee545c651910ea816ea0d10f268f0 Mon Sep 17 00:00:00 2001 From: muicoder Date: Tue, 21 Feb 2023 15:01:29 +0800 Subject: [PATCH] Probe use built-in, discarded healthcheck.sh Signed-off-by: muicoder https://github.com/redis/redis/blob/unstable/TLS.md The probe uses env mode to load the TLS certificate. --- k8sutils/statefulset.go | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/k8sutils/statefulset.go b/k8sutils/statefulset.go index b732a3afc..2e3fd2563 100644 --- a/k8sutils/statefulset.go +++ b/k8sutils/statefulset.go @@ -364,8 +364,8 @@ func generateContainerDef(name string, containerParams containerParameters, clus containerParams.Port, clusterVersion, ), - ReadinessProbe: getProbeInfo(containerParams.ReadinessProbe), - LivenessProbe: getProbeInfo(containerParams.LivenessProbe), + ReadinessProbe: getProbeInfo(containerParams, "R"), + LivenessProbe: getProbeInfo(containerParams, "L"), VolumeMounts: getVolumeMount(name, containerParams.PersistenceEnabled, clusterMode, nodeConfVolume, externalConfig, mountpath, containerParams.TLSConfig, containerParams.ACLConfig), }, } @@ -592,7 +592,35 @@ func getVolumeMount(name string, persistenceEnabled *bool, clusterMode bool, nod } // getProbeInfo generate probe for Redis StatefulSet -func getProbeInfo(probe *commonapi.Probe) *corev1.Probe { +func getProbeInfo(params containerParameters, probeType string) *corev1.Probe { + probePort := redisPort + if params.Role == "sentinel" { + probePort = sentinelPort + } + + probeCommand := []string{ + "redis-cli", "-p", strconv.Itoa(probePort), + } + if params.EnabledPassword != nil && *params.EnabledPassword { + probeCommand = append(probeCommand, "-a", "$(REDIS_PASSWORD)") + } + if params.TLSConfig != nil { + probeCommand = append(probeCommand, "--tls") + probeCommand = append(probeCommand, "--cacert", "$(REDIS_TLS_CA_KEY)") + probeCommand = append(probeCommand, "--cert", "$(REDIS_TLS_CERT)", "--key", "$(REDIS_TLS_CERT_KEY)") + } + probeCommand = append(probeCommand, "ping") + + var probe *commonapi.Probe + switch probeType { + case "R": + probe = params.ReadinessProbe + case "L": + probe = params.LivenessProbe + default: + probe = params.LivenessProbe + } + return &corev1.Probe{ InitialDelaySeconds: probe.InitialDelaySeconds, PeriodSeconds: probe.PeriodSeconds, @@ -601,10 +629,7 @@ func getProbeInfo(probe *commonapi.Probe) *corev1.Probe { SuccessThreshold: probe.SuccessThreshold, ProbeHandler: corev1.ProbeHandler{ Exec: &corev1.ExecAction{ - Command: []string{ - "bash", - "/usr/bin/healthcheck.sh", - }, + Command: probeCommand, }, }, }