Skip to content

Commit abfb593

Browse files
committed
fix: move kubelet --system-reserved deprecated flag to kubelet-config file
Signed-off-by: ffais <ffais@fbk.eu>
1 parent d7289b5 commit abfb593

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

images/capi/ansible/roles/kubernetes/files/usr/libexec/kubernetes/kubelet-resource-sizing.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#RPM and DEB systems kubelet sysconfig PATH
77
KUBELET_SYSCONFIG_FILES=( "/etc/sysconfig/kubelet" "/etc/default/kubelet" )
8+
KUBELET_CONFIG="/var/lib/kubelet/kubelet.conf.d/kubelet-resource-sizing.json"
89

910
for KUBELET_SYSCONFIG in "${KUBELET_SYSCONFIG_FILES[@]}"
1011
do
@@ -13,7 +14,7 @@ do
1314
# shellcheck source=/dev/null
1415
. "${KUBELET_SYSCONFIG}"
1516
# If system-reserved is already set by user, ignore
16-
if grep -q 'KUBELET_EXTRA_ARGS=.*--system-reserved' "${KUBELET_SYSCONFIG}"; then
17+
if grep -q 'systemReserved' "${KUBELET_SYSCONFIG}"; then
1718
exit 0
1819
fi
1920
fi
@@ -113,13 +114,6 @@ cpu_milicores_to_reserve() {
113114
echo "$cpu_microcores_reserved" | awk '{result = $1 / 10; if (result != int(result)) result++; printf "%d\n", result}'
114115
}
115116

116-
mkdir -p /run/kubelet
117-
# Check if system-reserved already exists
118-
if grep '.*--system-reserved' <<< "${KUBELET_EXTRA_ARGS}"; then
119-
# If system-reserved is already set by a previous run, replace old value with new one and write to /run/kubelet/extra-args.env
120-
system_reserved=$(sed -E "s|--system-reserved=cpu=[0-9]+m,memory=[0-9]+Mi|--system-reserved=cpu=$(cpu_milicores_to_reserve)m,memory=$(memory_reservation_mebibytes)Mi|" <<< "${KUBELET_EXTRA_ARGS}")
121-
echo "KUBELET_EXTRA_ARGS=${system_reserved} >/run/kubelet/extra-args.env"
122-
else
123-
# If not append system-reserved to KUBELET_EXTRA_ARGS and write to /run/kubelet/extra-args.env
124-
echo "KUBELET_EXTRA_ARGS=${KUBELET_EXTRA_ARGS} --system-reserved=cpu=$(cpu_milicores_to_reserve)m,memory=$(memory_reservation_mebibytes)Mi" >/run/kubelet/extra-args.env
125-
fi
117+
mkdir -p /var/lib/kubelet/kubelet.conf.d
118+
echo "$(jq --arg mebibytes_to_reserve "${mebibytes_to_reserve}Mi" --arg cpu_millicores_to_reserve "${cpu_millicores_to_reserve}m" \
119+
'. += {systemReserved: {"cpu": $cpu_millicores_to_reserve, "ephemeral-storage": "1Gi", "memory": $mebibytes_to_reserve}}' $KUBELET_CONFIG)" > $KUBELET_CONFIG

images/capi/ansible/roles/kubernetes/templates/usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Note: This dropin only works with kubeadm and kubelet v1.11+
22
[Service]
33
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
4-
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
4+
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml {% if kubernetes_enable_automatic_resource_sizing | bool %}--config-dir /var/lib/kubelet/kubelet.conf.d{% endif %}"
5+
# For Kubernetes v1.28 to v1.29, you can only specify --config-dir if you also set the environment variable KUBELET_CONFIG_DROPIN_DIR_ALPHA for the kubelet process (the value of that variable does not matter).
6+
{% if kubernetes_semver is version('v1.29.0', '<=') %}
7+
Environment="KUBELET_CONFIG_DROPIN_DIR_ALPHA"
8+
{% endif %}
59
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
610
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
711
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use

0 commit comments

Comments
 (0)