From ef46c352d0261d8d2c51f77ca6df3f2f6dc0b294 Mon Sep 17 00:00:00 2001 From: Mike Graves Date: Tue, 30 Nov 2021 04:07:08 -0500 Subject: [PATCH] Fix k8s_drain failing when pod has local storage (#295) Fix k8s_drain failing when pod has local storage SUMMARY The module fails to define the pod_names variable before using it for pods with local storage. Fixes #292 ISSUE TYPE Bugfix Pull Request COMPONENT NAME k8s_drain ADDITIONAL INFORMATION Reviewed-by: Abhijeet Kasurde Reviewed-by: None Reviewed-by: None --- .../fragments/295-fix-k8s-drain-variable-declaration.yaml | 3 +++ plugins/modules/k8s_drain.py | 1 + 2 files changed, 4 insertions(+) create mode 100644 changelogs/fragments/295-fix-k8s-drain-variable-declaration.yaml diff --git a/changelogs/fragments/295-fix-k8s-drain-variable-declaration.yaml b/changelogs/fragments/295-fix-k8s-drain-variable-declaration.yaml new file mode 100644 index 00000000..c56d3863 --- /dev/null +++ b/changelogs/fragments/295-fix-k8s-drain-variable-declaration.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - k8s_drain - fix error caused by accessing an undefined variable when pods have local storage (https://github.com/ansible-collections/kubernetes.core/issues/292). diff --git a/plugins/modules/k8s_drain.py b/plugins/modules/k8s_drain.py index 28ff24df..03aee07f 100644 --- a/plugins/modules/k8s_drain.py +++ b/plugins/modules/k8s_drain.py @@ -197,6 +197,7 @@ def filter_pods(pods, force, ignore_daemonset): # local storage if localStorage: + pod_names = ",".join([pod[0] + "/" + pod[1] for pod in localStorage]) errors.append("cannot delete Pods with local storage: {0}.".format(pod_names)) # DaemonSet managed Pods