-
Bug
-
Resolution: Won't Do
-
Undefined
-
None
-
Unspecified
-
False
-
-
False
-
-
https://github.com/ansible-collections/kubernetes.core/issues/622
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete all sections as described, this form is processed automatically -->
-
-
-
-
- SUMMARY
<!--- Explain the problem briefly below -->
- SUMMARY
-
-
-
-
-
-
-
- ISSUE TYPE
-
-
-
- Bug Report
-
-
-
-
- COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
kubernetes.core.k8s_drain
- COMPONENT NAME
-
-
-
-
-
-
-
- ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible [core 2.13.9]
configured module search path = ['/home/dev/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/dev/.local/lib/python3.8/site-packages/ansible
ansible collection location = /home/dev/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
jinja version = 3.1.2
libyaml = True
```
- ANSIBLE VERSION
-
-
-
-
-
-
-
- COLLECTION VERSION
<!--- Paste verbatim output from "ansible-galaxy collection list <namespace>.<collection>" between the quotes
for example: ansible-galaxy collection list community.general
-->
```paste below
Collection Version-
-
-
-
-
-
-
-
-
- -------
kubernetes.core 2.3.2
```
- -------
-
-
-
-
-
-
-
-
-
- COLLECTION VERSION
-
-
-
-
-
-
-
- CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below
- CONFIGURATION
-
-
-
```
-
-
-
-
- OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
Ubuntu 20.04.5 LTS
Kubernetes 1.27.1
- OS / ENVIRONMENT
-
-
-
-
-
-
-
- STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->
- STEPS TO REPRODUCE
-
-
-
- create a daemonset with an `emptyDir` volume
- use the `k8s_drain` module as shown below to drain a node that is running an instance of the daemonset
<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: drain node {{ node }}
kubernetes.core.k8s_drain:
state: drain
name: '{{ node }}'
delete_options:
delete_emptydir_data: true
ignore_daemonsets: true
```
<!--- HINT: You can paste gist.github.com links for larger files -->
-
-
-
-
- EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
Since the `ignore_daemonsets` option is set to `true`, the daemonset should not be terminated (this is what happens when using `kubectl drain node --ignore-daemonsets --delete-emptydir-data`).
- EXPECTED RESULTS
-
-
-
-
-
-
-
- ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->
- ACTUAL RESULTS
-
-
-
The daemonset gets terminated erroneously.
Looking at the [code of the module](https://github.com/ansible-collections/kubernetes.core/blob/54d8193972ead06dd482e3aff71fe07b32957ab2/plugins/modules/k8s_drain.py#L175), this is happening because both conditions are evaluated independently. That means any pod with an `emptyDir` volume will be deleted, regardless of other flags (i.e. even unmanaged pods will be deleted when `force` is set to `false`). In my understanding (and seemingly what happens with `kubectl`), the `delete_emptydir_data` option should only be applied to filter the list of pods deemed suitable for deletion based on the other criteria.