Skip to content

Commit

Permalink
Fix k8s_drain runs into timeout with pods from stateful sets. (#793) (#…
Browse files Browse the repository at this point in the history
…808)

This is a backport of PR #793 as merged into main (fca0dc0).
SUMMARY
Fixes #792 .
The function wait_for_pod_deletion in k8s_drain never checks on which node a pod is actually running:
            try:
                response = self._api_instance.read_namespaced_pod(
                    namespace=pod[0], name=pod[1]
                )
                if not response:
                    pod = None
                time.sleep(wait_sleep)
This means that if a pod is successfully evicted and restarted with the same name on a new node, k8s_drain does not notice and thinks that the original pod is still running. This is the case for pods which are part of a stateful set.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME
k8s_drain
  • Loading branch information
patchback[bot] authored Dec 11, 2024
1 parent 10a9b9e commit 2098dfe
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/793-fix-k8s-drain-runs-into-timeout.yaml
Original file line number Diff line number Diff line change
@@ -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).
1 change: 0 additions & 1 deletion plugins/module_utils/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/k8s_drain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
time.sleep(wait_sleep)
except ApiException as exc:
Expand Down

0 comments on commit 2098dfe

Please sign in to comment.