Skip to content

Commit

Permalink
Merge pull request #254 from dciabrin/galera-probe
Browse files Browse the repository at this point in the history
Fix non-Primary checks in liveness probe
  • Loading branch information
openshift-merge-bot[bot] authored Aug 5, 2024
2 parents 2d771bf + a4dd8b1 commit aa357cc
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions templates/galera/bin/mysql_probe.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
#!/bin/bash
set -eu
set -u

# This secret is mounted by k8s and always up to date
read -s -u 3 3< /var/lib/secrets/dbpassword MYSQL_PWD || true
export MYSQL_PWD

PROBE_USER=root
function mysql_status_check {
local status=$1
local expect=$2
set -x
mysql -u${PROBE_USER} -sNEe "show status like '${status}';" | tail -1 | grep -w -e "${expect}"
}

# Consider the pod has "started" once mysql is reachable
# and is part of the primary partition
if [ "$1" = "startup" ]; then
mysql -u${PROBE_USER} -sNe "select(1);"
mysql_status_check wsrep_cluster_status Primary
exit $?
fi

set -x
# readiness and liveness probes are run by k8s only after start probe succeeded

case "$1" in
readiness)
# If the node is e.g. a donor, it cannot serve traffic
mysql -u${PROBE_USER} -sNe "show status like 'wsrep_local_state_comment';" | grep -w -e Synced;;
mysql_status_check wsrep_local_state_comment Synced
;;
liveness)
# If the node is not in the primary partition, restart it
mysql -u${PROBE_USER} -sNe "show status like 'wsrep_cluster_status';" | grep -w -e Primary;;
# If the node is not in the primary partition, the failed liveness probe
# will make k8s restart this pod
mysql_status_check wsrep_cluster_status Primary
;;
*)
echo "Invalid probe option '$1'"
exit 1;;
Expand Down

0 comments on commit aa357cc

Please sign in to comment.