mirror of
https://github.com/kubevirt/kubevirt.core.git
synced 2026-05-07 13:52:39 +00:00
Merge pull request #39 from 0xFelix/bump-version-e2e
Bump e2e-setup.sh version and ensure compatibility with KubeVirt >=1.1.0
This commit is contained in:
1
.github/workflows/integration.yml
vendored
1
.github/workflows/integration.yml
vendored
@@ -101,6 +101,7 @@ jobs:
|
||||
if: inputs.ansible_test_targets != ''
|
||||
uses: helm/kind-action@v1.9.0
|
||||
with:
|
||||
version: v0.22.0
|
||||
install_only: true
|
||||
|
||||
- name: Deploy kubevirt
|
||||
|
||||
@@ -23,17 +23,17 @@ set_default_params() {
|
||||
BIN_DIR=${BIN_DIR:-$DIR/../bin}
|
||||
|
||||
KIND=${KIND:-$BIN_DIR/kind}
|
||||
KIND_VERSION=${KIND_VERSION:-v0.20.0}
|
||||
KIND_VERSION=${KIND_VERSION:-v0.22.0}
|
||||
|
||||
KUBECTL=${KUBECTL:-$BIN_DIR/kubectl}
|
||||
KUBECTL_VERSION=${KUBECTL_VERSION:-v1.28.1}
|
||||
KUBECTL_VERSION=${KUBECTL_VERSION:-v1.29.2}
|
||||
|
||||
KUBEVIRT_VERSION=${KUBEVIRT_VERSION:-v1.0.0}
|
||||
KUBEVIRT_CDI_VERSION=${KUBEVIRT_CDI_VERSION:-v1.57.0}
|
||||
KUBEVIRT_COMMON_INSTANCETYPES_VERSION=${KUBEVIRT_COMMON_INSTANCETYPES_VERSION:-v0.3.2}
|
||||
KUBEVIRT_VERSION=${KUBEVIRT_VERSION:-v1.1.0}
|
||||
KUBEVIRT_CDI_VERSION=${KUBEVIRT_CDI_VERSION:-v1.58.1}
|
||||
KUBEVIRT_COMMON_INSTANCETYPES_VERSION=${KUBEVIRT_COMMON_INSTANCETYPES_VERSION:-v0.4.0}
|
||||
KUBEVIRT_USE_EMULATION=${KUBEVIRT_USE_EMULATION:-"false"}
|
||||
|
||||
CNAO_VERSION=${CNAO_VERSION:-v0.89.0}
|
||||
CNAO_VERSION=${CNAO_VERSION:-v0.91.0}
|
||||
|
||||
CLUSTER_NAME=${CLUSTER_NAME:-kind}
|
||||
SECONDARY_NETWORK_NAME=${NETWORK_NAME:-kindexgw}
|
||||
|
||||
@@ -124,7 +124,7 @@ options:
|
||||
|
||||
requirements:
|
||||
- "python >= 3.6"
|
||||
- "kubernetes >= 12.0.0"
|
||||
- "kubernetes >= 28.1.0"
|
||||
- "PyYAML >= 3.11"
|
||||
"""
|
||||
|
||||
@@ -160,6 +160,7 @@ EXAMPLES = """
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from collections import defaultdict
|
||||
from json import loads
|
||||
from typing import (
|
||||
Any,
|
||||
@@ -170,17 +171,26 @@ from typing import (
|
||||
Union,
|
||||
)
|
||||
|
||||
|
||||
# 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 ResourceField
|
||||
from kubernetes.dynamic.exceptions import DynamicApiError
|
||||
from kubernetes.dynamic.resource import Resource, ResourceField
|
||||
from kubernetes.dynamic.exceptions import DynamicApiError, ServiceUnavailableError
|
||||
except ImportError:
|
||||
|
||||
class Resource:
|
||||
pass
|
||||
|
||||
class ResourceField:
|
||||
pass
|
||||
|
||||
class DynamicApiError(Exception):
|
||||
pass
|
||||
|
||||
class ServiceUnavailableError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
||||
|
||||
@@ -189,11 +199,36 @@ 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,
|
||||
K8SClient,
|
||||
)
|
||||
|
||||
|
||||
LABEL_KUBEVIRT_IO_DOMAIN = "kubevirt.io/domain"
|
||||
TYPE_LOADBALANCER = "LoadBalancer"
|
||||
TYPE_NODEPORT = "NodePort"
|
||||
@@ -310,6 +345,9 @@ 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.
|
||||
@@ -690,3 +728,68 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
return [self.__resource_field_to_dict(item) for item in field]
|
||||
|
||||
return field
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
@@ -106,7 +106,7 @@ options:
|
||||
|
||||
requirements:
|
||||
- "python >= 3.6"
|
||||
- "kubernetes >= 12.0.0"
|
||||
- "kubernetes >= 28.1.0"
|
||||
- "PyYAML >= 3.11"
|
||||
- "jsonpatch"
|
||||
- "jinja2"
|
||||
|
||||
@@ -69,7 +69,7 @@ extends_documentation_fragment:
|
||||
|
||||
requirements:
|
||||
- "python >= 3.6"
|
||||
- "kubernetes >= 12.0.0"
|
||||
- "kubernetes >= 28.1.0"
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
kubernetes>=12.0.0
|
||||
kubernetes>=28.1.0
|
||||
PyYaml
|
||||
jsonpatch
|
||||
jinja2
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
instancetype:
|
||||
name: u1.small
|
||||
preference:
|
||||
name: centos.9.stream
|
||||
name: centos.stream9
|
||||
spec:
|
||||
domain:
|
||||
devices: {}
|
||||
|
||||
Reference in New Issue
Block a user