c12s-kubespray/roles/remove-node/pre-remove/tasks/main.yml
Etienne Champetier e7f8d5a987 Fix remove-node by removing jq usage (#7405)
Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
(cherry picked from commit 36a3a78952)
2021-03-29 16:19:56 -07:00

30 lines
1.2 KiB
YAML

---
- name: remove-node | Set `nodes_to_drain` as empty list
set_fact:
nodes_to_drain: []
- name: remove-node | List nodes
command: kubectl get nodes -o go-template={% raw %}'{{ range .items }}{{ .metadata.name }}{{ "\n" }}{{ end }}'{% endraw %}
register: nodes
delegate_to: "{{ groups['kube-master']|first }}"
changed_when: false
run_once: true
- name: remove-node | Drain node except daemonsets resource # noqa 301
command: >-
{{ bin_dir }}/kubectl --kubeconfig /etc/kubernetes/admin.conf drain
--force
--ignore-daemonsets
--grace-period {{ drain_grace_period }}
--timeout {{ drain_timeout }}
--delete-local-data {{ hostvars[item]['kube_override_hostname']|default(item) }}
loop: "{{ node.split(',') | default(groups['kube-node']) }}"
# ignore servers that are not nodes
when: hostvars[item]['kube_override_hostname']|default(item) in nodes.stdout_lines
register: result
failed_when: result.rc != 0 and not allow_ungraceful_removal
delegate_to: "{{ groups['kube-master']|first }}"
run_once: true
until: result.rc == 0 or allow_ungraceful_removal
retries: "{{ drain_retries }}"
delay: "{{ drain_retry_delay_seconds }}"