@@ -12,7 +12,7 @@ port=${GATEWAY_HTTP_PORT:-8088}
1212status_endpoint=" http://localhost:${port} /system/gwinfo"
1313timeout_secs=3
1414expected_context_state=RUNNING
15- expected_redundant_state= Good
15+ expected_redundant_states=( Good OutOfDate Incompatible)
1616
1717# ##############################################################################
1818# Invoke a Redundancy-aware Health Check
@@ -23,7 +23,7 @@ function main() {
2323 exit 1
2424 fi
2525
26- debug " Status endpoint: ${status_endpoint} , expecting context state: ${expected_context_state} , expecting redundant state: ${expected_redundant_state} , timeout: ${timeout_secs} ."
26+ debug " Status endpoint: ${status_endpoint} , expecting context state: ${expected_context_state} , expecting redundant states: [ ${expected_redundant_states[*]} ] , timeout: ${timeout_secs} ."
2727
2828 curl_output=$( curl -s --max-time " ${timeout_secs} " -L -k -f " ${status_endpoint} " 2>&1 )
2929
@@ -43,17 +43,32 @@ function main() {
4343 echo " FAILED: ContextStatus is ${gwinfo_fields[ContextStatus]} , expected ${expected_context_state} " >&2
4444 exit 1
4545 fi
46- elif [ " ${gwinfo_fields[RedundantState]} " != " ${expected_redundant_state} " ] ; then
46+ elif ! validate_redundant_state " ${gwinfo_fields[RedundantState]} " ; then
4747 # Check RedundantNodeActiveStatus field
4848 if [ " ${gwinfo_fields[RedundantNodeActiveStatus]} " != " Active" ]; then
49- echo " FAILED: Not Active and RedundantState is ${gwinfo_fields[RedundantState]} , expected ${expected_redundant_state} " >&2
49+ echo " FAILED: Not Active and RedundantState is ${gwinfo_fields[RedundantState]} , expected one of: [ ${expected_redundant_states[*]} ] " >&2
5050 exit 1
5151 fi
5252 fi
5353 debug " SUCCESS"
5454 exit 0
5555}
5656
57+ # ##############################################################################
58+ # Validate redundant state against expected states
59+ # ##############################################################################
60+ function validate_redundant_state() {
61+ local actual_state=" $1 "
62+
63+ for expected_state in " ${expected_redundant_states[@]} " ; do
64+ if [ " ${actual_state,,} " = " ${expected_state,,} " ]; then
65+ return 0
66+ fi
67+ done
68+
69+ return 1
70+ }
71+
5772# ##############################################################################
5873# Outputs to stderr
5974# ##############################################################################
@@ -70,23 +85,29 @@ function debug() {
7085function usage() {
7186# usage redundant-health-check.sh
7287 >&2 echo " Usage: $0 [flags] STATUS_ENDPOINT"
73- >&2 echo " Example: ./redundant-health-check.sh -r Good - s RUNNING http://localhost:8088/system/gwinfo"
88+ >&2 echo " Example: ./redundant-health-check.sh -s RUNNING http://localhost:8088/system/gwinfo"
7489 >&2 echo " Flags:"
75- >&2 echo " -r <state> - Expected redundant state (default: Good)"
76- >&2 echo " -s <path/to/gan/secret > - The path to the mounted secret containing the webserver TLS certs/keystore (default: ${WEB_TLS_SECRETS_DIR} ) "
77- >&2 echo " -d <path/to/data/folder > - The path to the Ignition data folder (default: ${IGNITION_DATA_DIR} ) "
90+ >&2 echo " -r <state> - Expected redundant state (can be specified multiple times, defaults to ' Good', 'OutOfDate', and 'Incompatible' when omitted )"
91+ >&2 echo " -s <state > - Expected context state, defaults to 'RUNNING' "
92+ >&2 echo " -t <seconds > - Timeout in seconds for the health check request, defaults to 3 seconds "
7893 >&2 echo " -h - Print this help message"
7994 >&2 echo " -v - Enable verbose output"
8095}
8196
8297# Argument Processing
98+ first_expected_state=true
8399while getopts " :hvr:s:t:" opt; do
84100 case " $opt " in
85101 v)
86102 verbose=1
87103 ;;
88104 r)
89- expected_redundant_state=${OPTARG}
105+ # If this is the first -r argument, clear the default and start fresh
106+ if [ " ${first_expected_state} " = true ]; then
107+ expected_redundant_states=()
108+ first_expected_state=false
109+ fi
110+ expected_redundant_states+=(" ${OPTARG} " )
90111 ;;
91112 s)
92113 expected_context_state=${OPTARG}
0 commit comments