Created
April 20, 2022 11:14
-
-
Save smarthall/041ee5915c1027f2a97d988f5922abf2 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
set -uo pipefail | |
version="" | |
CEPH_HEALTH_TIMEOUT="15m" | |
NODE_HEALTH_TIMEOUT="15m" | |
NODE_UPGRADE_TIMEOUT="15m" | |
function usage() { | |
echo "${0}" | |
echo " -h - Show Usage" | |
echo " -v [version] - (Required) Specify version for upgrade" | |
exit 1 | |
} | |
if [[ ${#} -eq 0 ]]; then | |
usage | |
fi | |
optstring=":hv:" | |
while getopts ${optstring} arg; do | |
case ${arg} in | |
v) | |
version="${OPTARG}" | |
;; | |
h) | |
usage | |
exit 1 | |
;; | |
\?) | |
echo "Invalid option: -${OPTARG}." | |
echo | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
if [ -z "${version}" ]; then | |
echo 'No version specified' | |
echo | |
usage | |
exit 1 | |
fi | |
for machine in $(kubectl get nodes -o jsonpath='{.items[*].metadata.name}'); do | |
machine_ip=$(kubectl get node ${machine} -o jsonpath='{.status.addresses[?(@.type=="InternalIP")].address}') | |
echo "Upgrading ${machine}" | |
echo -n " Checking version... " | |
machine_version=$(kubectl get node ${machine} -o jsonpath='{.metadata.labels.feature\.node\.kubernetes\.io\/system-os_release\.VERSION_ID}') | |
if [ "${machine_version}" = "${version}" ]; then | |
echo -e "already upgraded\n\n---" | |
continue | |
else | |
echo "needs upgrade" | |
fi | |
echo -n " Waiting for all nodes to be Ready... " | |
kubectl wait --for=condition=Ready nodes --all --timeout=${NODE_HEALTH_TIMEOUT} &>/dev/null | |
if [ $? -eq 0 ]; then | |
echo "ok" | |
else | |
echo "failed" | |
exit 1 | |
fi | |
echo -n " Waiting for Ceph cluster to be healthy... " | |
kubectl --namespace rook-ceph wait --timeout=${CEPH_HEALTH_TIMEOUT} --for=jsonpath='{.status.ceph.health}=HEALTH_OK' cephcluster/rook-ceph &>/dev/null | |
if [ $? -eq 0 ]; then | |
echo "ok" | |
else | |
echo "failed" | |
exit 1 | |
fi | |
# Trigger Upgrade | |
echo -n " Triggering upgrade... " | |
talosctl upgrade --image ghcr.io/siderolabs/installer:${version} --nodes ${machine_ip} &>/dev/null | |
if [ $? -eq 0 ]; then | |
echo "ok" | |
else | |
echo "failed" | |
exit 1 | |
fi | |
echo -n " Waiting for node upgrade to complete... " | |
kubectl wait node ${machine} --timeout=${NODE_UPGRADE_TIMEOUT} --for=jsonpath="{.metadata.labels.feature\.node\.kubernetes\.io\/system-os_release\.VERSION_ID}=${version}" &>/dev/null | |
if [ $? -eq 0 ]; then | |
echo "ok" | |
else | |
echo "failed" | |
exit 1 | |
fi | |
echo -e "\n---" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment