From 92f25bf267ffd3393f6caffa588169d3a44a799c Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Tue, 4 Jan 2022 16:10:53 +0100 Subject: [PATCH] Simplify usage of pre-remove role (#8334) - Use builtin task scheduling of ansible (same task on each host) instead of manual looping on master Benefits: - One less play in remove-node.yml playbook - Parralel node drain - Drain parameters (timeout, grace period, retries, allow_ungraceful_removal) can be adjusted separately for each node with ansible variables --- remove-node.yml | 8 +------- roles/remove-node/pre-remove/tasks/main.yml | 6 ++---- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/remove-node.yml b/remove-node.yml index d8491073d..d99740c3f 100644 --- a/remove-node.yml +++ b/remove-node.yml @@ -21,13 +21,6 @@ msg: "Delete nodes confirmation failed" when: pause_result.user_input | default('yes') != 'yes' -- hosts: kube_control_plane[0] - gather_facts: no - environment: "{{ proxy_disable_env }}" - roles: - - { role: kubespray-defaults } - - { role: remove-node/pre-remove, tags: pre-remove } - - name: Gather facts import_playbook: facts.yml @@ -36,6 +29,7 @@ environment: "{{ proxy_disable_env }}" roles: - { role: kubespray-defaults, when: reset_nodes|default(True)|bool } + - { role: remove-node/pre-remove, tags: pre-remove } - { role: remove-node/remove-etcd-node } - { role: reset, tags: reset, when: reset_nodes|default(True)|bool } diff --git a/roles/remove-node/pre-remove/tasks/main.yml b/roles/remove-node/pre-remove/tasks/main.yml index 2344bc3b1..d92004809 100644 --- a/roles/remove-node/pre-remove/tasks/main.yml +++ b/roles/remove-node/pre-remove/tasks/main.yml @@ -14,14 +14,12 @@ --ignore-daemonsets --grace-period {{ drain_grace_period }} --timeout {{ drain_timeout }} - --delete-emptydir-data {{ hostvars[item]['kube_override_hostname']|default(item) }} - loop: "{{ node.split(',') | default(groups['kube_node']) }}" + --delete-emptydir-data {{ kube_override_hostname|default(inventory_hostname) }} # ignore servers that are not nodes - when: hostvars[item]['kube_override_hostname']|default(item) in nodes.stdout_lines + when: kube_override_hostname|default(inventory_hostname) in nodes.stdout_lines register: result failed_when: result.rc != 0 and not allow_ungraceful_removal delegate_to: "{{ groups['kube_control_plane']|first }}" - run_once: true until: result.rc == 0 or allow_ungraceful_removal retries: "{{ drain_retries }}" delay: "{{ drain_retry_delay_seconds }}"