Files
update/software/upgrade-scripts/02-k8s-disable-sched-controllermanager-leader-election.sh
Luis Eduardo Bonatti e93d1686f5 Move upgrade scripts from config repo to update repo
Since upgrade is responsibility of USM the upgrade scripts need
to be moved to this repo. This commit adds the upgrade-scripts
from config, note that the upgrade-scripts will still be located
under /usr/local/share/upgrade.d folder.
There's also a change in upgrade-scripts to use the log function
from this repo instead of controllerconfig one.
Also fix a log error in deploy scripts.

Test Plan:
PASS: Build-pkgs && build-image.
PASS: Upgrade from 24.09 to 25.09 in sx.
PASS: Install/bootstrap 25.09 in sx.
PASS: Check if /usr/local/share/upgrade.d have the same scripts.
PASS: Check scripts are logging accordingly.

Story: 2011357
Task: 52196

Change-Id: Iab5e6d6f0348f996daf0adb2447d22c4216e537f
Signed-off-by: Luis Eduardo Bonatti <luizeduardo.bonatti@windriver.com>
2025-05-22 13:17:48 +00:00

73 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# This script adds system service parameters for service kubernetes
# for sections kube_scheduler and kube_controller_manager.
#
# This script relies on 'kubernetes-service-parameters-apply.py'
# to apply the parameters to kubeapi, needing to be executed before it.
#
# As this script does not restart any kubernetes components, we do not
# need to run k8s health check here.
#
NAME=$(basename "$0")
# The migration scripts are passed these parameters:
FROM_RELEASE=$1
TO_RELEASE=$2
ACTION=$3
SOFTWARE_LOG_PATH="/var/log/software.log"
function log {
echo "$(date -Iseconds | cut -d'+' -f1): ${NAME}[$$]: INFO: $*" >> "${SOFTWARE_LOG_PATH}" 2>&1
}
log "Disable leader election for kube-scheduler and kube-controller-manager"\
"from $FROM_RELEASE to $TO_RELEASE with action $ACTION"
if [[ "${ACTION}" == "activate" ]]; then
source /etc/platform/platform.conf
if [[ "${nodetype}" == "controller" ]] && [[ "${system_mode}" == "simplex" ]]; then
source /etc/platform/openrc
for section in kube_scheduler kube_controller_manager; do
value=$(system service-parameter-list --service kubernetes \
--section "${section}" --format value | awk '/leader-elect/ {print $5}')
if [[ "${value}" == "false" ]]; then
log "Service parameter leader-elect=false already exists for section ${section}."\
"Nothing to do."
elif [[ "${value}" == "" ]]; then
system service-parameter-add kubernetes "${section}" leader-elect=false
RC=$?
if [ ${RC} == 0 ]; then
log "Successfully added service parameter leader-elect=false for ${section}"
else
log "Command service-parameter-add failed for section ${section}."\
"Exiting for manual intervention or retry of the activation."
exit 1
fi
else
# 'true' or any garbage value
system service-parameter-modify kubernetes "${section}" leader-elect=false
RC=$?
if [ ${RC} == 0 ]; then
log "Successfully updated service parameter leader-elect=false for ${section}"
else
log "Command service-parameter-modify failed for section ${section}."\
"Exiting for manual intervention or retry of the activation."
exit 1
fi
fi
done
else
log "No actions required for ${system_mode}-${nodetype}"
fi
else
log "No actions required from release ${FROM_RELEASE} to ${TO_RELEASE} with action ${ACTION}"
fi
exit 0