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 <[email protected]>
  • Loading branch information
muicoder committed Feb 21, 2023
1 parent 7cf390e commit 99a8c90
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 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,27 @@ 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 {
var ProbeCommand []string
probePort := redisPort
if role == "sentinel" {
probePort = sentinelPort
}
if tlsConfig != nil {
ProbeCommand = []string{
"redis-cli", "-p", strconv.Itoa(probePort),
"--tls",
"--cert", tlsConfig.CertKeyFile,
"--key", tlsConfig.KeyFile,
"--cacert", tlsConfig.CaKeyFile,
"ping",
}
} else {
ProbeCommand = []string{
"redis-cli", "-p", strconv.Itoa(probePort),
"ping",
}
}
return &corev1.Probe{
InitialDelaySeconds: probe.InitialDelaySeconds,
PeriodSeconds: probe.PeriodSeconds,
Expand All @@ -446,10 +466,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 @@ -486,14 +503,23 @@ func getEnvironmentVariables(role string, enabledMetric bool, enabledPassword *b
}
}

envVars = append(envVars, corev1.EnvVar{
Name: "REDIS_ADDR",
Value: redisHost,
})
redisHost := "redis://localhost:6379"
if role == "sentinel" {
redisHost = "redis://localhost:26379"
}
RedisPassword := "REDIS_PASSWORD"
if enabledMetric {
envVars = append(envVars, corev1.EnvVar{
Name: "REDIS_ADDR",
Value: redisHost,
})
} else {
RedisPassword = "REDISCLI_AUTH"
}

if enabledPassword != nil && *enabledPassword {
envVars = append(envVars, corev1.EnvVar{
Name: "REDIS_PASSWORD",
Name: RedisPassword,
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Expand All @@ -508,7 +534,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 99a8c90

Please sign in to comment.