Skip to content

Commit

Permalink
enabled self heal through readiness and liveness probes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomp21 committed Dec 26, 2024
1 parent 5d66705 commit 2db2bbe
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ response=$(
timeout -s 15 $1 \
redis-cli \
-h $REDIS_MASTER_HOST \
-p $REDIS_MASTER_PORT_NUMBER \
-p $REDIS_PORT \
ping
)
if [ "$?" -eq "124" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ response=$(
timeout -s 15 $1 \
redis-cli \
-h $REDIS_MASTER_HOST \
-p $REDIS_MASTER_PORT_NUMBER \
-p $REDIS_PORT \
ping
)
if [ "$?" -eq "124" ]; then
Expand Down
77 changes: 77 additions & 0 deletions internal/controller/reconcilers/statefulset_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,32 @@ func getMasterContainers(name, image string) []corev1.Container {
Name: fmt.Sprintf("%s-data", name),
MountPath: "/data",
},
{
Name: "health",
MountPath: "/health",
},
},
LivenessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"sh",
"-c",
"/health/ping_liveness_local.sh 5",
},
},
},
},
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"sh",
"-c",
"/health/ping_readiness_local.sh 1",
},
},
},
},
Resources: getResources(),
},
Expand All @@ -240,6 +266,17 @@ func getReplicaContainers(name, image string) []corev1.Container {
},
},
},
{
Name: "REDIS_MASTER_PASSWORD",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: name,
},
Key: PasswordSecretKey,
},
},
},
{
Name: "REDIS_REPLICATION_MODE",
Value: "replica",
Expand All @@ -256,6 +293,10 @@ func getReplicaContainers(name, image string) []corev1.Container {
Name: "HEADLESS_SERVICE",
Value: fmt.Sprintf("%s-headless", name),
},
{
Name: "ALLOW_EMPLTY_PASSWORD",
Value: "no",
},
},
Ports: []corev1.ContainerPort{
{
Expand All @@ -275,6 +316,32 @@ func getReplicaContainers(name, image string) []corev1.Container {
Name: fmt.Sprintf("%s-data", name),
MountPath: "/data",
},
{
Name: "health",
MountPath: "/health",
},
},
LivenessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"sh",
"-c",
"/health/ping_liveness_local_and_master.sh 5",
},
},
},
},
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"sh",
"-c",
"/health/ping_readiness_local_and_master.sh 1",
},
},
},
},
Resources: getResources(),
},
Expand Down Expand Up @@ -329,6 +396,16 @@ func getVolumes() []corev1.Volume {
DefaultMode: &defaultMode,
},
},
}, {
Name: "health",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "redis-health",
},
DefaultMode: &defaultMode,
},
},
},
}
}

0 comments on commit 2db2bbe

Please sign in to comment.