From 483d860d7db0acab484d6eb2d4a74d53136367a9 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Mon, 27 Nov 2023 15:11:33 +0100 Subject: [PATCH 1/2] Clean up redondant defaulting drain_{timeout,grace_period}_after_failure don't exist at this point, so they always default. --- roles/upgrade/pre-upgrade/tasks/main.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/roles/upgrade/pre-upgrade/tasks/main.yml b/roles/upgrade/pre-upgrade/tasks/main.yml index 58dfee0a9fd..eecb656c29f 100644 --- a/roles/upgrade/pre-upgrade/tasks/main.yml +++ b/roles/upgrade/pre-upgrade/tasks/main.yml @@ -38,13 +38,7 @@ - name: Set if node needs cordoning set_fact: - # noqa: jinja[spacing] - needs_cordoning: >- - {% if (kubectl_node_ready.stdout == "True" and not kubectl_node_schedulable.stdout) or upgrade_node_always_cordon -%} - true - {%- else -%} - false - {%- endif %} + needs_cordoning: "{{ (kubectl_node_ready.stdout == 'True' and not kubectl_node_schedulable.stdout) or upgrade_node_always_cordon }}" - name: Node draining delegate_to: "{{ groups['kube_control_plane'][0] }}" @@ -78,8 +72,8 @@ {{ kubectl }} drain --force --ignore-daemonsets - --grace-period {{ hostvars['localhost']['drain_grace_period_after_failure'] | default(drain_grace_period) }} - --timeout {{ hostvars['localhost']['drain_timeout_after_failure'] | default(drain_timeout) }} + --grace-period {{ drain_grace_period }} + --timeout {{ drain_timeout }} --delete-emptydir-data {{ kube_override_hostname | default(inventory_hostname) }} {% if drain_pod_selector %}--pod-selector '{{ drain_pod_selector }}'{% endif %} when: drain_nodes From 5938d6461efc4502ddabd2f46928fb18cad66a08 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Mon, 27 Nov 2023 15:29:05 +0100 Subject: [PATCH 2/2] Remove useless facts The drain_*_after_failure are never used --- roles/upgrade/pre-upgrade/tasks/main.yml | 40 +++++++++--------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/roles/upgrade/pre-upgrade/tasks/main.yml b/roles/upgrade/pre-upgrade/tasks/main.yml index eecb656c29f..ddfc15d47d7 100644 --- a/roles/upgrade/pre-upgrade/tasks/main.yml +++ b/roles/upgrade/pre-upgrade/tasks/main.yml @@ -85,35 +85,25 @@ retries: "{{ drain_retries }}" delay: "{{ drain_retry_delay_seconds }}" - - name: Drain fallback + - name: Drain node - fallback with disabled eviction when: - drain_nodes - drain_fallback_enabled - result.rc != 0 - block: - - name: Set facts after regular drain has failed - set_fact: - drain_grace_period_after_failure: "{{ drain_fallback_grace_period }}" - drain_timeout_after_failure: "{{ drain_fallback_timeout }}" - delegate_to: localhost - delegate_facts: yes - run_once: yes - - - name: Drain node - fallback with disabled eviction - command: >- - {{ kubectl }} drain - --force - --ignore-daemonsets - --grace-period {{ drain_fallback_grace_period }} - --timeout {{ drain_fallback_timeout }} - --delete-emptydir-data {{ kube_override_hostname | default(inventory_hostname) }} - {% if drain_pod_selector %}--pod-selector '{{ drain_pod_selector }}'{% endif %} - --disable-eviction - register: drain_fallback_result - until: drain_fallback_result.rc == 0 - retries: "{{ drain_fallback_retries }}" - delay: "{{ drain_fallback_retry_delay_seconds }}" - changed_when: drain_fallback_result.rc == 0 + command: >- + {{ kubectl }} drain + --force + --ignore-daemonsets + --grace-period {{ drain_fallback_grace_period }} + --timeout {{ drain_fallback_timeout }} + --delete-emptydir-data {{ kube_override_hostname | default(inventory_hostname) }} + {% if drain_pod_selector %}--pod-selector '{{ drain_pod_selector }}'{% endif %} + --disable-eviction + register: drain_fallback_result + until: drain_fallback_result.rc == 0 + retries: "{{ drain_fallback_retries }}" + delay: "{{ drain_fallback_retry_delay_seconds }}" + changed_when: drain_fallback_result.rc == 0 rescue: - name: Set node back to schedulable