Uploaded image for project: 'Ansible Cloud Automation'
  1. Ansible Cloud Automation
  2. ACA-976

[kubernetes.core/622] k8s_drain erroneously deletes daemonset when both delete options `delete_emptydir_data` and `ignore_daemonsets` are set to `true`

XMLWordPrintable

    • False
    • Hide

      None

      Show
      None
    • 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 -->

              1. SUMMARY
                <!--- Explain the problem briefly below -->
              1. ISSUE TYPE
      • Bug Report
              1. COMPONENT NAME
                <!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
                kubernetes.core.k8s_drain
              1. 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
                ```
              1. 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
                                    ```
              1. CONFIGURATION
                <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
                ```paste below

      ```

              1. 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
              1. STEPS TO REPRODUCE
                <!--- Describe exactly how to reproduce the problem, using a minimal test-case -->
      • 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 -->

              1. 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`).
              1. ACTUAL RESULTS
                <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

      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.

            Unassigned Unassigned
            jrouleau Jill Rouleau
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: