mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-13 21:12:05 +00:00
Handle invalid kubeconfig parsing error (#119)
Provide message to user about invalid or empty kubeconfig by handling exception raised by kubernetes Python API Fixes: #90 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
@@ -191,13 +191,19 @@ class K8sAnsibleMixin(object):
|
|||||||
# We have enough in the parameters to authenticate, no need to load incluster or kubeconfig
|
# We have enough in the parameters to authenticate, no need to load incluster or kubeconfig
|
||||||
pass
|
pass
|
||||||
elif auth_set('kubeconfig') or auth_set('context'):
|
elif auth_set('kubeconfig') or auth_set('context'):
|
||||||
kubernetes.config.load_kube_config(auth.get('kubeconfig'), auth.get('context'), persist_config=auth.get('persist_config'))
|
try:
|
||||||
|
kubernetes.config.load_kube_config(auth.get('kubeconfig'), auth.get('context'), persist_config=auth.get('persist_config'))
|
||||||
|
except Exception as err:
|
||||||
|
self.fail(msg='Failed to load kubeconfig due to %s' % to_native(err))
|
||||||
else:
|
else:
|
||||||
# First try to do incluster config, then kubeconfig
|
# First try to do incluster config, then kubeconfig
|
||||||
try:
|
try:
|
||||||
kubernetes.config.load_incluster_config()
|
kubernetes.config.load_incluster_config()
|
||||||
except kubernetes.config.ConfigException:
|
except kubernetes.config.ConfigException:
|
||||||
kubernetes.config.load_kube_config(auth.get('kubeconfig'), auth.get('context'), persist_config=auth.get('persist_config'))
|
try:
|
||||||
|
kubernetes.config.load_kube_config(auth.get('kubeconfig'), auth.get('context'), persist_config=auth.get('persist_config'))
|
||||||
|
except Exception as err:
|
||||||
|
self.fail(msg='Failed to load kubeconfig due to %s' % to_native(err))
|
||||||
|
|
||||||
# Override any values in the default configuration with Ansible parameters
|
# Override any values in the default configuration with Ansible parameters
|
||||||
configuration = kubernetes.client.Configuration()
|
configuration = kubernetes.client.Configuration()
|
||||||
|
|||||||
Reference in New Issue
Block a user