#!/bin/bash
Update these two lines with at least one namespace and the pod counts that are specific to your workloads. Use the kubernetes <namespace> where your workload is deployed.
Set greenboot to read and execute the workload health check functions library.
Set the exit handler to log the exit status.
Set the script exit handler to log a `FAILURE` or `FINISHED` message depending on the exit status of the last command.
args: None
return: None
Set the system to automatically stop the script if the user running it is not 'root'.
Set the script to stop without reporting an error if the MicroShift service is not running.
Set the wait timeout for the current check based on the boot counter.
Set the script to wait for the pod images to be downloaded.
Set the script to wait for pods to enter ready state.
Verify that pods are not restarting by running, which could indicate a crash loop.
# #!/bin/bashset-eSCRIPT_NAME=$(basename $0)PODS_NS_LIST=(<user_workload_namespace1><user_workload_namespace2>)PODS_CT_LIST=(<user_workload_namespace1_pod_count><user_workload_namespace2_pod_count>)# Update these two lines with at least one namespace and the pod counts that are specific to your workloads. Use the kubernetes <namespace> where your workload is deployed.# Set greenboot to read and execute the workload health check functions library.source /usr/share/microshift/functions/greenboot.sh
# Set the exit handler to log the exit status.trap'script_exit' EXIT
# Set the script exit handler to log a `FAILURE` or `FINISHED` message depending on the exit status of the last command.# args: None# return: Nonefunctionscript_exit(){["$?"-ne0]&&status=FAILURE ||status=FINISHED
echo$status}# Set the system to automatically stop the script if the user running it is not 'root'.if[$(id-u)-ne0];thenecho"The '${SCRIPT_NAME}' script must be run with the 'root' user privileges"exit1fiecho"STARTED"# Set the script to stop without reporting an error if the MicroShift service is not running.if[$(systemctl is-enabled microshift.service 2>/dev/null)!="enabled"];thenecho"MicroShift service is not enabled. Exiting..."exit0fi# Set the wait timeout for the current check based on the boot counter.WAIT_TIMEOUT_SECS=$(get_wait_timeout)# Set the script to wait for the pod images to be downloaded.foriin${!PODS_NS_LIST[@]};doCHECK_PODS_NS=${PODS_NS_LIST[$i]}echo"Waiting ${WAIT_TIMEOUT_SECS}s for pod image(s) from the ${CHECK_PODS_NS} namespace to be downloaded"
wait_for ${WAIT_TIMEOUT_SECS} namespace_images_downloaded
done# Set the script to wait for pods to enter ready state.foriin${!PODS_NS_LIST[@]};doCHECK_PODS_NS=${PODS_NS_LIST[$i]}CHECK_PODS_CT=${PODS_CT_LIST[$i]}echo"Waiting ${WAIT_TIMEOUT_SECS}s for ${CHECK_PODS_CT} pod(s) from the ${CHECK_PODS_NS} namespace to be in 'Ready' state"
wait_for ${WAIT_TIMEOUT_SECS} namespace_pods_ready
done# Verify that pods are not restarting by running, which could indicate a crash loop.foriin${!PODS_NS_LIST[@]};doCHECK_PODS_NS=${PODS_NS_LIST[$i]}echo"Checking pod restart count in the ${CHECK_PODS_NS} namespace"
namespace_pods_not_restarting ${CHECK_PODS_NS}done
Copy to ClipboardCopied!Toggle word wrapToggle overflow