From 4f32f94a51706edd461b00ddb3ffc6dd2ceed3f7 Mon Sep 17 00:00:00 2001
From: Chad Swenson <chadswen@gmail.com>
Date: Thu, 8 Dec 2022 18:02:11 -0600
Subject: [PATCH] Fix drain rescue task when `kube_override_hostname` is set
 (#9556)

This fixes a task failure in the rescue block that uncordons nodes after an unsuccessful drain. The issue occurs when `kube_override_hostname` is set and does not match `inventory_hostname`.
---
 roles/upgrade/pre-upgrade/tasks/main.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/roles/upgrade/pre-upgrade/tasks/main.yml b/roles/upgrade/pre-upgrade/tasks/main.yml
index 1f65aa239..210818b3c 100644
--- a/roles/upgrade/pre-upgrade/tasks/main.yml
+++ b/roles/upgrade/pre-upgrade/tasks/main.yml
@@ -119,11 +119,11 @@
 
   rescue:
     - name: Set node back to schedulable
-      command: "{{ kubectl }} uncordon {{ inventory_hostname }}"
+      command: "{{ kubectl }} uncordon {{ kube_override_hostname|default(inventory_hostname) }}"
       when: upgrade_node_uncordon_after_drain_failure
     - name: Fail after rescue
       fail:
-        msg: "Failed to drain node {{ inventory_hostname }}"
+        msg: "Failed to drain node {{ kube_override_hostname|default(inventory_hostname) }}"
       when: upgrade_node_fail_if_drain_fails
   delegate_to: "{{ groups['kube_control_plane'][0] }}"
   when:
-- 
GitLab