From 64c0f3c88279e4dcc17e4d291b9016662de4d480 Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Mon, 14 Oct 2024 16:53:14 -0400 Subject: [PATCH] Fix kube-vip bootstrapping --- roles/kube_vip/defaults/main.yml | 3 +++ roles/kube_vip/tasks/main.yml | 26 +++++++++++++++++++++++ roles/kube_vip/templates/kube-vip.yaml.j2 | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/roles/kube_vip/defaults/main.yml b/roles/kube_vip/defaults/main.yml index 864ea78e..cbd3df5a 100644 --- a/roles/kube_vip/defaults/main.yml +++ b/roles/kube_vip/defaults/main.yml @@ -12,6 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +# Inventory group containing controllers +kube_vip_control_plane_group: "{{ kubernetes_control_plane_group | default('controllers') }}" + # Image to use for kube-vip kube_vip_image: ghcr.io/kube-vip/kube-vip:v0.6.4 diff --git a/roles/kube_vip/tasks/main.yml b/roles/kube_vip/tasks/main.yml index 584eed57..5195b699 100644 --- a/roles/kube_vip/tasks/main.yml +++ b/roles/kube_vip/tasks/main.yml @@ -40,6 +40,32 @@ notify: - Restart "kubelet" service +- name: Check if super-admin.conf exists + ansible.builtin.stat: + path: /etc/kubernetes/super-admin.conf + failed_when: false + changed_when: false + register: kube_vip_stat_super_admin + +- name: Check if kubeadm has already run + ansible.builtin.stat: + path: /var/lib/kubelet/config.yaml + get_attributes: false + get_checksum: false + get_mime: false + register: kube_vip_stat_kubelet_config + +- name: Set fact with KUBECONFIG path + ansible.builtin.set_fact: + kube_vip_kubeconfig_path: /etc/kubernetes/admin.conf + +- name: Set fact with KUBECONFIG path (with super-admin.conf) + ansible.builtin.set_fact: + kube_vip_kubeconfig_path: /etc/kubernetes/super-admin.conf + when: + - inventory_hostname == groups[kube_vip_control_plane_group] | first + - (kube_vip_stat_super_admin.stat.exists and kube_vip_stat_super_admin.stat.isreg) or (not kube_vip_stat_kubelet_config.stat.exists) + - name: Upload Kubernetes manifest ansible.builtin.template: src: kube-vip.yaml.j2 diff --git a/roles/kube_vip/templates/kube-vip.yaml.j2 b/roles/kube_vip/templates/kube-vip.yaml.j2 index 99f15c9e..4a27d77e 100644 --- a/roles/kube_vip/templates/kube-vip.yaml.j2 +++ b/roles/kube_vip/templates/kube-vip.yaml.j2 @@ -59,6 +59,6 @@ spec: hostNetwork: true volumes: - hostPath: - path: /etc/kubernetes/admin.conf + path: "{{ kube_vip_kubeconfig_path }}" name: kubeconfig status: {}