forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add health check probe for k8s upgrade containers. (sonic-net#15223)
#### Why I did it After k8s upgrade a container, k8s can only know the container is running, don't know the service's status inside container. So we need a probe inside container, k8s will call the probe to check whether the container is really ready. ##### Work item tracking - Microsoft ADO **(number only)**: 22453004 #### How I did it Add a health check probe inside config engine container, the probe will check whether the start service exit normally or not if the start service exists and call the python script to do container self-related specific checks if the script is there. The python script should be implemented by feature owner if it's needed. more details: [design doc](https://github.com/sonic-net/SONiC/blob/master/doc/kubernetes/health-check.md) #### How to verify it Check path /usr/bin/readiness_probe.sh inside container. #### Which release branch to backport (provide reason below if selected) - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 - [x] 202205 - [x] 202211 #### Tested branch (Please provide the tested image version) - [x] 20220531.28
- Loading branch information
1 parent
c589230
commit c470b7d
Showing
6 changed files
with
43 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
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
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
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
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
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,35 @@ | ||
#!/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: if the hook script is python code, the default crash exit code is 1 | ||
# 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 doesn't exist, do nothing | ||
# if the start service exists, check if it exits normally | ||
# if the start service doesn't exit normally, exit with code 2 | ||
pre_check_service_name="start" | ||
no_process_string="ERROR (no such process)" | ||
service_status=$(supervisorctl status $pre_check_service_name) | ||
if [[ $service_status != *"$no_process_string"* ]] && [[ $(echo $service_status |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_hook" | ||
if [ -x $post_check_script ]; then | ||
$post_check_script | ||
post_check_result=$? | ||
if [ $post_check_result != 0 ]; then | ||
exit $post_check_result | ||
fi | ||
fi | ||
|
||
exit 0 |