-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add health check probe for k8s upgrade containers. #15223
Changes from 3 commits
d819b27
4b53a12
a74b408
28ae09b
30b4c06
353c0c0
95008f7
f914042
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
# This script is used by k8s to check the readiness of containers | ||
# Check if the container is readiness or not, exit code 0 means readiness, others mean not readiness | ||
|
||
#### exit code contract, k8s only cares zero or not none-zero, but we want to use none-zero code to indicate different error | ||
# 0: readiness | ||
# 1: python script crach exit code | ||
# 2: supervisor start service doesn't exit normally | ||
# other exit code: returned by post_check_script, define in the post_check_script, should not include 1,2 | ||
|
||
# check if the start service exists | ||
# if the start service exists, check if it exits normally | ||
# if the start service doesn't exist normally, exit with code 2 | ||
pre_check_service_name="start" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The critical processes unexpected event will be handled by the supervisord exit-listener for now, the listener will kill the container, I don't think we need to check them here. Is this correct? |
||
supervisorctl status |awk '{print $1}' |grep -w $pre_check_service_name > /dev/null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only do "supervisorctl status start", We can't do judgement by exit code, because start not existing and some failed state exit codes are the same. If only do "supervisorctl status start", need to judge by the outputs "start: ERROR (no such process)", "start EXITED Jun 21 05:28 PM". I do checking whether start exists in advance, I think code logic is more easy to understand here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an example
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
start_check_result=$? | ||
if [ $start_check_result = 0 ] && [ $(supervisorctl status $pre_check_service_name |awk '{print $2}') != 'EXITED' ]; then | ||
exit 2 | ||
fi | ||
|
||
# feature owner can add their own readiness check script | ||
# check if the post_check_script exists | ||
# if the post_check_script exists, run it | ||
# if the post_check_script exits with non-zero code, exit with the code | ||
post_check_script="/usr/bin/readiness_probe.py" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
if [ -f $post_check_script ]; then | ||
python3 $post_check_script | ||
post_check_result=$? | ||
if [ $post_check_result != 0 ]; then | ||
exit $post_check_result | ||
fi | ||
fi | ||
|
||
exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed