MCPcopy Create free account
hub / github.com/kubernetes-client/python / __init__

Method __init__

kubernetes/base/config/kube_config.py:194–264  ·  view source on GitHub ↗
(self, config_dict, active_context=None,
                 get_google_credentials=None,
                 config_base_path="",
                 config_persister=None,
                 temp_file_path=None)

Source from the content-addressed store, hash-verified

192class KubeConfigLoader:
193
194 def __init__(self, config_dict, active_context=None,
195 get_google_credentials=None,
196 config_base_path="",
197 config_persister=None,
198 temp_file_path=None):
199
200 if config_dict is None:
201 raise ConfigException(
202 'Invalid kube-config. '
203 'Expected config_dict to not be None.')
204 elif isinstance(config_dict, ConfigNode):
205 self._config = config_dict
206 else:
207 self._config = ConfigNode('kube-config', config_dict)
208
209 self._current_context = None
210 self._user = None
211 self._cluster = None
212 self.set_active_context(active_context)
213 self._config_base_path = config_base_path
214 self._config_persister = config_persister
215 self._temp_file_path = temp_file_path
216
217 def _refresh_credentials_with_cmd_path():
218 config = self._user['auth-provider']['config']
219 cmd = config['cmd-path']
220 if len(cmd) == 0:
221 raise ConfigException(
222 'missing access token cmd '
223 '(cmd-path is an empty string in your kubeconfig file)')
224 if 'scopes' in config and config['scopes'] != "":
225 raise ConfigException(
226 'scopes can only be used '
227 'when kubectl is using a gcp service account key')
228 args = []
229 if 'cmd-args' in config:
230 args = config['cmd-args'].split()
231 else:
232 fields = config['cmd-path'].split()
233 cmd = fields[0]
234 args = fields[1:]
235
236 commandTokenSource = CommandTokenSource(
237 cmd, args,
238 config.safe_get('token-key'),
239 config.safe_get('expiry-key'))
240 return commandTokenSource.token()
241
242 def _refresh_credentials():
243 # Refresh credentials using cmd-path
244 if ('auth-provider' in self._user and
245 'config' in self._user['auth-provider'] and
246 'cmd-path' in self._user['auth-provider']['config']):
247 return _refresh_credentials_with_cmd_path()
248
249 # Make the Google auth block optional.
250 if google_auth_available:
251 credentials, project_id = google.auth.default(scopes=[

Callers

nothing calls this directly

Calls 3

set_active_contextMethod · 0.95
ConfigExceptionClass · 0.70
ConfigNodeClass · 0.70

Tested by

no test coverage detected