Skip to content

Commit 84f67ec

Browse files
Merge pull request #4535 from pmtk/healthchecks-fail-fast
[release-4.18] USHIFT-5379: Early quit for microshift greenboot scripts
2 parents b7de7dc + 3f5ae81 commit 84f67ec

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

packaging/greenboot/functions.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
SCRIPT_NAME=$(basename "$0")
77
SCRIPT_PID=$$
88

9+
MICROSHIFT_GREENBOOT_FAIL_MARKER=/run/microshift-greenboot-healthcheck-failed
10+
911
OCCONFIG_OPT="--kubeconfig /var/lib/microshift/resources/kubeadmin/kubeconfig"
1012
OCGET_OPT="--no-headers"
1113
OCGET_CMD="oc get ${OCCONFIG_OPT}"
@@ -126,6 +128,21 @@ function get_wait_timeout() {
126128
echo "${wait_timeout}"
127129
}
128130

131+
# Exit if previous MicroShift healthcheck scripts failed.
132+
function exit_if_fail_marker_exists() {
133+
if [ -f "${MICROSHIFT_GREENBOOT_FAIL_MARKER}" ]; then
134+
>&2 echo "'${MICROSHIFT_GREENBOOT_FAIL_MARKER}' file exists, exiting with an error"
135+
exit 1
136+
fi
137+
}
138+
139+
# Create fail marker and exit
140+
function create_fail_marker_and_exit() {
141+
>&2 echo "Creating '${MICROSHIFT_GREENBOOT_FAIL_MARKER}' file and exiting with an error."
142+
touch "${MICROSHIFT_GREENBOOT_FAIL_MARKER}"
143+
exit 1
144+
}
145+
129146
# Run a command with a second delay until it returns a zero exit status
130147
#
131148
# arg1: Time in seconds to wait for a command to succeed

packaging/greenboot/microshift-running-check-gateway-api.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ if [ "$(id -u)" -ne 0 ] ; then
4040
exit 1
4141
fi
4242

43+
exit_if_fail_marker_exists
44+
4345
echo "STARTED"
4446

4547
# Print the boot variable status
@@ -62,5 +64,5 @@ LOG_POD_EVENTS=true
6264
echo "Waiting ${WAIT_TIMEOUT_SECS}s for '${CHECK_DEPLOY_NS}' Deployments to be ready"
6365
if ! wait_for "${WAIT_TIMEOUT_SECS}" namespace_deployment_ready ; then
6466
echo "Error: Timed out waiting for '${CHECK_DEPLOY_NS}' Deployments to be ready"
65-
exit 1
67+
create_fail_marker_and_exit
6668
fi

packaging/greenboot/microshift-running-check-multus.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ if [ "$(id -u)" -ne 0 ] ; then
4040
exit 1
4141
fi
4242

43+
exit_if_fail_marker_exists
44+
4345
echo "STARTED"
4446

4547
# Print the boot variable status
@@ -62,5 +64,5 @@ LOG_POD_EVENTS=true
6264
echo "Waiting ${WAIT_TIMEOUT_SECS}s for '${CHECK_DAEMONSET_NS}' DaemonSets to be ready"
6365
if ! wait_for "${WAIT_TIMEOUT_SECS}" namespace_daemonset_ready ; then
6466
echo "Error: Timed out waiting for '${CHECK_DAEMONSET_NS}' DaemonSets to be ready"
65-
exit 1
67+
create_fail_marker_and_exit
6668
fi

packaging/greenboot/microshift-running-check-olm.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ if [ "$(id -u)" -ne 0 ] ; then
4040
exit 1
4141
fi
4242

43+
exit_if_fail_marker_exists
44+
4345
echo "STARTED"
4446

4547
# Print the boot variable status
@@ -62,5 +64,5 @@ LOG_POD_EVENTS=true
6264
echo "Waiting ${WAIT_TIMEOUT_SECS}s for '${CHECK_DEPLOY_NS}' deployments to be ready"
6365
if ! wait_for "${WAIT_TIMEOUT_SECS}" namespace_deployment_ready ; then
6466
echo "Error: Timed out waiting for '${CHECK_DEPLOY_NS}' deployments to be ready"
65-
exit 1
67+
create_fail_marker_and_exit
6668
fi

packaging/greenboot/microshift-running-check.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ LOG_FAILURE_FILES+=("/var/lib/microshift-backups/prerun_failed.log")
128128
echo "Waiting ${WAIT_TIMEOUT_SECS}s for MicroShift service to be active and not failed"
129129
if ! wait_for "${WAIT_TIMEOUT_SECS}" microshift_service_active ; then
130130
echo "Error: Timed out waiting for MicroShift service to be active"
131-
exit 1
131+
create_fail_marker_and_exit
132132
fi
133133

134134
# Wait for MicroShift API health endpoints to be OK
@@ -138,7 +138,7 @@ if ! wait_for "${WAIT_TIMEOUT_SECS}" microshift_health_endpoints_ok ; then
138138
log_failure_cmd "health-livez" "${OCGET_CMD} --raw=/livez?verbose"
139139

140140
echo "Error: Timed out waiting for MicroShift API health endpoints to be OK"
141-
exit 1
141+
create_fail_marker_and_exit
142142
fi
143143

144144
if lvmsShouldBeDeployed; then
@@ -165,7 +165,7 @@ LOG_POD_EVENTS=true
165165
echo "Waiting ${WAIT_TIMEOUT_SECS}s for any pods to be running"
166166
if ! wait_for "${WAIT_TIMEOUT_SECS}" any_pods_running ; then
167167
echo "Error: Timed out waiting for any MicroShift pod to be running"
168-
exit 1
168+
create_fail_marker_and_exit
169169
fi
170170

171171
# Wait for MicroShift core pod images to be downloaded
@@ -175,7 +175,7 @@ for i in "${!PODS_NS_LIST[@]}"; do
175175
echo "Waiting ${WAIT_TIMEOUT_SECS}s for pod image(s) from the '${CHECK_PODS_NS}' namespace to be downloaded"
176176
if ! wait_for "${WAIT_TIMEOUT_SECS}" namespace_images_downloaded; then
177177
echo "Error: Timed out waiting for pod image(s) from the '${CHECK_PODS_NS}' namespace to be downloaded"
178-
exit 1
178+
create_fail_marker_and_exit
179179
fi
180180
done
181181

@@ -187,7 +187,7 @@ for i in "${!PODS_NS_LIST[@]}"; do
187187
echo "Waiting ${WAIT_TIMEOUT_SECS}s for ${CHECK_PODS_CT} pod(s) from the '${CHECK_PODS_NS}' namespace to be in 'Ready' state"
188188
if ! wait_for "${WAIT_TIMEOUT_SECS}" namespace_pods_ready; then
189189
echo "Error: Timed out waiting for ${CHECK_PODS_CT} pod(s) in the '${CHECK_PODS_NS}' namespace to be in 'Ready' state"
190-
exit 1
190+
create_fail_marker_and_exit
191191
fi
192192
done
193193

@@ -216,5 +216,5 @@ done
216216

217217
# Exit with an error code if the pod restart check failed
218218
if ${check_failed} ; then
219-
exit 1
219+
create_fail_marker_and_exit
220220
fi

0 commit comments

Comments
 (0)