mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-07 21:42:38 +00:00
Import ApiException from single source (#384)
Import ApiException from single source SUMMARY Signed-off-by: Abhijeet Kasurde akasurde@redhat.com ISSUE TYPE Bugfix Pull Request COMPONENT NAME changelogs/fragments/exception.yml plugins/modules/k8s_drain.py plugins/modules/k8s_taint.py Reviewed-by: None <None>
This commit is contained in:
3
changelogs/fragments/exception.yml
Normal file
3
changelogs/fragments/exception.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- import exception from ``kubernetes.client.rest``.
|
||||||
@@ -124,9 +124,12 @@ result:
|
|||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
from datetime import datetime
|
|
||||||
import time
|
import time
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import (
|
||||||
AnsibleModule,
|
AnsibleModule,
|
||||||
)
|
)
|
||||||
@@ -137,12 +140,26 @@ from ansible.module_utils._text import to_native
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from kubernetes.client.api import core_v1_api
|
from kubernetes.client.api import core_v1_api
|
||||||
from kubernetes.client.models import V1beta1Eviction, V1DeleteOptions
|
from kubernetes.client.models import V1DeleteOptions
|
||||||
from kubernetes.client.exceptions import ApiException
|
from kubernetes.client.exceptions import ApiException
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# ImportError are managed by the common module already.
|
# ImportError are managed by the common module already.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
HAS_EVICTION_API = True
|
||||||
|
k8s_import_exception = None
|
||||||
|
K8S_IMP_ERR = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
from kubernetes.client.models import V1beta1Eviction as v1_eviction
|
||||||
|
except ImportError:
|
||||||
|
try:
|
||||||
|
from kubernetes.client.models import V1Eviction as v1_eviction
|
||||||
|
except ImportError as e:
|
||||||
|
k8s_import_exception = e
|
||||||
|
K8S_IMP_ERR = traceback.format_exc()
|
||||||
|
HAS_EVICTION_API = False
|
||||||
|
|
||||||
|
|
||||||
def filter_pods(pods, force, ignore_daemonset, delete_emptydir_data):
|
def filter_pods(pods, force, ignore_daemonset, delete_emptydir_data):
|
||||||
k8s_kind_mirror = "kubernetes.io/config.mirror"
|
k8s_kind_mirror = "kubernetes.io/config.mirror"
|
||||||
@@ -311,7 +328,7 @@ class K8sDrainAnsible(object):
|
|||||||
name=name, namespace=namespace, body=body
|
name=name, namespace=namespace, body=body
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
body = V1beta1Eviction(**definition)
|
body = v1_eviction(**definition)
|
||||||
self._api_instance.create_namespaced_pod_eviction(
|
self._api_instance.create_namespaced_pod_eviction(
|
||||||
name=name, namespace=namespace, body=body
|
name=name, namespace=namespace, body=body
|
||||||
)
|
)
|
||||||
@@ -496,6 +513,13 @@ def argspec():
|
|||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(argument_spec=argspec())
|
module = AnsibleModule(argument_spec=argspec())
|
||||||
|
|
||||||
|
if not HAS_EVICTION_API:
|
||||||
|
module.fail_json(
|
||||||
|
msg="The kubernetes Python library missing with V1Eviction API",
|
||||||
|
exception=K8S_IMP_ERR,
|
||||||
|
error=to_native(k8s_import_exception),
|
||||||
|
)
|
||||||
|
|
||||||
k8s_drain = K8sDrainAnsible(module)
|
k8s_drain = K8sDrainAnsible(module)
|
||||||
k8s_drain.execute_module()
|
k8s_drain.execute_module()
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
|||||||
try:
|
try:
|
||||||
from kubernetes.client.apis import core_v1_api
|
from kubernetes.client.apis import core_v1_api
|
||||||
from kubernetes.stream import stream
|
from kubernetes.stream import stream
|
||||||
from kubernetes.client.rest import ApiException
|
from kubernetes.client.exceptions import ApiException
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# ImportError are managed by the common module already.
|
# ImportError are managed by the common module already.
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ from ansible_collections.kubernetes.core.plugins.module_utils.args_common import
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from kubernetes.client.api import core_v1_api
|
from kubernetes.client.api import core_v1_api
|
||||||
from kubernetes.dynamic.exceptions import ApiException
|
from kubernetes.client.exceptions import ApiException
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# ImportError are managed by the common module already.
|
# ImportError are managed by the common module already.
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user