From 98b808f570c48252ff544e443c8d796e8f37614e Mon Sep 17 00:00:00 2001 From: Ashley Dumaine <5779804+AshleyDumaine@users.noreply.github.com> Date: Mon, 12 Feb 2024 20:25:27 -0500 Subject: [PATCH] [fix]: tweaks for pre-init script (#105) * fail script early on error or unset variables * fix parsing of version to handle v prefix --- templates/cluster-template.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/templates/cluster-template.yaml b/templates/cluster-template.yaml index ec9443b48..8a3730426 100644 --- a/templates/cluster-template.yaml +++ b/templates/cluster-template.yaml @@ -61,7 +61,7 @@ spec: key: kubeadm-pre-init.sh permissions: "0500" preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' ${KUBERNETES_VERSION#[vV]} clusterConfiguration: apiServer: extraArgs: @@ -162,7 +162,7 @@ spec: key: kubeadm-pre-init.sh permissions: "0500" preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' ${KUBERNETES_VERSION#[vV]} joinConfiguration: nodeRegistration: kubeletExtraArgs: @@ -194,10 +194,11 @@ stringData: net.ipv4.ip_forward = 1 kubeadm-pre-init.sh: | #!/bin/bash + set -euo pipefail export DEBIAN_FRONTEND=noninteractive hostnamectl set-hostname "$1" && hostname -F /etc/hostname mkdir -p -m 755 /etc/apt/keyrings - VERSION=${2%.*} + VERSION=$${2%.*} curl -fsSL "https://pkgs.k8s.io/core:/stable:/v$VERSION/deb/Release.key" | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v$VERSION/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list apt-get update -y