Dump rancher logs when webhook fails to deploy

This commit is contained in:
Jake Hyde
2024-05-24 16:42:44 -04:00
parent 40f891d0e5
commit 8d2d374706
2 changed files with 11 additions and 0 deletions

View File

@@ -121,6 +121,7 @@ dump_rancher_logs()
cat /tmp/rancher.log | gzip | base64 -w 0
echo -e "\n-----RANCHER-LOG-DUMP-END-----"
}
export -f dump_rancher_logs
# Compile Rancher
# This needs to happen before build_and_run_rancher is executed in the background.
@@ -150,6 +151,7 @@ echo "Waiting up to 5 minutes for rancher-webhook deployment"
--sleep 2 `# Sleep for 2 seconds in between attempts` \
--message-interval 30 `# Print the progress message below every 30 attempts (roughly every minute)` \
--message "rancher-webhook was not available after {{elapsed}} seconds" `# Print this progress message` \
--exit-command "dump_rancher_logs" `# Dump logs to find out why webhook did not start` \
"kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml rollout status -w -n cattle-system deploy/rancher-webhook &>/dev/null"
echo "Waiting up to 5 minutes for rancher-provisioning-capi deployment"
@@ -158,6 +160,7 @@ echo "Waiting up to 5 minutes for rancher-provisioning-capi deployment"
--sleep 2 `# Sleep for 2 seconds in between attempts` \
--message-interval 30 `# Print the progress message below every 30 attempts (roughly every minute)` \
--message "rancher-provisioning-capi was not available after {{elapsed}} seconds" `# Print this progress message` \
--exit-command "dump_rancher_logs" `# Dump logs to find out why webhook did not start` \
"kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml rollout status -w -n cattle-provisioning-capi-system deploy/capi-controller-manager &>/dev/null"

View File

@@ -22,6 +22,7 @@ print_usage() {
echo " elapsed time (in seconds) and total attempts respectively."
echo " -i, --message-interval The number of command attempts to make before each printing of the progress message"
echo " (default: 5)."
echo " -e, --exit-command Optional command to run before exiting (default: '')"
echo
}
@@ -50,6 +51,10 @@ while [[ $# -gt 0 ]]; do
shift
messageInterval="$1"
;;
-e | --exit-command)
shift
exitCommand="$1"
;;
*)
cmd="$@"
break
@@ -82,5 +87,8 @@ done
# If we timed out, print the final progress message and exit with code 1.
if [ "$elapsedSeconds" -gt "$timeoutSeconds" ]; then
print_progress
if [ -n "$exitCommand" ]; then
eval "$exitCommand"
fi
exit 1
fi