From 550f6868ffa4f4288b53d07b136e1fc45fc81d1c Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 12 Apr 2023 20:49:38 +0200 Subject: [PATCH 1/7] Fix old usage of network_plugin var --- kubernetes/templates/k3s/server/config.yaml.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes/templates/k3s/server/config.yaml.jinja2 b/kubernetes/templates/k3s/server/config.yaml.jinja2 index ab58922..d496912 100644 --- a/kubernetes/templates/k3s/server/config.yaml.jinja2 +++ b/kubernetes/templates/k3s/server/config.yaml.jinja2 @@ -27,7 +27,7 @@ service-cidr: {{ kubernetes.ipPool.ipv4.service_cidr }} egress-selector-mode: disabled # Network-plugin -{% if kubernetes.network_plugin == "flannel" %} +{% if kubernetes.network.plugin == "flannel" %} flannel-backend: vxlan {% else %} disable-network-policy: true From c1c7ec9e56ffffc302d813b995aae9d1f6d567d1 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 12 Apr 2023 22:39:43 +0200 Subject: [PATCH 2/7] Remove workaround as k3s is now at 1.26 --- kubernetes/templates/k3s/agent/config.yaml.jinja2 | 3 --- kubernetes/templates/k3s/server/config.yaml.jinja2 | 3 --- 2 files changed, 6 deletions(-) diff --git a/kubernetes/templates/k3s/agent/config.yaml.jinja2 b/kubernetes/templates/k3s/agent/config.yaml.jinja2 index f42ec8e..fd2bc58 100644 --- a/kubernetes/templates/k3s/agent/config.yaml.jinja2 +++ b/kubernetes/templates/k3s/agent/config.yaml.jinja2 @@ -3,9 +3,6 @@ token: '{{ kubernetes.token }}' {% if nodeip_ipv6 != "" and kubernetes.ipPool.ipv6 is defined %} node-ip: {{ nodeip_ipv4 }},{{ nodeip_ipv6 }} - -# FIXME: Workaround for bug in Kubernetes 1.24/1.25 ignoring node IPv6 addresses -kubelet-arg: "--node-ip=0.0.0.0" {% else %} node-ip: {{ nodeip_ipv4 }} {% endif %} diff --git a/kubernetes/templates/k3s/server/config.yaml.jinja2 b/kubernetes/templates/k3s/server/config.yaml.jinja2 index d496912..d9168b2 100644 --- a/kubernetes/templates/k3s/server/config.yaml.jinja2 +++ b/kubernetes/templates/k3s/server/config.yaml.jinja2 @@ -15,9 +15,6 @@ tls-san: node-ip: {{ nodeip_ipv4 }},{{ nodeip_ipv6 }} cluster-cidr: {{ kubernetes.ipPool.ipv4.cluster_cidr }},{{ kubernetes.ipPool.ipv6.cluster_cidr }} service-cidr: {{ kubernetes.ipPool.ipv4.service_cidr }},{{ kubernetes.ipPool.ipv6.service_cidr }} - -# FIXME: Workaround for bug in Kubernetes 1.24/1.25 ignoring node IPv6 addresses -kubelet-arg: "--node-ip=0.0.0.0" {% else %} node-ip: {{ nodeip_ipv4 }} cluster-cidr: {{ kubernetes.ipPool.ipv4.cluster_cidr }} From c2c6a2872f70017a73ce4903cbdfd7442ddd9cc9 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 12 Apr 2023 23:11:26 +0200 Subject: [PATCH 3/7] Fix conditional for changed after install --- kubernetes/tasks/install/agent/install_k3s.yml | 2 +- kubernetes/tasks/install/server/install_k3s.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kubernetes/tasks/install/agent/install_k3s.yml b/kubernetes/tasks/install/agent/install_k3s.yml index 94a064a..87bd64b 100644 --- a/kubernetes/tasks/install/agent/install_k3s.yml +++ b/kubernetes/tasks/install/agent/install_k3s.yml @@ -1,7 +1,7 @@ - name: Install K3s agent command: /root/k3s_install.sh {{ type }} register: command - changed_when: "'No change detected' in command.stdout" + changed_when: "'No change detected' not in command.stdout" until: "command is not failed" retries: 2 delay: 10 diff --git a/kubernetes/tasks/install/server/install_k3s.yml b/kubernetes/tasks/install/server/install_k3s.yml index b4a3076..620b5f9 100644 --- a/kubernetes/tasks/install/server/install_k3s.yml +++ b/kubernetes/tasks/install/server/install_k3s.yml @@ -2,7 +2,7 @@ command: /root/k3s_install.sh {{ type }} when: "inventory_hostname == groups['kubernetes'][0]" register: command - changed_when: "'No change detected' in command.stdout" + changed_when: "'No change detected' not in command.stdout" - name: Restart when config changed, but install already done service: @@ -21,7 +21,7 @@ command: /root/k3s_install.sh {{ type }} when: "inventory_hostname != groups['kubernetes'][0]" register: command - changed_when: "'No change detected' in command.stdout" + changed_when: "'No change detected' not in command.stdout" until: "command is not failed" retries: 2 delay: 10 From 668ff23ee6c9e6a1e55854452d3c5057fdbf96db Mon Sep 17 00:00:00 2001 From: Ruakij Date: Fri, 14 Apr 2023 09:42:46 +0200 Subject: [PATCH 4/7] Fix service task wrong usage --- kubernetes/tasks/install/agent/install_k3s.yml | 4 ++-- kubernetes/tasks/install/server/install_k3s.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kubernetes/tasks/install/agent/install_k3s.yml b/kubernetes/tasks/install/agent/install_k3s.yml index 87bd64b..e0e5728 100644 --- a/kubernetes/tasks/install/agent/install_k3s.yml +++ b/kubernetes/tasks/install/agent/install_k3s.yml @@ -8,6 +8,6 @@ - name: Restart when config changed, but install already done service: - name: k3s - status: restarted + name: k3s-agent + state: restarted when: "inventory_hostname != groups['kubernetes'][0] and not command.changed and config.changed" diff --git a/kubernetes/tasks/install/server/install_k3s.yml b/kubernetes/tasks/install/server/install_k3s.yml index 620b5f9..3cd0ccf 100644 --- a/kubernetes/tasks/install/server/install_k3s.yml +++ b/kubernetes/tasks/install/server/install_k3s.yml @@ -7,7 +7,7 @@ - name: Restart when config changed, but install already done service: name: k3s - status: restarted + state: restarted when: "inventory_hostname == groups['kubernetes'][0] and not command.changed and config.changed" - name: Waiting for K3s-server to accept connections @@ -29,7 +29,7 @@ - name: Restart when config changed, but install already done service: name: k3s - status: restarted + state: restarted when: "inventory_hostname != groups['kubernetes'][0] and not command.changed and config.changed" - name: Waiting for K3s-server to accept connections on other nodes From f50e3ac33c1aa1f1a0aa614fe0fb03f59040fbae Mon Sep 17 00:00:00 2001 From: Ruakij Date: Fri, 14 Apr 2023 09:50:39 +0200 Subject: [PATCH 5/7] Use first node's IP for joining cluster --- kubernetes/templates/k3s/agent/config.yaml.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes/templates/k3s/agent/config.yaml.jinja2 b/kubernetes/templates/k3s/agent/config.yaml.jinja2 index fd2bc58..91c6644 100644 --- a/kubernetes/templates/k3s/agent/config.yaml.jinja2 +++ b/kubernetes/templates/k3s/agent/config.yaml.jinja2 @@ -1,4 +1,4 @@ -server: https://{{ kubernetes.control_plane.dns_name }}:6443 +server: https://{{ hostvars[groups['kubernetes'][0]]['nodeip_ipv4'] }}:6443 token: '{{ kubernetes.token }}' {% if nodeip_ipv6 != "" and kubernetes.ipPool.ipv6 is defined %} From a92409c56f18c16cc11716ac0cef4ecc792ac031 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Fri, 14 Apr 2023 10:01:42 +0200 Subject: [PATCH 6/7] Add failed_when to deploy calico operator --- .../tasks/install/server/network-plugin/deploy_calico.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kubernetes/tasks/install/server/network-plugin/deploy_calico.yml b/kubernetes/tasks/install/server/network-plugin/deploy_calico.yml index 7cd2955..8c8a802 100644 --- a/kubernetes/tasks/install/server/network-plugin/deploy_calico.yml +++ b/kubernetes/tasks/install/server/network-plugin/deploy_calico.yml @@ -3,6 +3,8 @@ register: command changed_when: "'created' in command.stdout" run_once: true + failed_when: + - "command.rc == 1 and 'AlreadyExists' not in command.stderr" - name: Deploy calico ressource template ansible.builtin.template: From 093612f3a7fb3eb46ad366036b237cc48c405463 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Fri, 14 Apr 2023 10:20:16 +0200 Subject: [PATCH 7/7] Change restart-check to started/restarted check --- kubernetes/tasks/install/agent/install_k3s.yml | 5 ++--- kubernetes/tasks/install/server/install_k3s.yml | 12 ++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/kubernetes/tasks/install/agent/install_k3s.yml b/kubernetes/tasks/install/agent/install_k3s.yml index e0e5728..2fd0ec6 100644 --- a/kubernetes/tasks/install/agent/install_k3s.yml +++ b/kubernetes/tasks/install/agent/install_k3s.yml @@ -6,8 +6,7 @@ retries: 2 delay: 10 -- name: Restart when config changed, but install already done +- name: Make sure service is started / restarted on config change service: name: k3s-agent - state: restarted - when: "inventory_hostname != groups['kubernetes'][0] and not command.changed and config.changed" + state: "{{ 'restarted' if not command.changed and config.changed else 'started' }}" diff --git a/kubernetes/tasks/install/server/install_k3s.yml b/kubernetes/tasks/install/server/install_k3s.yml index 3cd0ccf..5454e48 100644 --- a/kubernetes/tasks/install/server/install_k3s.yml +++ b/kubernetes/tasks/install/server/install_k3s.yml @@ -4,11 +4,11 @@ register: command changed_when: "'No change detected' not in command.stdout" -- name: Restart when config changed, but install already done +- name: Make sure service is started / restarted on config change service: name: k3s - state: restarted - when: "inventory_hostname == groups['kubernetes'][0] and not command.changed and config.changed" + state: "{{ 'restarted' if not command.changed and config.changed else 'started' }}" + when: "inventory_hostname == groups['kubernetes'][0]" - name: Waiting for K3s-server to accept connections ansible.builtin.wait_for: @@ -26,11 +26,11 @@ retries: 2 delay: 10 -- name: Restart when config changed, but install already done +- name: Make sure service is started / restarted on config change service: name: k3s - state: restarted - when: "inventory_hostname != groups['kubernetes'][0] and not command.changed and config.changed" + state: "{{ 'restarted' if not command.changed and config.changed else 'started' }}" + when: "inventory_hostname != groups['kubernetes'][0]" - name: Waiting for K3s-server to accept connections on other nodes ansible.builtin.wait_for: