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]>
https://github.com/redis/redis/blob/unstable/TLS.md
The probe uses env mode to load the TLS certificate.
  • Loading branch information
muicoder committed Mar 4, 2024
1 parent 649ebd4 commit 6734115
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions k8sutils/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),

Check warning on line 368 in k8sutils/statefulset.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/statefulset.go#L367-L368

Added lines #L367 - L368 were not covered by tests
VolumeMounts: getVolumeMount(name, containerParams.PersistenceEnabled, clusterMode, nodeConfVolume, externalConfig, mountpath, containerParams.TLSConfig, containerParams.ACLConfig),
},
}
Expand Down Expand Up @@ -592,7 +592,33 @@ 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
}

Check warning on line 599 in k8sutils/statefulset.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/statefulset.go#L595-L599

Added lines #L595 - L599 were not covered by tests

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

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

Check warning on line 619 in k8sutils/statefulset.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/statefulset.go#L601-L619

Added lines #L601 - L619 were not covered by tests
}

return &corev1.Probe{
InitialDelaySeconds: probe.InitialDelaySeconds,
PeriodSeconds: probe.PeriodSeconds,
Expand All @@ -601,10 +627,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,

Check warning on line 630 in k8sutils/statefulset.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/statefulset.go#L630

Added line #L630 was not covered by tests
},
},
}
Expand Down

0 comments on commit 6734115

Please sign in to comment.