blob: fd0279421a1f5158ec833fd2488248fb67095347 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
---
- name: get list of current taints
delegate_to: "{{ groups['_kubernetes_primary_controlplane_node_'] | first }}"
check_mode: no
command: kubectl --kubeconfig /etc/kubernetes/admin.conf get node '{{ kubernetes_node_name }}' -o jsonpath='{.spec.taints}'
changed_when: false
register: kubectl_list_taints
- set_fact:
current_taints: "{{ kubectl_list_taints.stdout | ternary(kubectl_list_taints.stdout, '[]') | from_json }}"
- name: add taints to node
delegate_to: "{{ groups['_kubernetes_primary_controlplane_node_'] | first }}"
loop: "{{ kubernetes_node_taints | dict2items }}"
loop_control:
label: "{{ item.key }}={{ item.value }}"
when: "item.key not in current_taints or current_taints[item.key] != item.value"
command: kubectl --kubeconfig /etc/kubernetes/admin.conf taint --overwrite node '{{ kubernetes_node_name }}' '{{ item.key }}={{ item.value }}'
- name: add stamp files for managed taints
loop: "{{ kubernetes_node_taints | dict2items }}"
loop_control:
label: "{{ item.key }}={{ item.value }}"
copy:
dest: "/etc/kubernetes/decorations/taints/{{ item.key | replace('/', '%') }}"
content: "{{ item.value }}"
- name: get list of managed taints
find:
path: /etc/kubernetes/decorations/taints
register: managed_taints
- name: remove superflous taints from node
delegate_to: "{{ groups['_kubernetes_primary_controlplane_node_'] | first }}"
loop: "{{ managed_taints.files | map(attribute='path') | map('basename') | replace('%', '/') }}"
when: "item not in kubernetes_node_taints"
command: kubectl --kubeconfig /etc/kubernetes/admin.conf taint --overwrite node '{{ kubernetes_node_name }}' '{{ item }}-'
- name: remove stamp files for superflous taints
loop: "{{ managed_taints.files | map(attribute='path') | map('basename') | replace('%', '/') }}"
when: "item not in kubernetes_node_taints"
file:
path: "/etc/kubernetes/decorations/taints/{{ item | replace('/', '%') }}"
state: absent
|