diff options
author | Marcos Amorim <mamorim@rkh.co.uk> | 2018-06-04 17:22:26 +0100 |
---|---|---|
committer | Marcos Amorim <mamorim@rkh.co.uk> | 2018-06-04 17:22:26 +0100 |
commit | 7a2455852c54b3c7975358b7179fe6f6158b431b (patch) | |
tree | fa6d5058e11c260b1dfedf9fdd5b8bc7c517f5ad | |
parent | 550141074026f46892cd20e4c946040b740696f0 (diff) |
Loading the kubeconfig file var on client instead of kubeshell
-rw-r--r-- | kubeshell/client.py | 6 | ||||
-rw-r--r-- | kubeshell/kubeshell.py | 3 |
2 files changed, 5 insertions, 4 deletions
diff --git a/kubeshell/client.py b/kubeshell/client.py index 360f337..a6304bb 100644 --- a/kubeshell/client.py +++ b/kubeshell/client.py @@ -3,6 +3,7 @@ from urllib3.exceptions import NewConnectionError, ConnectTimeoutError, MaxRetry from kubernetes import client, config from kubernetes.client.api_client import ApiException +import os import logging import urllib3 @@ -10,6 +11,7 @@ import urllib3 ulogger = logging.getLogger("urllib3") ulogger.setLevel("ERROR") urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) +kubeconfig_filepath = os.getenv("KUBECONFIG") or "~/.kube/config" class KubernetesClient(object): @@ -17,7 +19,8 @@ class KubernetesClient(object): def __init__(self): self.logger = logging.getLogger(__name__) try: - config.load_kube_config() + config_file = os.path.expanduser(kubeconfig_filepath) + config.load_kube_config(config_file=config_file) except: self.logger.warning("unable to load kube-config") @@ -29,7 +32,6 @@ class KubernetesClient(object): self.batchV1Api = client.BatchV1Api() self.batchV2Api = client.BatchV2alpha1Api() - def get_resource(self, resource, namespace="all"): ret, resources = None, list() try: diff --git a/kubeshell/kubeshell.py b/kubeshell/kubeshell.py index 4d67d23..7bbc8f2 100644 --- a/kubeshell/kubeshell.py +++ b/kubeshell/kubeshell.py @@ -10,7 +10,7 @@ from kubeshell.style import StyleFactory from kubeshell.completer import KubectlCompleter from kubeshell.lexer import KubectlLexer from kubeshell.toolbar import Toolbar -from kubeshell.client import KubernetesClient +from kubeshell.client import KubernetesClient, kubeconfig_filepath import os import click @@ -24,7 +24,6 @@ inline_help = True registry = load_key_bindings_for_prompt() completer = KubectlCompleter() client = KubernetesClient() -kubeconfig_filepath = os.getenv("KUBECONFIG") or "~/.kube/config" class KubeConfig(object): |