From a6ee6b6d977682a3907bc8de77ffd60dc847e58a Mon Sep 17 00:00:00 2001 From: Ottavia Balducci Date: Fri, 15 Nov 2024 11:06:20 +0100 Subject: [PATCH] Fix k8s_drain runs into timeout with pods from stateful sets. --- changelogs/fragments/793-fix-k8s-drain-runs-into-timeout.yaml | 2 ++ plugins/module_utils/helm.py | 1 - plugins/modules/k8s_drain.py | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/793-fix-k8s-drain-runs-into-timeout.yaml diff --git a/changelogs/fragments/793-fix-k8s-drain-runs-into-timeout.yaml b/changelogs/fragments/793-fix-k8s-drain-runs-into-timeout.yaml new file mode 100644 index 0000000000..26b8b8407c --- /dev/null +++ b/changelogs/fragments/793-fix-k8s-drain-runs-into-timeout.yaml @@ -0,0 +1,2 @@ +bugfixes: + - k8s_drain - Fix k8s_drain runs into a timeout when evicting a pod which is part of a stateful set (https://github.com/ansible-collections/kubernetes.core/issues/792). diff --git a/plugins/module_utils/helm.py b/plugins/module_utils/helm.py index edc48f6b0c..4318ff0851 100644 --- a/plugins/module_utils/helm.py +++ b/plugins/module_utils/helm.py @@ -77,7 +77,6 @@ def write_temp_kubeconfig(server, validate_certs=True, ca_cert=None, kubeconfig= class AnsibleHelmModule(object): - """ An Ansible module class for Kubernetes.core helm modules """ diff --git a/plugins/modules/k8s_drain.py b/plugins/modules/k8s_drain.py index 045d26f815..9d8561e708 100644 --- a/plugins/modules/k8s_drain.py +++ b/plugins/modules/k8s_drain.py @@ -299,7 +299,9 @@ def _elapsed_time(): response = self._api_instance.read_namespaced_pod( namespace=pod[0], name=pod[1] ) - if not response: + if not response or response.spec.node_name != self._module.params.get( + "name" + ): pod = None del pods[-1] time.sleep(wait_sleep)