Skip to content

Commit

Permalink
Adding logic to allow config to be specified for kubeadm init (#313)
Browse files Browse the repository at this point in the history
* Adding logic to allow config to be specified for kubeadm

* Cleanup for linter

* Fix for non config use case
  • Loading branch information
dkosteck authored Dec 11, 2024
1 parent 9c5afa9 commit adaad40
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion e2e/provision/playbooks/roles/kubeadm/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ cni_plugins_ver: 1.1.1
pod_network_cidr: 10.244.0.0/16
# comment out multus_ver if clusters (e.g; management clusters) do not need multus installed
multus_ver: 3.9.2
k8s_ver: 1.30
k8s_ver: "1.30"
ctrlplane_ep_ip_filter: 10.128
network_plugin_url: https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
13 changes: 13 additions & 0 deletions e2e/provision/playbooks/roles/kubeadm/tasks/kubeadm-Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@
- kubectl
state: present

- name: Disable swap 1/2
become: true
ansible.builtin.command: swapoff -a
register: my_output
changed_when: my_output.rc != 0

- name: Disable swap in fstab 2/2
become: true
ansible.builtin.replace:
path: /etc/fstab
regexp: '^([^#].*?\sswap\s+sw\s+.*)$'
replace: '# \1'

- name: Hold kubeadm
ansible.builtin.dpkg_selections:
name: kubeadm
Expand Down
47 changes: 46 additions & 1 deletion e2e/provision/playbooks/roles/kubeadm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,57 @@
ignore_errors: true
changed_when: false

- name: Get control plane endpoint
become: true
ansible.builtin.shell:
cmd: |
$(hostname -i | xargs -n1 | grep ^{{ ctrlplane_ep_ip_filter }})
executable: /bin/bash
register: control_plane_endpoint
changed_when: my_output.rc != 0
ignore_errors: true

- name: Read kubeadm config
ansible.builtin.set_fact:
kubeadm_config_data: "{{ lookup('file', kubeadm_config) | from_yaml }}"
when: kubeadm_config is defined

- name: Generate new kubeadm config
ansible.builtin.set_fact:
new_kubeadm_config_data: |
networking:
podSubnet: "{{ pod_network_cidr }}"
controlPlaneEndpoint: "{{ control_plane_endpoint.stdout }}"
when: kubeadm_config is defined

- name: Patch kubeadm config
ansible.builtin.set_fact:
kubeadm_data: "{{ kubeadm_config_data | combine(new_kubeadm_config_data | from_yaml, recursive=True) }}"
when: kubeadm_config is defined

- name: Write new kubeadm config
ansible.builtin.copy:
mode: "0644"
content: "{{ kubeadm_data | to_nice_yaml }}"
dest: "/tmp/yaml_output"
when: kubeadm_config is defined

- name: Set kubeadm cmd with config
ansible.builtin.set_fact:
kubeadm_cmd: kubeadm init "--config=/tmp/yaml_output"
when: kubeadm_config is defined

- name: Set kubeadm cmd without config
ansible.builtin.set_fact:
kubeadm_cmd: kubeadm init --pod-network-cidr={{ pod_network_cidr }} --control-plane-endpoint={{ control_plane_endpoint.stdout }}
when: kubeadm_config is undefined

- name: Invoke kubeadm init
become: true
ansible.builtin.shell:
cmd: |
set -o pipefail
kubeadm init --pod-network-cidr={{ pod_network_cidr }} --control-plane-endpoint=$(hostname -i | xargs -n1 | grep ^{{ ctrlplane_ep_ip_filter }})
{{ kubeadm_cmd }}
executable: /bin/bash
when: token.stderr_lines != []
register: my_output
Expand Down

0 comments on commit adaad40

Please sign in to comment.