From dfd2b005300a8151d80fa6eb4e41b24b3f68818a Mon Sep 17 00:00:00 2001 From: Brad House Date: Sun, 29 Nov 2026 13:14:22 +0000 Subject: [PATCH] Retry the CKS upgrade manifests while the API server restarts upgrade-kubernetes.sh applied the CNI and dashboard manifests on the first control node right after restarting containerd and kubelet, while the upgraded API server was still restarting. kubectl failed with "unexpected EOF", then with "Forbidden" until the API server authorized requests again, so the first upgrade attempt of the control node failed and only a retry of the whole script got past it. With cloud.kubernetes.cluster.upgrade.retries=0 the upgrade stopped there. Apply each manifest again every 10 seconds while it fails. No retry starts more than 180 seconds after the first attempt, and each attempt is stopped after 90 seconds, so an apply that hangs on a restarting API server is retried too. Signed-off-by: Brad House --- .../resources/script/upgrade-kubernetes.sh | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/integrations/kubernetes-service/src/main/resources/script/upgrade-kubernetes.sh b/plugins/integrations/kubernetes-service/src/main/resources/script/upgrade-kubernetes.sh index a947d508436e..fbf3d458570d 100755 --- a/plugins/integrations/kubernetes-service/src/main/resources/script/upgrade-kubernetes.sh +++ b/plugins/integrations/kubernetes-service/src/main/resources/script/upgrade-kubernetes.sh @@ -45,6 +45,22 @@ if [[ "$PATH" != *:/usr/sbin && "$PATH" != *:/usr/sbin:* ]]; then export PATH=$PATH:/usr/sbin fi +# Restarting containerd and kubelet can restart the API server: retry while it is down or refuses requests +APPLY_ATTEMPT_TIMEOUT=90 +APPLY_RETRY_TIMEOUT=180 +APPLY_RETRY_SLEEP=10 +apply_manifest() { + local deadline=$((SECONDS + APPLY_RETRY_TIMEOUT)) + until timeout -k 10 ${APPLY_ATTEMPT_TIMEOUT} /opt/bin/kubectl apply -f "$1"; do + if [ $((SECONDS + APPLY_RETRY_SLEEP)) -ge $deadline ]; then + echo "ERROR: Unable to apply $1" + return 1 + fi + echo "Unable to apply $1, retrying in ${APPLY_RETRY_SLEEP} seconds" + sleep ${APPLY_RETRY_SLEEP} + done +} + ISO_MOUNT_DIR=/mnt/k8sdisk BINARIES_DIR=${ISO_MOUNT_DIR}/ @@ -149,9 +165,9 @@ if [ -d "$BINARIES_DIR" ]; then if [ "${IS_MAIN_CONTROL}" == 'true' ]; then if [[ ${EXTERNAL_CNI} == true ]]; then - /opt/bin/kubectl apply -f ${BINARIES_DIR}/network.yaml + apply_manifest ${BINARIES_DIR}/network.yaml fi - /opt/bin/kubectl apply -f ${BINARIES_DIR}/dashboard.yaml + apply_manifest ${BINARIES_DIR}/dashboard.yaml fi umount "${ISO_MOUNT_DIR}" && rmdir "${ISO_MOUNT_DIR}"