kubeadm: allow to provide patch inline in inventories

Specifying one directory for kubeadm patches is not ideal:
1. It does not allow working with multiples inventories easily
2. No ansible templating of the patch
3. Ansible path searching can sometimes be confusing

Instead, provide the patch directly in a variable, and add some quality
of life to handle components targeting and patch ordering more
explicitly (`target` and `type` which are translated to the kubeadm
scheme which is based on the file name)
pull/11521/head
Max Gautier 2024-09-10 12:00:26 +02:00
parent a8b66fd207
commit 8e254ec1e8
No known key found for this signature in database
6 changed files with 29 additions and 13 deletions

View File

@ -18,7 +18,7 @@
--ignore-preflight-errors=all --ignore-preflight-errors=all
--allow-experimental-upgrades --allow-experimental-upgrades
--etcd-upgrade={{ (etcd_deployment_type == "kubeadm") | bool | lower }} --etcd-upgrade={{ (etcd_deployment_type == "kubeadm") | bool | lower }}
{% if kubeadm_patches is defined and kubeadm_patches.enabled %}--patches={{ kubeadm_patches.dest_dir }}{% endif %} {% if kubeadm_patches | length > 0 %}--patches={{ kubeadm_patches_dir }}{% endif %}
--force --force
register: kubeadm_upgrade register: kubeadm_upgrade
# Retry is because upload config sometimes fails # Retry is because upload config sometimes fails
@ -39,7 +39,7 @@
--ignore-preflight-errors=all --ignore-preflight-errors=all
--allow-experimental-upgrades --allow-experimental-upgrades
--etcd-upgrade={{ (etcd_deployment_type == "kubeadm") | bool | lower }} --etcd-upgrade={{ (etcd_deployment_type == "kubeadm") | bool | lower }}
{% if kubeadm_patches is defined and kubeadm_patches.enabled %}--patches={{ kubeadm_patches.dest_dir }}{% endif %} {% if kubeadm_patches | length > 0 %}--patches={{ kubeadm_patches_dir }}{% endif %}
--force --force
register: kubeadm_upgrade register: kubeadm_upgrade
# Retry is because upload config sometimes fails # Retry is because upload config sometimes fails

View File

@ -28,9 +28,9 @@ nodeRegistration:
kubeletExtraArgs: kubeletExtraArgs:
cloud-provider: external cloud-provider: external
{% endif %} {% endif %}
{% if kubeadm_patches is defined and kubeadm_patches.enabled %} {% if kubeadm_patches | length > 0 %}
patches: patches:
directory: {{ kubeadm_patches.dest_dir }} directory: {{ kubeadm_patches_dir }}
{% endif %} {% endif %}
--- ---
apiVersion: kubeadm.k8s.io/v1beta3 apiVersion: kubeadm.k8s.io/v1beta3

View File

@ -31,7 +31,7 @@ nodeRegistration:
{% else %} {% else %}
taints: [] taints: []
{% endif %} {% endif %}
{% if kubeadm_patches is defined and kubeadm_patches.enabled %} {% if kubeadm_patches | length > 0 %}
patches: patches:
directory: {{ kubeadm_patches.dest_dir }} directory: {{ kubeadm_patches_dir }}
{% endif %} {% endif %}

View File

@ -38,7 +38,7 @@ nodeRegistration:
- effect: NoSchedule - effect: NoSchedule
key: node-role.kubernetes.io/calico-rr key: node-role.kubernetes.io/calico-rr
{% endif %} {% endif %}
{% if kubeadm_patches is defined and kubeadm_patches.enabled %} {% if kubeadm_patches | length > 0 %}
patches: patches:
directory: {{ kubeadm_patches.dest_dir }} directory: {{ kubeadm_patches_dir }}
{% endif %} {% endif %}

View File

@ -0,0 +1,14 @@
---
kubeadm_patches_dir: "{{ kube_config_dir }}/patches"
kubeadm_patches: []
# kubeadm_patches:
# - target: kube-apiserver|kube-controller-manager|kube-scheduler|etcd|kubeletconfiguration
# type: strategic(default)|json|merge
# patch:
# metadata:
# annotations:
# example.com/test: "true"
# labels:
# example.com/prod_level: "{{ prod_level }}"
# - ...
# Patches are applied in the order they are specified.

View File

@ -1,15 +1,17 @@
--- ---
- name: Kubeadm | Create directory to store kubeadm patches - name: Kubeadm | Create directory to store kubeadm patches
file: file:
path: "{{ kubeadm_patches.dest_dir }}" path: "{{ kubeadm_patches_dir }}"
state: directory state: directory
mode: "0640" mode: "0640"
when: kubeadm_patches is defined and kubeadm_patches.enabled when: kubeadm_patches | length > 0
- name: Kubeadm | Copy kubeadm patches from inventory files - name: Kubeadm | Copy kubeadm patches from inventory files
copy: copy:
src: "{{ kubeadm_patches.source_dir }}/" content: "{{ item.patch | to_yaml }}"
dest: "{{ kubeadm_patches.dest_dir }}" dest: "{{ kubeadm_patches_dir }}/{{ item.target }}{{ suffix }}+{{ item.type | d('strategic') }}.yaml"
owner: "root" owner: "root"
mode: "0644" mode: "0644"
when: kubeadm_patches is defined and kubeadm_patches.enabled loop: "{{ kubeadm_patches }}"
loop_control:
index_var: suffix