blob: f15beb3d01ad85b9ae44575bce2f542e06f316cf (
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 annotations
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='{.metadata.annotations}'
changed_when: false
register: kubectl_list_annotations
- set_fact:
current_annotations: "{{ kubectl_list_annotations.stdout | ternary(kubectl_list_annotations.stdout, '[]') | from_json }}"
- name: add annotations to node
delegate_to: "{{ groups['_kubernetes_primary_controlplane_node_'] | first }}"
loop: "{{ kubernetes_node_annotations | dict2items }}"
loop_control:
label: "{{ item.key }}={{ item.value }}"
when: "item.key not in current_annotations or current_annotations[item.key] != item.value"
command: kubectl --kubeconfig /etc/kubernetes/admin.conf annotate --overwrite node '{{ kubernetes_node_name }}' '{{ item.key }}={{ item.value }}'
- name: add stamp files for managed annotations
loop: "{{ kubernetes_node_annotations | dict2items }}"
loop_control:
label: "{{ item.key }}={{ item.value }}"
copy:
dest: "/etc/kubernetes/decorations/annotations/{{ item.key | replace('/', '%') }}"
content: "{{ item.value }}"
- name: get list of managed annotations
find:
path: /etc/kubernetes/decorations/annotations
register: managed_annotations
- name: remove superflous annotations from node
delegate_to: "{{ groups['_kubernetes_primary_controlplane_node_'] | first }}"
loop: "{{ managed_annotations.files | map(attribute='path') | map('basename') | replace('%', '/') }}"
when: "item not in kubernetes_node_annotations"
command: kubectl --kubeconfig /etc/kubernetes/admin.conf annotate --overwrite node '{{ kubernetes_node_name }}' '{{ item }}-'
- name: remove stamp files for superflous annotations
loop: "{{ managed_annotations.files | map(attribute='path') | map('basename') | replace('%', '/') }}"
when: "item not in kubernetes_node_annotations"
file:
path: "/etc/kubernetes/decorations/annotations/{{ item | replace('/', '%') }}"
state: absent
|