Skip to content

Commit

Permalink
Probe use built-in, discarded healthcheck.sh
Browse files Browse the repository at this point in the history
Signed-off-by: muicoder <muicoder@gmail.com>
https://github.com/redis/redis/blob/unstable/TLS.md
The probe uses env mode to load the TLS certificate.
  • Loading branch information
muicoder committed Oct 20, 2023
1 parent 91feb40 commit 9437450
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions k8sutils/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ func generateContainerDef(name string, containerParams containerParameters, clus
containerParams.ACLConfig,
containerParams.EnvVars,
),
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),
},
}
Expand Down Expand Up @@ -551,7 +551,38 @@ 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),
"ping",
}

if params.TLSConfig != nil {
probeCommand = []string{
"redis-cli", "-p", strconv.Itoa(probePort),
"--tls",
"--cacert", "$(REDIS_TLS_CA_KEY)",
"--cert", "$(REDIS_TLS_CERT)",
"--key", "$(REDIS_TLS_CERT_KEY)",
"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,
Expand All @@ -560,10 +591,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,
},
},
}
Expand Down Expand Up @@ -613,6 +641,17 @@ func getEnvironmentVariables(role string, enabledPassword *bool, secretName *str
},
},
})
envVars = append(envVars, corev1.EnvVar{
Name: "REDISCLI_AUTH",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: *secretName,
},
Key: *secretKey,
},
},
})
}
if persistenceEnabled != nil && *persistenceEnabled {
envVars = append(envVars, corev1.EnvVar{Name: "PERSISTENCE_ENABLED", Value: "true"})
Expand Down

0 comments on commit 9437450

Please sign in to comment.