From 56e4a7de45dea1371237ca96e82eb7790391b3e2 Mon Sep 17 00:00:00 2001 From: Jim Gauld Date: Wed, 2 Mar 2022 16:59:48 -0500 Subject: [PATCH] Update kubelet patch restarting script to check running version This adds a version check to kubelet patch restarting script. This will only restart kubelet if the running kubelet is v1.21.8. This script requires modification depending on specific kubelet versions that are actually being patched. TESTING: - PASS: Verified restart of kubelet and isolcpus_plugin services with designer patch install and remove for only v1.21.8 Story: 2008760 Task: 44541 Signed-off-by: Jim Gauld Change-Id: I335f2a2e088ead55d32749c07e217a96d53c09a3 --- .../scripts/kubelet-restart-example | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/patch-scripts/EXAMPLE_KUBELET/scripts/kubelet-restart-example b/patch-scripts/EXAMPLE_KUBELET/scripts/kubelet-restart-example index 79630f8a..dab1c1c1 100644 --- a/patch-scripts/EXAMPLE_KUBELET/scripts/kubelet-restart-example +++ b/patch-scripts/EXAMPLE_KUBELET/scripts/kubelet-restart-example @@ -26,6 +26,12 @@ # declare -i GLOBAL_RC=$PATCH_STATUS_OK +# +# Declare subset of kubernetes versions we want to patch. +# This is customized for the particular patch. +# +declare -a PATCH_RESTART_VERSIONS=( "v1.21.8" ) + # kubelet doesn't run on storage nodes if is_storage then @@ -38,6 +44,26 @@ then systemctl status kubelet.service|grep -q "Active: active (running)" if [ $? -eq 0 ] then + # Obtain current kubelet version + KVER=$(kubectl version --short=true 2>/dev/null | grep -oP 'Client Version: \K\S+') + + # Check current kubelet version matches any expected restart versions + FOUND=0 + for val in ${PATCH_RESTART_VERSIONS[@]}; do + if [ "${val}" == "${KVER}" ]; then + FOUND=1 + break + fi + done + if [ ${FOUND} -eq 1 ]; then + loginfo "$0: Current kubelet ${KVER} found in: ${PATCH_RESTART_VERSIONS[@]}" + else + # do not restart versions that do not require patching + loginfo "$0: Current kubelet ${KVER} not found in" \ + "${PATCH_RESTART_VERSIONS[@]}, skipping kubelet restart" + exit $GLOBAL_RC + fi + # issue a systemd daemon-reload once the rpms have been installed # and before the processes have been restarted. systemctl daemon-reload