kubernetes.aio.config.kube_config module

class kubernetes.aio.config.kube_config.ConfigNode(name, value, path=None)

Bases: object

Remembers each config key’s path and construct a relevant exception message in case of missing keys. The assumption is all access keys are present in a well-formed kube-config.

get_with_name(name, safe=False)
safe_get(key)
class kubernetes.aio.config.kube_config.FileOrData(obj, file_key_name, data_key_name=None, file_base_path='', base64_file_content=True, temp_file_path=None)

Bases: object

Utility class to read content of obj[%data_key_name] or file’s content of obj[%file_key_name] and represent it as file or data. Note that the data is preferred. The obj[%file_key_name] will be used iff obj[‘%data_key_name’] is not set or empty. Assumption is file content is raw data and data field is base64 string. The assumption can be changed with base64_file_content flag. If set to False, the content of the file will assumed to be base64 and read as is. The default True value will result in base64 encode of the file content after read.

as_data()

If obj[%data_key_name] exists, Return obj[%data_key_name] otherwise base64 encoded string of obj[%file_key_name] file content.

as_file()

If obj[%data_key_name] exists, return name of a file with base64 decoded obj[%data_key_name] content otherwise obj[%file_key_name].

class kubernetes.aio.config.kube_config.KubeConfigLoader(config_dict, active_context=None, get_google_credentials=None, config_base_path='', config_persister=None, temp_file_path=None)

Bases: object

property current_context
list_contexts()
async load_and_set(client_configuration)
async load_from_exec_plugin()
async load_gcp_token()
set_active_context(context_name=None)
class kubernetes.aio.config.kube_config.KubeConfigMerger(paths)

Bases: object

Reads and merges configuration from one or more kube-config’s. The propery config can be passed to the KubeConfigLoader as config_dict. It uses a path attribute from ConfigNode to store the path to kubeconfig. This path is required to load certs from relative paths. A method save_changes updates changed kubeconfig’s (it compares current state of dicts with).

property config
load_config(path)
save_changes()
save_config(path)
kubernetes.aio.config.kube_config.list_kube_config_contexts(config_file=None)
async kubernetes.aio.config.kube_config.load_kube_config(config_file=None, context=None, client_configuration=None, persist_config=True, temp_file_path=None)

Loads authentication and cluster information from kube-config file and stores them in kubernetes.client.configuration.

Parameters:
  • config_file – Name of the kube-config file.

  • context – set the active context. If is set to None, current_context from config file will be used.

  • client_configuration – The kubernetes.client.Configuration to set configs to.

  • persist_config – If True, config file will be updated when changed (e.g GCP token refresh).

  • temp_file_path – directory where temp files are stored (default - system temp dir).

async kubernetes.aio.config.kube_config.load_kube_config_from_dict(config_dict, context=None, client_configuration=None, temp_file_path=None)

Loads authentication and cluster information from config_dict and stores them in kubernetes.client.configuration.

Parameters:
  • config_dict – Takes the config file as a dict.

  • context – set the active context. If is set to None, current_context from config file will be used.

  • client_configuration – The kubernetes.aio.client.Configuration to set configs to.

  • temp_file_path – directory where temp files are stored (default - system temp dir).

async kubernetes.aio.config.kube_config.new_client_from_config(config_file=None, context=None, persist_config=True, temp_file_path=None)

Loads configuration the same as load_kube_config but returns an ApiClient to be used with any API object. This will allow the caller to concurrently talk with multiple clusters.

async kubernetes.aio.config.kube_config.new_client_from_config_dict(config_dict=None, context=None, temp_file_path=None)

Loads configuration the same as load_kube_config_dict but returns an ApiClient to be used with any API object. This will allow the caller to concurrently talk with multiple clusters.

async kubernetes.aio.config.kube_config.refresh_token(loader, client_configuration=None, interval=60)

Refresh token if necessary, updates the token in client configurarion

Parameters:
  • loader – KubeConfigLoader returned by load_kube_config

  • client_configuration – The kubernetes.client.Configuration to set configs to.

  • interval – how often check if token is up-to-date