This repository has been archived by the owner on Mar 17, 2023. It is now read-only.
forked from jupyter-on-openshift/poc-hub-openshift-auth
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from lucferbux/feature/readiness-probe
Added readiness probe script
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |