mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-29 10:54:41 +00:00
Add exception handling when retrieving k8s client
This commit is contained in:
committed by
Jeff Geerling
parent
50557ac47c
commit
d1c0b3a00d
@@ -36,6 +36,7 @@ from ansible.module_utils.common.dict_transformations import dict_merge
|
|||||||
try:
|
try:
|
||||||
import yaml
|
import yaml
|
||||||
from openshift.dynamic.exceptions import DynamicApiError, NotFoundError, ConflictError, ForbiddenError, KubernetesValidateMissing
|
from openshift.dynamic.exceptions import DynamicApiError, NotFoundError, ConflictError, ForbiddenError, KubernetesValidateMissing
|
||||||
|
import urllib3
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Exceptions handled in common
|
# Exceptions handled in common
|
||||||
pass
|
pass
|
||||||
@@ -169,7 +170,11 @@ class KubernetesRawModule(KubernetesAnsibleModule):
|
|||||||
def execute_module(self):
|
def execute_module(self):
|
||||||
changed = False
|
changed = False
|
||||||
results = []
|
results = []
|
||||||
self.client = self.get_api_client()
|
try:
|
||||||
|
self.client = self.get_api_client()
|
||||||
|
# Hopefully the kubernetes client will provide its own exception class one day
|
||||||
|
except (urllib3.exceptions.RequestError) as e:
|
||||||
|
self.fail_json(msg="Couldn't connect to Kubernetes: %s" % str(e))
|
||||||
|
|
||||||
flattened_definitions = []
|
flattened_definitions = []
|
||||||
for definition in self.resource_definitions:
|
for definition in self.resource_definitions:
|
||||||
|
|||||||
Reference in New Issue
Block a user