def load_kube_config( config_file=None, context=None, client_configuration=None, persist_config=True, get_google_credentials=None, print_config=False, **kwargs ): """Loads authentication and cluster information from kube-config file and stores them in kubernetes.client.configuration. :param config_file: Name of the kube-config file. :param context: set the active context. If is set to None, current_context from config file will be used. :param client_configuration: The kubernetes.client.ConfigurationObject to set configs to. :param persist_config: If True, config file will be updated when changed (e.g GCP token refresh). """ if config_file is None: config_file = os.path.expanduser(kube_config.KUBE_CONFIG_DEFAULT_LOCATION) logging.info("Using Kubernetes config file: %s", config_file) config_persister = None if persist_config: def _save_kube_config(config_map): with open(config_file, "w") as f: yaml.safe_dump(config_map, f, default_flow_style=False) config_persister = _save_kube_config loader = kube_config._get_kube_config_loader_for_yaml_file( # pylint: disable=protected-access config_file, active_context=context, config_persister=config_persister, get_google_credentials=get_google_credentials, **kwargs ) if client_configuration is None: config = type.__call__(kubernetes_configuration.Configuration) loader.load_and_set(config) # pylint: disable=too-many-function-args kubernetes_configuration.Configuration.set_default(config) else: loader.load_and_set( client_configuration ) # pylint: disable=too-many-function-args # Dump the loaded config. # Warning this will print out any access tokens stored in your kubeconfig if print_config: run(["kubectl", "config", "view"])
def load_kube_config(config_file=None, context=None, client_configuration=configuration, persist_config=True, get_google_credentials=_refresh_credentials, **kwargs): """Loads authentication and cluster information from kube-config file and stores them in kubernetes.client.configuration. :param config_file: Name of the kube-config file. :param context: set the active context. If is set to None, current_context from config file will be used. :param client_configuration: The kubernetes.client.ConfigurationObject to set configs to. :param persist_config: If True, config file will be updated when changed (e.g GCP token refresh). """ if config_file is None: config_file = os.path.expanduser( kube_config.KUBE_CONFIG_DEFAULT_LOCATION) config_persister = None if persist_config: def _save_kube_config(config_map): with open(config_file, 'w') as f: yaml.safe_dump(config_map, f, default_flow_style=False) config_persister = _save_kube_config kube_config._get_kube_config_loader_for_yaml_file( # pylint: disable=protected-access config_file, active_context=context, client_configuration=client_configuration, config_persister=config_persister, get_google_credentials=get_google_credentials, **kwargs).load_and_set()