23
23
import urllib3
24
24
import yaml
25
25
26
- from kubernetes .client import ApiClient , ConfigurationObject , configuration
26
+ from kubernetes .client import ApiClient , Configuration
27
27
28
28
from .config_exception import ConfigException
29
29
from .dateutil import UTC , format_rfc3339 , parse_rfc3339
@@ -118,7 +118,6 @@ class KubeConfigLoader(object):
118
118
119
119
def __init__ (self , config_dict , active_context = None ,
120
120
get_google_credentials = None ,
121
- client_configuration = configuration ,
122
121
config_base_path = "" ,
123
122
config_persister = None ):
124
123
self ._config = ConfigNode ('kube-config' , config_dict )
@@ -139,7 +138,6 @@ def _refresh_credentials():
139
138
self ._get_google_credentials = get_google_credentials
140
139
else :
141
140
self ._get_google_credentials = _refresh_credentials
142
- self ._client_configuration = client_configuration
143
141
144
142
def set_active_context (self , context_name = None ):
145
143
if context_name is None :
@@ -240,19 +238,19 @@ def _load_cluster_info(self):
240
238
if 'insecure-skip-tls-verify' in self ._cluster :
241
239
self .verify_ssl = not self ._cluster ['insecure-skip-tls-verify' ]
242
240
243
- def _set_config (self ):
241
+ def _set_config (self , client_configuration ):
244
242
if 'token' in self .__dict__ :
245
- self . _client_configuration .api_key ['authorization' ] = self .token
243
+ client_configuration .api_key ['authorization' ] = self .token
246
244
# copy these keys directly from self to configuration object
247
245
keys = ['host' , 'ssl_ca_cert' , 'cert_file' , 'key_file' , 'verify_ssl' ]
248
246
for key in keys :
249
247
if key in self .__dict__ :
250
- setattr (self . _client_configuration , key , getattr (self , key ))
248
+ setattr (client_configuration , key , getattr (self , key ))
251
249
252
- def load_and_set (self ):
250
+ def load_and_set (self , client_configuration ):
253
251
self ._load_authentication ()
254
252
self ._load_cluster_info ()
255
- self ._set_config ()
253
+ self ._set_config (client_configuration )
256
254
257
255
def list_contexts (self ):
258
256
return [context .value for context in self ._config ['contexts' ]]
@@ -331,15 +329,15 @@ def list_kube_config_contexts(config_file=None):
331
329
332
330
333
331
def load_kube_config (config_file = None , context = None ,
334
- client_configuration = configuration ,
332
+ client_configuration = None ,
335
333
persist_config = True ):
336
334
"""Loads authentication and cluster information from kube-config file
337
335
and stores them in kubernetes.client.configuration.
338
336
339
337
:param config_file: Name of the kube-config file.
340
338
:param context: set the active context. If is set to None, current_context
341
339
from config file will be used.
342
- :param client_configuration: The kubernetes.client.ConfigurationObject to
340
+ :param client_configuration: The kubernetes.client.Configuration to
343
341
set configs to.
344
342
:param persist_config: If True, config file will be updated when changed
345
343
(e.g GCP token refresh).
@@ -355,10 +353,15 @@ def _save_kube_config(config_map):
355
353
yaml .safe_dump (config_map , f , default_flow_style = False )
356
354
config_persister = _save_kube_config
357
355
358
- _get_kube_config_loader_for_yaml_file (
356
+ loader = _get_kube_config_loader_for_yaml_file (
359
357
config_file , active_context = context ,
360
- client_configuration = client_configuration ,
361
- config_persister = config_persister ).load_and_set ()
358
+ config_persister = config_persister )
359
+ if client_configuration is None :
360
+ config = Configuration ()
361
+ loader .load_and_set (config )
362
+ Configuration .set_default (config )
363
+ else :
364
+ loader .load_and_set (client_configuration )
362
365
363
366
364
367
def new_client_from_config (
@@ -368,8 +371,8 @@ def new_client_from_config(
368
371
"""Loads configuration the same as load_kube_config but returns an ApiClient
369
372
to be used with any API object. This will allow the caller to concurrently
370
373
talk with multiple clusters."""
371
- client_config = ConfigurationObject ()
374
+ client_config = Configuration ()
372
375
load_kube_config (config_file = config_file , context = context ,
373
376
client_configuration = client_config ,
374
377
persist_config = persist_config )
375
- return ApiClient (config = client_config )
378
+ return ApiClient (configuration = client_config )
0 commit comments