Skip to content

Commit

Permalink
Probe use built-in, discarded healthcheck.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
muicoder committed Jul 5, 2023
1 parent 8e854cb commit 200196e
Showing 1 changed file with 63 additions and 7 deletions.
70 changes: 63 additions & 7 deletions k8sutils/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ func generateContainerDef(name string, containerParams containerParameters, clus
containerParams.TLSConfig,
containerParams.ACLConfig,
),
ReadinessProbe: getProbeInfo(containerParams.ReadinessProbe),
LivenessProbe: getProbeInfo(containerParams.LivenessProbe),
ReadinessProbe: getProbeInfo(containerParams, "R"),
LivenessProbe: getProbeInfo(containerParams, "L"),
VolumeMounts: getVolumeMount(name, containerParams.PersistenceEnabled, clusterMode, externalConfig, mountpath, containerParams.TLSConfig, containerParams.ACLConfig),
},
}
Expand Down Expand Up @@ -562,7 +562,55 @@ func getVolumeMount(name string, persistenceEnabled *bool, clusterMode bool, ext
}

// getProbeInfo generate probe for Redis StatefulSet
func getProbeInfo(probe *redisv1beta1.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 {
root := "/tls/"

// get and set Defaults
caCert := "ca.crt"
tlsCert := "tls.crt"
tlsCertKey := "tls.key"

if params.TLSConfig.CaKeyFile != "" {
caCert = params.TLSConfig.CaKeyFile
}
if params.TLSConfig.CertKeyFile != "" {
tlsCert = params.TLSConfig.CertKeyFile
}
if params.TLSConfig.KeyFile != "" {
tlsCertKey = params.TLSConfig.KeyFile
}

probeCommand = []string{
"redis-cli", "-p", strconv.Itoa(probePort),
"--tls",
"--cacert", path.Join(root, caCert),
"--cert", path.Join(root, tlsCert),
"--key", path.Join(root, tlsCertKey),
"ping",
}
}

var probe *redisv1beta1.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 @@ -571,10 +619,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,
},
},
}
Expand Down Expand Up @@ -640,6 +685,17 @@ func getEnvironmentVariables(role string, enabledMetric bool, enabledPassword *b
},
},
})
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 200196e

Please sign in to comment.