From b92a9d1f3fbb311e17a51d5050b67506edd2e952 Mon Sep 17 00:00:00 2001 From: Brad House Date: Sun, 22 Nov 2026 21:10:07 +0000 Subject: [PATCH] Check net.ipv4.ip_forward in validate-cks-node - validate-cks-node now fails when /proc/sys/net/ipv4/ip_forward is not 1 - kubeadm join preflight requires it; without it an added external node passes validation, is rebooted into the join userdata and then fails kubeadm preflight with a less obvious error - each check adds its message to a FAILURES list; the script prints them all and exits 1 if there are any, so a new check is one more `if` block - missing packages and ip_forward are reported together in one run - the caller's log line says the node failed validation, not that it lacks dependencies, since the reason may not be a package - reads /proc rather than calling sysctl, which is not on a non-root user's PATH on Debian Signed-off-by: Brad House --- .../actionworkers/KubernetesClusterAddWorker.java | 4 ++-- .../src/main/resources/script/validate-cks-node | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterAddWorker.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterAddWorker.java index 8b694adf1cca..670bcc6fc538 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterAddWorker.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterAddWorker.java @@ -284,8 +284,8 @@ private boolean validateNodeCompatibility(IpAddress publicIp, long nodeId, int n Pair result = SshHelper.sshExecute(publicIp.getAddress().addr(), nodeSshPort, getControlNodeLoginUser(), pkFile, null, command, 10000, 10000, 10 * 60 * 1000); if (Boolean.FALSE.equals(result.first())) { - logger.error(String.format("Node with ID: %s cannot be added as a worker node as it does not have " + - "the following dependencies: %s ", nodeId, result.second())); + logger.error(String.format("Node with ID: %s cannot be added as a worker node, it failed validation: %s", + nodeId, result.second())); return false; } } catch (Exception e) { diff --git a/plugins/integrations/kubernetes-service/src/main/resources/script/validate-cks-node b/plugins/integrations/kubernetes-service/src/main/resources/script/validate-cks-node index e28614e05afe..0bf571f53b72 100644 --- a/plugins/integrations/kubernetes-service/src/main/resources/script/validate-cks-node +++ b/plugins/integrations/kubernetes-service/src/main/resources/script/validate-cks-node @@ -20,6 +20,7 @@ OS=`awk -F= '/^NAME/{print $2}' /etc/os-release` REQUIRED_PACKAGES=(cloud-init cloud-guest-utils conntrack apt-transport-https ca-certificates curl gnupg gnupg-agent \ software-properties-common gnupg lsb-release python3-json-pointer python3-jsonschema cloud-init containerd.io) declare -a MISSING_PACKAGES +declare -a FAILURES if [[ $OS == *"Ubuntu"* || $OS == *"Debian"* ]]; then for package in ${REQUIRED_PACKAGES[@]}; do dpkg -s $package >/dev/null 2>&1 @@ -36,10 +37,16 @@ else done fi -echo ${#MISSING_PACKAGES[@]} if (( ${#MISSING_PACKAGES[@]} )); then - echo "Following packages are missing in the node template: ${MISSING_PACKAGES[@]}" + FAILURES+=("Following packages are missing in the node template: ${MISSING_PACKAGES[*]}") +fi + +if [[ $(cat /proc/sys/net/ipv4/ip_forward 2>/dev/null) != "1" ]]; then + FAILURES+=("net.ipv4.ip_forward is not set to 1 on the node; set it in /etc/sysctl.d/ so it survives the reboot that follows") +fi + +if (( ${#FAILURES[@]} )); then + printf '%s\n' "${FAILURES[@]}" exit 1 -else - echo 0 fi +echo 0