Last active
July 17, 2018 18:07
-
-
Save jmvrbanac/2c39fde00e68bad43ddba8ba2e141efd to your computer and use it in GitHub Desktop.
Python Kubernetes use dictionary config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kubernetes.client import ApiClient, Configuration, CoreV1Api | |
from kubernetes.config import kube_config | |
def build_k8_client(cfg_dict): | |
loader = kube_config.KubeConfigLoader(cfg_dict) | |
config_cls = type.__call__(Configuration) | |
loader.load_and_set(config_cls) | |
Configuration.set_default(config_cls) | |
return ApiClient(configuration=config_cls) | |
def list_namespaces_names(client): | |
api = CoreV1Api(client) | |
response = api.list_namespace() | |
return [item.metadata.name for item in response.items] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment