Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #116 from lucferbux/feature/readiness-probe
Browse files Browse the repository at this point in the history
Added readiness probe script
  • Loading branch information
vpavlin authored Sep 14, 2021
2 parents 4583d84 + d1fdde2 commit a72f4ec
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions readinessProbe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

function is_container_running() {
[ $(curl -s -o /dev/null -w ''%{http_code}'' localhost:8081) == "302" ]
};

function is_leader_election_ready() {
[ $(curl -s -o /dev/null -w ''%{http_code}'' localhost:4040) == "200" ]
}

function get_leader() {
echo "$(curl http://localhost:4040 2> /dev/null | python3 -c "import sys, json; print(json.load(sys.stdin)['name'])")"
}

function get_pod_name() {
echo ${HOSTNAME}
}

function is_container_leader() {
[ "$(get_leader)" == "$(get_pod_name)" ]
};

if ! is_leader_election_ready; then
# Leader election is not ready yet
exit 0
fi

if ! is_container_running; then
# Pod is waiting to become leader
exit 0
elif is_container_leader; then
# Pod is the leader
exit 0
else
# Pod is still running but it is not the leader
exit 1
fi

0 comments on commit a72f4ec

Please sign in to comment.