Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Probe use built-in, discarded healthcheck.sh #444

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions k8sutils/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@
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,35 @@
}

// 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 598 in k8sutils/statefulset.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/statefulset.go#L595-L598

Added lines #L595 - L598 were not covered by tests
}

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

Check warning on line 602 in k8sutils/statefulset.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/statefulset.go#L601-L602

Added lines #L601 - L602 were not covered by tests
}
if params.EnabledPassword != nil && *params.EnabledPassword {
probeCommand = append(probeCommand, "-a", "$(REDIS_PASSWORD)")

Check warning on line 605 in k8sutils/statefulset.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/statefulset.go#L604-L605

Added lines #L604 - L605 were not covered by tests
}
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)")

Check warning on line 610 in k8sutils/statefulset.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/statefulset.go#L607-L610

Added lines #L607 - L610 were not covered by tests
}
probeCommand = append(probeCommand, "ping")

Check warning on line 612 in k8sutils/statefulset.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/statefulset.go#L612

Added line #L612 was not covered by tests

var probe *commonapi.Probe
switch probeType {
case "R":
probe = params.ReadinessProbe
case "L":
probe = params.LivenessProbe
default:
probe = params.LivenessProbe

Check warning on line 621 in k8sutils/statefulset.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/statefulset.go#L614-L621

Added lines #L614 - L621 were not covered by tests
}

return &corev1.Probe{
InitialDelaySeconds: probe.InitialDelaySeconds,
PeriodSeconds: probe.PeriodSeconds,
Expand All @@ -601,10 +629,7 @@
SuccessThreshold: probe.SuccessThreshold,
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"bash",
"/usr/bin/healthcheck.sh",
},
Command: probeCommand,

Check warning on line 632 in k8sutils/statefulset.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/statefulset.go#L632

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