From aea4dfd3901a2bb298aa32d8cd96d47a6267631a Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Wed, 4 Dec 2024 17:53:55 -0700 Subject: [PATCH] Improve handling of kubeconfig for kube-vip: K8s 1.29 has a kubeconfig file named different than other versions. https://github.com/kube-vip/kube-vip/issues/684 Signed-off-by: Jacob Weinstock --- capt/tasks/Taskfile-capi.yaml | 3 +-- capt/templates/kustomization-iso.tmpl | 2 +- capt/templates/kustomization-netboot.tmpl | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/capt/tasks/Taskfile-capi.yaml b/capt/tasks/Taskfile-capi.yaml index 20d55e7..c266d5a 100644 --- a/capt/tasks/Taskfile-capi.yaml +++ b/capt/tasks/Taskfile-capi.yaml @@ -121,8 +121,6 @@ tasks: sh: yq eval '.versions.kubevip' {{.STATE_FILE_FQ_PATH}} CONTROL_PLANE_VIP: sh: yq eval '.cluster.controlPlane.vip' {{.STATE_FILE_FQ_PATH}} - CONF_PATH: # https://github.com/kube-vip/kube-vip/issues/684 - sh: "[[ $(echo {{.KUBE_VERSION}} | awk -F. '{print $2}') -gt 28 ]] && echo /etc/kubernetes/super-admin.conf || echo /etc/kubernetes/admin.conf" vars: KUBE_VERSION: sh: yq eval '.versions.kube' {{.STATE_FILE_FQ_PATH}} @@ -138,6 +136,7 @@ tasks: - "{{.OUTPUT_DIR}}/kustomization.yaml" cmds: - envsubst "$(printf '${%s} ' $(env | cut -d'=' -f1))" < templates/{{.KUSTOMIZE_FILE}} > {{.OUTPUT_DIR}}/kustomization.yaml + # FYI, the `preKubeadmCommands` checks for k8s v1.29 because of https://github.com/kube-vip/kube-vip/issues/684 apply-kustomization: run: once diff --git a/capt/templates/kustomization-iso.tmpl b/capt/templates/kustomization-iso.tmpl index 8e1b7f4..3162900 100644 --- a/capt/templates/kustomization-iso.tmpl +++ b/capt/templates/kustomization-iso.tmpl @@ -297,4 +297,4 @@ patches: - op: add path: /spec/kubeadmConfigSpec/preKubeadmCommands value: - - mkdir -p /etc/kubernetes/manifests && ctr images pull ghcr.io/kube-vip/kube-vip:v$KUBEVIP_VERSION && ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:v$KUBEVIP_VERSION vip /kube-vip manifest pod --arp --interface $(ip -4 -j route list default | jq -r .[0].dev) --address $CONTROL_PLANE_VIP --controlplane --leaderElection --k8sConfigPath $CONF_PATH > /etc/kubernetes/manifests/kube-vip.yaml + - if [ $(cat /etc/kubernetes-version | awk -F. '{print $2}') -eq 29 ]; then export KUBE_FILE=/etc/kubernetes/super-admin.conf; else export KUBE_FILE=/etc/kubernetes/admin.conf; fi && mkdir -p /etc/kubernetes/manifests && ctr images pull ghcr.io/kube-vip/kube-vip:v$KUBEVIP_VERSION && ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:v$KUBEVIP_VERSION vip /kube-vip manifest pod --arp --interface $(ip -4 -j route list default | jq -r .[0].dev) --address $CONTROL_PLANE_VIP --controlplane --leaderElection --k8sConfigPath $KUBE_FILE > /etc/kubernetes/manifests/kube-vip.yaml diff --git a/capt/templates/kustomization-netboot.tmpl b/capt/templates/kustomization-netboot.tmpl index 9a2cb31..eb8fdbb 100644 --- a/capt/templates/kustomization-netboot.tmpl +++ b/capt/templates/kustomization-netboot.tmpl @@ -219,4 +219,4 @@ patches: - op: add path: /spec/kubeadmConfigSpec/preKubeadmCommands value: - - mkdir -p /etc/kubernetes/manifests && ctr images pull ghcr.io/kube-vip/kube-vip:v$KUBEVIP_VERSION && ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:v$KUBEVIP_VERSION vip /kube-vip manifest pod --arp --interface $(ip -4 -j route list default | jq -r .[0].dev) --address $CONTROL_PLANE_VIP --controlplane --leaderElection --k8sConfigPath $CONF_PATH > /etc/kubernetes/manifests/kube-vip.yaml + - if [ $(cat /etc/kubernetes-version | awk -F. '{print $2}') -eq 29 ]; then export KUBE_FILE=/etc/kubernetes/super-admin.conf; else export KUBE_FILE=/etc/kubernetes/admin.conf; fi && mkdir -p /etc/kubernetes/manifests && ctr images pull ghcr.io/kube-vip/kube-vip:v$KUBEVIP_VERSION && ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:v$KUBEVIP_VERSION vip /kube-vip manifest pod --arp --interface $(ip -4 -j route list default | jq -r .[0].dev) --address $CONTROL_PLANE_VIP --controlplane --leaderElection --k8sConfigPath $KUBE_FILE > /etc/kubernetes/manifests/kube-vip.yaml