mirror of
https://github.com/kubevirt/kubevirt.core.git
synced 2026-03-26 19:03:16 +00:00
chore: Bump dependency on kubernetes.core
Bump the dependency on kubernetes.core to versions >=3.0.1 and remove
the workaround introduced by 4429ac8c03.
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
---
|
||||
ancestor: 1.0.0
|
||||
releases:
|
||||
1.0.0:
|
||||
@@ -7,14 +8,14 @@ releases:
|
||||
1.1.0:
|
||||
changes:
|
||||
major_changes:
|
||||
- Add kubevirt_vm_info module to describe existing VirtualMachines
|
||||
- Add kubevirt_vm_info module to describe existing VirtualMachines
|
||||
minor_changes:
|
||||
- 'inventory: Allow to control creation of additional groups'
|
||||
- 'inventory: Drop creation of the namespace_vmis_group as it is redundant'
|
||||
- 'inventory: Allow to control creation of additional groups'
|
||||
- 'inventory: Drop creation of the namespace_vmis_group as it is redundant'
|
||||
fragments:
|
||||
- 0_flatten_groups.yml
|
||||
- 1_add_create_groups.yml
|
||||
- 3_add_kubevirt_vm_info.yml
|
||||
- 0_flatten_groups.yml
|
||||
- 1_add_create_groups.yml
|
||||
- 3_add_kubevirt_vm_info.yml
|
||||
release_date: '2023-09-21'
|
||||
1.2.0:
|
||||
release_date: '2024-03-04'
|
||||
|
||||
@@ -6,7 +6,7 @@ readme: README.md
|
||||
authors:
|
||||
- KubeVirt Project (kubevirt.io)
|
||||
dependencies:
|
||||
kubernetes.core: '>=2.0.0'
|
||||
kubernetes.core: '>=3.0.1'
|
||||
description: Lean Ansible bindings for KubeVirt
|
||||
license_file: LICENSE
|
||||
tags:
|
||||
|
||||
@@ -160,7 +160,6 @@ EXAMPLES = """
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from collections import defaultdict
|
||||
from json import loads
|
||||
from typing import (
|
||||
Any,
|
||||
@@ -173,19 +172,12 @@ from typing import (
|
||||
# Handle import errors of python kubernetes client.
|
||||
# HAS_K8S_MODULE_HELPER imported below will print a warning to the user if the client is missing.
|
||||
try:
|
||||
from kubernetes.dynamic.resource import Resource
|
||||
from kubernetes.dynamic.exceptions import DynamicApiError, ServiceUnavailableError
|
||||
from kubernetes.dynamic.exceptions import DynamicApiError
|
||||
except ImportError:
|
||||
|
||||
class Resource:
|
||||
pass
|
||||
|
||||
class DynamicApiError(Exception):
|
||||
pass
|
||||
|
||||
class ServiceUnavailableError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
||||
|
||||
@@ -194,29 +186,6 @@ from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
||||
k8s_import_exception,
|
||||
)
|
||||
|
||||
# Handle import errors of python kubernetes client.
|
||||
# HAS_K8S_MODULE_HELPER imported above will print a warning to the user if the client is missing.
|
||||
try:
|
||||
from ansible_collections.kubernetes.core.plugins.module_utils.client.discovery import (
|
||||
Discoverer,
|
||||
)
|
||||
except ImportError:
|
||||
|
||||
class Discoverer:
|
||||
pass
|
||||
|
||||
|
||||
# Handle import errors of python kubernetes client.
|
||||
# HAS_K8S_MODULE_HELPER imported above will print a warning to the user if the client is missing.
|
||||
try:
|
||||
from ansible_collections.kubernetes.core.plugins.module_utils.client.resource import (
|
||||
ResourceList,
|
||||
)
|
||||
except ImportError:
|
||||
|
||||
class ResourceList:
|
||||
pass
|
||||
|
||||
|
||||
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.client import (
|
||||
get_api_client,
|
||||
@@ -340,9 +309,6 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
super().__init__()
|
||||
self.host_format = None
|
||||
|
||||
# Monkey patch the Discoverers method, see end of file for an explanation.
|
||||
Discoverer.get_resources_for_api_version = _get_resources_for_api_version
|
||||
|
||||
def verify_file(self, path: str) -> None:
|
||||
"""
|
||||
verify_file ensures the inventory file is compatible with this plugin.
|
||||
@@ -695,68 +661,3 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
ansible_host = ip_address
|
||||
|
||||
self.inventory.set_variable(vmi_name, "ansible_host", ansible_host)
|
||||
|
||||
|
||||
# This function is copied from the kubernetes.core sources and a fix to handle apis of the format a/b/c was applied.
|
||||
# To ensure compatibility with KubeVirt >=1.1.0 the kubernetes.core Discoverers original method is monkey patched with this one.
|
||||
# TODO: Remove this once the fix was applied to the upstream kubernetes.core collection.
|
||||
#
|
||||
# See:
|
||||
# https://github.com/ansible-collections/kubernetes.core/blob/main/plugins/module_utils/client/discovery.py
|
||||
# https://github.com/ansible-collections/kubernetes.core/issues/685
|
||||
# https://github.com/kubernetes-client/python/issues/2091
|
||||
# https://github.com/kubernetes-client/python/pull/2095
|
||||
def _get_resources_for_api_version(self, prefix, group, version, preferred):
|
||||
"""returns a dictionary of resources associated with provided (prefix, group, version)"""
|
||||
|
||||
resources = defaultdict(list)
|
||||
subresources = defaultdict(dict)
|
||||
|
||||
path = "/".join(filter(None, [prefix, group, version]))
|
||||
try:
|
||||
resources_response = self.client.request("GET", path).resources or []
|
||||
except ServiceUnavailableError:
|
||||
resources_response = []
|
||||
|
||||
resources_raw = list(
|
||||
filter(lambda resource: "/" not in resource["name"], resources_response)
|
||||
)
|
||||
subresources_raw = list(
|
||||
filter(lambda resource: "/" in resource["name"], resources_response)
|
||||
)
|
||||
for subresource in subresources_raw:
|
||||
resource, name = subresource["name"].split("/", 1)
|
||||
subresources[resource][name] = subresource
|
||||
|
||||
for resource in resources_raw:
|
||||
# Prevent duplicate keys
|
||||
for key in ("prefix", "group", "api_version", "client", "preferred"):
|
||||
resource.pop(key, None)
|
||||
|
||||
resourceobj = Resource(
|
||||
prefix=prefix,
|
||||
group=group,
|
||||
api_version=version,
|
||||
client=self.client,
|
||||
preferred=preferred,
|
||||
subresources=subresources.get(resource["name"]),
|
||||
**resource,
|
||||
)
|
||||
resources[resource["kind"]].append(resourceobj)
|
||||
|
||||
resource_lookup = {
|
||||
"prefix": prefix,
|
||||
"group": group,
|
||||
"api_version": version,
|
||||
"kind": resourceobj.kind,
|
||||
"name": resourceobj.name,
|
||||
}
|
||||
resource_list = ResourceList(
|
||||
self.client,
|
||||
group=group,
|
||||
api_version=version,
|
||||
base_kind=resource["kind"],
|
||||
base_resource_lookup=resource_lookup,
|
||||
)
|
||||
resources[resource_list.kind].append(resource_list)
|
||||
return resources
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
---
|
||||
collections:
|
||||
- name: kubernetes.core
|
||||
version: '>=2.0.0'
|
||||
version: '>=3.0.1'
|
||||
|
||||
Reference in New Issue
Block a user