From e43e08c7d1ea6a522c4bd648e1300cea82d7cf39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sel=C3=A7uk=20Ar=C4=B1bal=C4=B1?= Date: Sun, 11 Aug 2024 06:35:58 +0200 Subject: [PATCH] fix: use super-admin.conf for kube-vip on first master when it exists (#11422) * fix: use super-admin.conf for kube-vip when it exists * Mathieu Parent add as co-author Co-authored-by: Mathieu Parent * template change for readability * fix lint error --------- Co-authored-by: Mathieu Parent --- .../node/tasks/loadbalancer/kube-vip.yml | 26 +++++++++++++++++++ .../templates/manifests/kube-vip.manifest.j2 | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/roles/kubernetes/node/tasks/loadbalancer/kube-vip.yml b/roles/kubernetes/node/tasks/loadbalancer/kube-vip.yml index 7e3471593..b210cfe16 100644 --- a/roles/kubernetes/node/tasks/loadbalancer/kube-vip.yml +++ b/roles/kubernetes/node/tasks/loadbalancer/kube-vip.yml @@ -6,6 +6,32 @@ - kube_proxy_mode == 'ipvs' and not kube_proxy_strict_arp - kube_vip_arp_enabled +- name: Kube-vip | Check if super-admin.conf exists + stat: + path: "{{ kube_config_dir }}/super-admin.conf" + failed_when: false + changed_when: false + register: stat_kube_vip_super_admin + +- name: Kube-vip | Check if kubeadm has already run + stat: + path: "/var/lib/kubelet/config.yaml" + get_attributes: no + get_checksum: no + get_mime: no + register: kubeadm_already_run + +- name: Kube-vip | Set admin.conf + set_fact: + kube_vip_admin_conf: admin.conf + +- name: Kube-vip | Set admin.conf for first Control Plane + set_fact: + kube_vip_admin_conf: super-admin.conf + when: + - inventory_hostname == groups['kube_control_plane'] | first + - (stat_kube_vip_super_admin.stat.exists and stat_kube_vip_super_admin.stat.isreg) or (not kubeadm_already_run.stat.exists ) + - name: Kube-vip | Write static pod template: src: manifests/kube-vip.manifest.j2 diff --git a/roles/kubernetes/node/templates/manifests/kube-vip.manifest.j2 b/roles/kubernetes/node/templates/manifests/kube-vip.manifest.j2 index 11a971e93..35b6f0eee 100644 --- a/roles/kubernetes/node/templates/manifests/kube-vip.manifest.j2 +++ b/roles/kubernetes/node/templates/manifests/kube-vip.manifest.j2 @@ -119,6 +119,6 @@ spec: hostNetwork: true volumes: - hostPath: - path: /etc/kubernetes/admin.conf + path: /etc/kubernetes/{{kube_vip_admin_conf}} name: kubeconfig status: {}