openshift / community.okd

OKD/Openshift collection for Ansible
http://galaxy.ansible.com/community/okd
GNU General Public License v3.0
56 stars 36 forks source link

Unsupported parameters for (k8s) module: label_selectors #177

Closed mike-lloyd03 closed 2 years ago

mike-lloyd03 commented 2 years ago

Summary

I was redirected here by ansibot from https://github.com/ansible/ansible/issues/79255.

When attempting to use the label_selectors parameter with the k8s module as per the docs, I get an error message stating that the parameter is unsupported.

Issue Type

Bug Report

Component Name

k8s

Ansible Version

ansible [core 2.13.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/mike/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /home/mike/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.6 (main, Aug  3 2022, 17:39:45) [GCC 12.1.1 20220730]
  jinja version = 3.1.2
  libyaml = True

OS / Environment

Linux 5.19.3-arch1-1 x86_64 running inside a QEMU VM on a Mac running macOS 12.5.1

Steps to Reproduce

I am attempting to delete all pods with a specific label:

- name: "Redeploy coredns pods"
  k8s:
    namespace: "kube-system"
    kind: pod
    label_selectors:
      - k8s-app=kube-dns
    state: absent

Using the k8s_info module as a workaround is successful:

- name: "Get coredns pods"
  k8s_info:
    namespace: "kube-system"
    kind: pod
    label_selectors:
      - k8s-app=kube-dns
  register: pods

- name: "Redeploy coredns pods"
  k8s:
    namespace: "kube-system"
    kind: pod
    name: "{{ item.metadata.name }}"
    state: absent
  with_items: "{{ pods.resources }}"

Expected Results

All pods with the specified labels are deleted.

Actual Results

fatal: [127.0.0.1]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (k8s) module: label_selectors Supported parameters include: api_key, api_version, append_hash, apply, ca_cert, client_cert, client_key, context, force, host, kind, kubeconfig, merge_type, name, namespace, password, persist_config, proxy, resource_definition, src, state, template, username, validate, validate_certs, wait, wait_condition, wait_sleep, wait_timeout"}
gravesm commented 2 years ago

@mike-lloyd03 Could you clarify if you are using the community.okd.k8s module or the kubernetes.core.k8s module? Also, which version of the collection you are using?

mike-lloyd03 commented 2 years ago

ansible-galaxy collections list actually shows both collections. So calling kubernetes.core.k8s appears to be the answer. Your question seems to have answered my question.