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 Feb 22, 2023
1 parent 7cf390e commit 8ea2170
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions k8sutils/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}
Expand Down Expand Up @@ -437,7 +437,45 @@ 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 {
probePort := redisPort
if role == "sentinel" {
probePort = sentinelPort
}

ProbeCommand := []string{
"redis-cli", "-p", strconv.Itoa(probePort),
"ping",
}

if tlsConfig != nil {
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
}

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",
}
}

return &corev1.Probe{
InitialDelaySeconds: probe.InitialDelaySeconds,
PeriodSeconds: probe.PeriodSeconds,
Expand All @@ -446,10 +484,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 @@ -508,7 +543,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 {
Expand Down

0 comments on commit 8ea2170

Please sign in to comment.