Only cordon Ready nodes

This commit is contained in:
Matthew Mosesohn 2017-03-22 16:19:27 +03:00
parent 5ed03ce7f0
commit 44d851d5bb
3 changed files with 17 additions and 3 deletions

View file

@ -93,3 +93,5 @@
delegate_to: "{{item}}"
with_items: "{{groups['etcd']}}"
when: needs_etcd_migration|bool
notify: "Master | reload kubelet"

View file

@ -3,3 +3,4 @@
- name: Uncordon node
command: "{{ bin_dir }}/kubectl uncordon {{ ansible_hostname }}"
delegate_to: "{{ groups['kube-master'][0] }}"
when: needs_cordoning|default(false)

View file

@ -1,8 +1,21 @@
---
- name: See if node is in ready state
command: "kubectl get nodes | grep {{ inventory_hostname }}"
register: kubectl_nodes
ignore_errors: true
- set_fact:
needs_cordoning: >-
{% if " Ready" in kubectl_nodes.stdout %}
true
{% else %}
false
{% endif %}
- name: Cordon node
command: "{{ bin_dir }}/kubectl cordon {{ ansible_hostname }}"
delegate_to: "{{ groups['kube-master'][0] }}"
when: needs_cordoning
- name: Drain node
command: >-
@ -13,6 +26,4 @@
--timeout {{ drain_timeout }}
--delete-local-data {{ ansible_hostname }}
delegate_to: "{{ groups['kube-master'][0] }}"
- name: Sleep for grace period for draining
pause: seconds=30
when: needs_cordoning