Skip to content

Commit

Permalink
Improve control plane scale flow (#13)
Browse files Browse the repository at this point in the history
* Added version 1.20.10 of K8s

* Setting first_kube_control_plane to a existing one

* Setting first_kube_control_plane to a existing one
  • Loading branch information
Alvaro-Campesino committed Sep 17, 2021
1 parent 80caaa3 commit 5bc4211
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
16 changes: 16 additions & 0 deletions roles/kubernetes/control-plane/tasks/define-first-kube-control.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: Check which kube-control nodes are already members of the cluster
shell: "{{ bin_dir }}/kubectl get nodes --selector=node-role.kubernetes.io/control-plane -o json"
register: kube_control_planes_raw
ignore_errors: yes

- name: Set fact joined_control_panes
set_fact:
joined_control_planes: "{{ ((kube_control_planes_raw.stdout| from_json)['items'])| default([]) | map (attribute='metadata') | map (attribute='name') | list }}"
delegate_to: item
with_items: groups['kube_control_plane']
when: kube_control_planes_raw is succeeded
run_once: yes

- name: Set fact first_kube_control_plane
set_fact:
first_kube_control_plane: "{{ joined_control_planes|default([]) | first | default(groups['kube_control_plane']|first) }}"
6 changes: 3 additions & 3 deletions roles/kubernetes/control-plane/tasks/kubeadm-secondary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
--upload-certs
register: kubeadm_upload_cert
when:
- inventory_hostname == groups['kube_control_plane']|first
- inventory_hostname == first_kube_control_plane

- name: Parse certificate key if not set
set_fact:
Expand All @@ -35,7 +35,7 @@
mode: 0640
backup: yes
when:
- inventory_hostname != groups['kube_control_plane']|first
- inventory_hostname != first_kube_control_plane
- not kubeadm_already_run.stat.exists

- name: Wait for k8s apiserver
Expand Down Expand Up @@ -64,5 +64,5 @@
throttle: 1
until: kubeadm_join_control_plane is succeeded
when:
- inventory_hostname != groups['kube_control_plane']|first
- inventory_hostname != first_kube_control_plane
- kubeadm_already_run is not defined or not kubeadm_already_run.stat.exists
8 changes: 4 additions & 4 deletions roles/kubernetes/control-plane/tasks/kubeadm-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
# Retry is because upload config sometimes fails
retries: 3
until: kubeadm_init is succeeded or "field is immutable" in kubeadm_init.stderr
when: inventory_hostname == groups['kube_control_plane']|first and not kubeadm_already_run.stat.exists
when: inventory_hostname == first_kube_control_plane and not kubeadm_already_run.stat.exists
failed_when: kubeadm_init.rc != 0 and "field is immutable" not in kubeadm_init.stderr
environment:
PATH: "{{ bin_dir }}:{{ ansible_env.PATH }}"
Expand All @@ -151,7 +151,7 @@
{{ bin_dir }}/kubeadm --kubeconfig /etc/kubernetes/admin.conf token create {{ kubeadm_token }}
changed_when: false
when:
- inventory_hostname == groups['kube_control_plane']|first
- inventory_hostname == first_kube_control_plane
- kubeadm_token is defined
- kubeadm_refresh_token
tags:
Expand All @@ -164,7 +164,7 @@
retries: 5
delay: 5
until: temp_token is succeeded
delegate_to: "{{ groups['kube_control_plane'] | first }}"
delegate_to: "{{ first_kube_control_plane }}"
when: kubeadm_token is not defined
tags:
- kubeadm_token
Expand All @@ -188,7 +188,7 @@
# FIXME(mattymo): from docs: If you don't want to taint your control-plane node, set this field to an empty slice, i.e. `taints: {}` in the YAML file.
- name: kubeadm | Remove taint for master with node role
command: "{{ bin_dir }}/kubectl --kubeconfig {{ kube_config_dir }}/admin.conf taint node {{ inventory_hostname }} {{ item }}"
delegate_to: "{{ groups['kube_control_plane'] | first }}"
delegate_to: "{{ first_kube_control_plane }}"
with_items:
- "node-role.kubernetes.io/master:NoSchedule-"
- "node-role.kubernetes.io/control-plane:NoSchedule-"
Expand Down
4 changes: 2 additions & 2 deletions roles/kubernetes/control-plane/tasks/kubeadm-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Retry is because upload config sometimes fails
retries: 3
until: kubeadm_upgrade.rc == 0
when: inventory_hostname == groups['kube_control_plane']|first
when: inventory_hostname == first_kube_control_plane
failed_when: kubeadm_upgrade.rc != 0 and "field is immutable" not in kubeadm_upgrade.stderr
environment:
PATH: "{{ bin_dir }}:{{ ansible_env.PATH }}"
Expand All @@ -40,7 +40,7 @@
--etcd-upgrade={{ etcd_kubeadm_enabled | bool | lower }}
--force
register: kubeadm_upgrade
when: inventory_hostname != groups['kube_control_plane']|first
when: inventory_hostname != first_kube_control_plane
failed_when:
- kubeadm_upgrade.rc != 0
- '"field is immutable" not in kubeadm_upgrade.stderr'
Expand Down
3 changes: 3 additions & 0 deletions roles/kubernetes/control-plane/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
tags:
- k8s-pre-upgrade

- name: Define nodes already joined to existing cluster and first_kube_master
import_tasks: define-first-kube-control.yml

- name: Create webhook token auth config
template:
src: webhook-token-auth-config.yaml.j2
Expand Down

0 comments on commit 5bc4211

Please sign in to comment.