Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic discovery cannot handle APIs of format a/b/c #685

Closed
0xFelix opened this issue Feb 29, 2024 · 1 comment
Closed

Dynamic discovery cannot handle APIs of format a/b/c #685

0xFelix opened this issue Feb 29, 2024 · 1 comment

Comments

@0xFelix
Copy link
Contributor

0xFelix commented Feb 29, 2024

SUMMARY

The get_resources_for_api_version() method of module_utils.client.discovery.Discoverer expects sub-resource names to be of the format a/b, which breaks with newly added APIs in KubeVirt that are of the format a/b/c.

See:

kubernetes-client/python#2091
kubernetes-client/python#2095

ISSUE TYPE
  • Bug Report
COMPONENT NAME

module_utils.client.discovery.Discoverer

ANSIBLE VERSION
ansible [core 2.16.2]
  config file = /home/felix/.ansible.cfg
  configured module search path = ['/home/felix/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /home/felix/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.12.2 (main, Feb  7 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True
COLLECTION VERSION
# /home/felix/.ansible/collections/ansible_collections
Collection      Version
--------------- -------
kubernetes.core 3.0.0
STEPS TO REPRODUCE

With https://github.com/kubevirt/kubevirt.core try to use the inventory plugin against a cluster running KubeVirt >=1.1.0.

ansible-inventory -i examples/inventory.kubevirt.yml -y --list -vvvv
EXPECTED RESULTS

Inventory should be able to list VMs on cluster.

ACTUAL RESULTS

Inventory fails because it fails to discover APIs on the cluster.

felix@felix-p1 kubevirt/kubevirt.core (bump-version-e2e *) » ansible-inventory -i examples/inventory.kubevirt.yml -y --list -vvvv
ansible-inventory [core 2.16.2]
  config file = /home/felix/.ansible.cfg
  configured module search path = ['/home/felix/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /home/felix/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-inventory
  python version = 3.12.2 (main, Feb  7 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True
Using /home/felix/.ansible.cfg as config file
setting up inventory plugins
Loading collection kubevirt.core from /home/felix/.ansible/collections/ansible_collections/kubevirt/core
Loading collection ansible.builtin from 
Loading collection kubernetes.core from /home/felix/.ansible/collections/ansible_collections/kubernetes/core
[WARNING]:  * Failed to parse /home/felix/Dokumente/kubevirt/kubevirt.core/examples/inventory.kubevirt.yml with ansible_collections.kubevirt.core.plugins.inventory.kubevirt plugin: too many values to unpack (expected 2)
  File "/usr/lib/python3.12/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/felix/.ansible/collections/ansible_collections/kubevirt/core/plugins/inventory/kubevirt.py", line 346, in parse
    self.setup(config_data, cache, cache_key)
  File "/home/felix/.ansible/collections/ansible_collections/kubevirt/core/plugins/inventory/kubevirt.py", line 370, in setup
    self.fetch_objects(connections)
  File "/home/felix/.ansible/collections/ansible_collections/kubevirt/core/plugins/inventory/kubevirt.py", line 405, in fetch_objects
    self.get_vmis_for_namespace(client, name, namespace, opts)
  File "/home/felix/.ansible/collections/ansible_collections/kubevirt/core/plugins/inventory/kubevirt.py", line 469, in get_vmis_for_namespace
    services = self.get_ssh_services_for_namespace(client, namespace)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/felix/.ansible/collections/ansible_collections/kubevirt/core/plugins/inventory/kubevirt.py", line 623, in get_ssh_services_for_namespace
    v1_service = client.resources.get(api_version="v1", kind="Service")
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/felix/.ansible/collections/ansible_collections/kubernetes/core/plugins/module_utils/client/discovery.py", line 158, in get
    results = self.search(**kwargs)
              ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/kubernetes/dynamic/discovery.py", line 246, in search
    results = self.__search(self.__build_search(**kwargs), self.__resources, [])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/kubernetes/dynamic/discovery.py", line 294, in __search
    matches.extend(self.__search([key] + parts[1:], resources, reqParams))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/kubernetes/dynamic/discovery.py", line 280, in __search
    return self.__search(parts[1:], resourcePart, reqParams + [part] )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/kubernetes/dynamic/discovery.py", line 294, in __search
    matches.extend(self.__search([key] + parts[1:], resources, reqParams))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/kubernetes/dynamic/discovery.py", line 280, in __search
    return self.__search(parts[1:], resourcePart, reqParams + [part] )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/kubernetes/dynamic/discovery.py", line 269, in __search
    resourcePart.resources = self.get_resources_for_api_version(
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/felix/.ansible/collections/ansible_collections/kubevirt/core/plugins/inventory/kubevirt.py", line 731, in __get_resources_for_api_version
    resource, name = subresource["name"].split("/")
    ^^^^^^^^^^^^^^
[WARNING]: Unable to parse /home/felix/Dokumente/kubevirt/kubevirt.core/examples/inventory.kubevirt.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{}
@gravesm
Copy link
Member

gravesm commented Feb 29, 2024

Duplicate of #659.

@gravesm gravesm closed this as completed Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants