Skip to content

Commit

Permalink
fix: Ensure compatibility with kubernetes.core >=3.10,<4.1.0
Browse files Browse the repository at this point in the history
Ensure compatibility with kubernetes.core >=3.10,<4.1.0 by replacing
deprecated imports of HAS_K8S_MODULE_HELPER and k8s_import_exception.

Signed-off-by: Felix Matouschek <[email protected]>
  • Loading branch information
0xFelix committed May 29, 2024
1 parent 131aace commit a9c6296
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ansible-galaxy collection install kubevirt-kubevirt.core-*.tar.gz
<!--start collection_dependencies -->
#### Ansible collections

* [kubernetes.core](https://galaxy.ansible.com/ui/repo/published/kubernetes/core)>=3.0.1
* [kubernetes.core](https://galaxy.ansible.com/ui/repo/published/kubernetes/core)>=3.1.0,<4.1.0

To install all the dependencies:
```bash
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ readme: README.md
authors:
- KubeVirt Project (kubevirt.io)
dependencies:
kubernetes.core: '>=3.0.1'
kubernetes.core: '>=3.1.0,<4.1.0'
description: Lean Ansible bindings for KubeVirt
license_file: LICENSE
tags:
Expand Down
15 changes: 8 additions & 7 deletions plugins/inventory/kubevirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,23 @@


# 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.
# Set HAS_K8S_MODULE_HELPER and k8s_import exception accordingly to
# potentially print a warning to the user if the client is missing.
try:
from kubernetes.dynamic.exceptions import DynamicApiError
except ImportError:

HAS_K8S_MODULE_HELPER = True
k8s_import_exception = None
except ImportError as e:

class DynamicApiError(Exception):
pass

HAS_K8S_MODULE_HELPER = False
k8s_import_exception = e

from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable

from ansible_collections.kubernetes.core.plugins.module_utils.common import (
HAS_K8S_MODULE_HELPER,
k8s_import_exception,
)


from ansible_collections.kubernetes.core.plugins.module_utils.k8s.client import (
get_api_client,
Expand Down
2 changes: 1 addition & 1 deletion requirements.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
collections:
- name: kubernetes.core
version: '>=3.0.1'
version: '>=3.1.0,<4.1.0'

0 comments on commit a9c6296

Please sign in to comment.