Skip to content

Commit

Permalink
feat: probe use built-in, discarded healthcheck.sh (OT-CONTAINER-KIT#907
Browse files Browse the repository at this point in the history
)

* feat: probe use built-in, discarded healthcheck.sh

Signed-off-by: drivebyer <yang.wu@daocloud.io>

* use shell

Signed-off-by: drivebyer <yang.wu@daocloud.io>

---------

Signed-off-by: drivebyer <yang.wu@daocloud.io>
Signed-off-by: Matt Robinson <mattrobinsonsre@gmail.com>
  • Loading branch information
drivebyer authored and mattrobinsonsre committed Jul 11, 2024
1 parent 4ed274d commit 02ef604
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions k8sutils/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ func createPVCTemplate(volumeName string, stsMeta metav1.ObjectMeta, storageSpec

// generateContainerDef generates container definition for Redis
func generateContainerDef(name string, containerParams containerParameters, clusterMode, nodeConfVolume, enableMetrics bool, externalConfig, clusterVersion *string, mountpath []corev1.VolumeMount, sidecars []redisv1beta2.Sidecar) []corev1.Container {
sentinelCntr := containerParams.Role == "sentinel"
enableTLS := containerParams.TLSConfig != nil
enableAuth := containerParams.EnabledPassword != nil && *containerParams.EnabledPassword
containerDefinition := []corev1.Container{
{
Name: name,
Expand All @@ -365,8 +368,8 @@ func generateContainerDef(name string, containerParams containerParameters, clus
containerParams.Port,
clusterVersion,
),
ReadinessProbe: getProbeInfo(containerParams.ReadinessProbe),
LivenessProbe: getProbeInfo(containerParams.LivenessProbe),
ReadinessProbe: getProbeInfo(containerParams.ReadinessProbe, sentinelCntr, enableTLS, enableAuth),
LivenessProbe: getProbeInfo(containerParams.LivenessProbe, sentinelCntr, enableTLS, enableAuth),
VolumeMounts: getVolumeMount(name, containerParams.PersistenceEnabled, clusterMode, nodeConfVolume, externalConfig, mountpath, containerParams.TLSConfig, containerParams.ACLConfig),
},
}
Expand Down Expand Up @@ -595,7 +598,23 @@ func getVolumeMount(name string, persistenceEnabled *bool, clusterMode bool, nod
}

// getProbeInfo generate probe for Redis StatefulSet
func getProbeInfo(probe *commonapi.Probe) *corev1.Probe {
func getProbeInfo(probe *commonapi.Probe, sentinel, enableTLS, enableAuth bool) *corev1.Probe {
healthChecker := []string{
"redis-cli",
"-h", "$(hostname)",
}
if sentinel {
healthChecker = append(healthChecker, "-p", "${SENTINEL_PORT}")
} else {
healthChecker = append(healthChecker, "-p", "${REDIS_PORT}")
}
if enableAuth {
healthChecker = append(healthChecker, "-a", "${REDIS_PASSWORD}")
}
if enableTLS {
healthChecker = append(healthChecker, "--tls", "--cert", "${REDIS_TLS_CERT}", "--key", "${REDIS_TLS_CERT_KEY}", "--cacert", "${REDIS_TLS_CA_KEY}")
}
healthChecker = append(healthChecker, "ping")
return &corev1.Probe{
InitialDelaySeconds: probe.InitialDelaySeconds,
PeriodSeconds: probe.PeriodSeconds,
Expand All @@ -604,10 +623,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: []string{"sh", "-c", strings.Join(healthChecker, " ")},
},
},
}
Expand Down

0 comments on commit 02ef604

Please sign in to comment.