mirror of
https://github.com/geerlingguy/ansible-role-kubernetes.git
synced 2024-11-23 19:06:33 +01:00
add dynamic tainting logic
This commit is contained in:
parent
4a4c88b6b8
commit
0bde57da9f
@ -71,10 +71,34 @@
|
|||||||
changed_when: "'created' in weave_result.stdout"
|
changed_when: "'created' in weave_result.stdout"
|
||||||
when: kubernetes_pod_network.cni == 'weave'
|
when: kubernetes_pod_network.cni == 'weave'
|
||||||
|
|
||||||
# TODO: Check if taint exists with something like `kubectl describe nodes`
|
# Get the current taint status from the control-plane node
|
||||||
# instead of using kubernetes_init_stat.stat.exists check.
|
# add/remove the taint according to kubernetes_allow_pods_on_control_plane
|
||||||
- name: Allow pods on control plane (if configured).
|
|
||||||
command: "kubectl taint nodes --all node-role.kubernetes.io/control-plane-"
|
- name: Get node spec
|
||||||
|
command: kubectl get nodes {{ ansible_hostname }} -o=jsonpath='{.spec}'
|
||||||
|
register: node_spec
|
||||||
|
|
||||||
|
- name: Store node spec as JSON
|
||||||
|
set_fact:
|
||||||
|
node_spec_json: "{{ node_spec.stdout | from_json }}"
|
||||||
|
|
||||||
|
- name: Get current taint status
|
||||||
|
set_fact:
|
||||||
|
taint_status: true
|
||||||
when:
|
when:
|
||||||
- kubernetes_allow_pods_on_control_plane | bool
|
- node_spec_json.taints is defined
|
||||||
- not kubernetes_init_stat.stat.exists
|
- item.effect == "NoSchedule"
|
||||||
|
- item.key == "node-role.kubernetes.io/control-plane"
|
||||||
|
with_items: "{{ node_spec_json.taints }}"
|
||||||
|
|
||||||
|
- name: Allow pods on the control plane
|
||||||
|
command: kubectl taint nodes {{ ansible_hostname }} node-role.kubernetes.io/control-plane-
|
||||||
|
when:
|
||||||
|
- kubernetes_allow_pods_on_control_plane | bool
|
||||||
|
- taint_status is defined
|
||||||
|
|
||||||
|
- name: Deny pods on the control plane
|
||||||
|
command: kubectl taint nodes {{ ansible_hostname }} node-role.kubernetes.io/control-plane:NoSchedule
|
||||||
|
when:
|
||||||
|
- not kubernetes_allow_pods_on_control_plane | bool
|
||||||
|
- taint_status is not defined
|
||||||
|
Loading…
Reference in New Issue
Block a user