This repository was archived by the owner on Mar 13, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 18
18
from .incluster_config import load_incluster_config
19
19
from .kube_config import (KUBE_CONFIG_DEFAULT_LOCATION ,
20
20
list_kube_config_contexts , load_kube_config ,
21
- load_kube_config_from_dict , new_client_from_config )
21
+ load_kube_config_from_dict , new_client_from_config , new_client_from_config_dict )
22
22
23
23
24
24
def load_config (** kwargs ):
Original file line number Diff line number Diff line change @@ -871,3 +871,21 @@ def new_client_from_config(
871
871
client_configuration = client_config ,
872
872
persist_config = persist_config )
873
873
return ApiClient (configuration = client_config )
874
+
875
+
876
+ def new_client_from_config_dict (
877
+ config_dict = None ,
878
+ context = None ,
879
+ persist_config = True ,
880
+ temp_file_path = None ):
881
+ """
882
+ Loads configuration the same as load_kube_config_from_dict but returns an ApiClient
883
+ to be used with any API object. This will allow the caller to concurrently
884
+ talk with multiple clusters.
885
+ """
886
+ client_config = type .__call__ (Configuration )
887
+ load_kube_config_from_dict (config_dict = config_dict , context = context ,
888
+ client_configuration = client_config ,
889
+ persist_config = persist_config ,
890
+ temp_file_path = temp_file_path )
891
+ return ApiClient (configuration = client_config )
Original file line number Diff line number Diff line change 37
37
_get_kube_config_loader ,
38
38
_get_kube_config_loader_for_yaml_file ,
39
39
list_kube_config_contexts , load_kube_config ,
40
- load_kube_config_from_dict , new_client_from_config )
40
+ load_kube_config_from_dict , new_client_from_config , new_client_from_config_dict )
41
41
42
42
BEARER_TOKEN_FORMAT = "Bearer %s"
43
43
@@ -1351,6 +1351,13 @@ def test_new_client_from_config(self):
1351
1351
self .assertEqual (BEARER_TOKEN_FORMAT % TEST_DATA_BASE64 ,
1352
1352
client .configuration .api_key ['authorization' ])
1353
1353
1354
+ def test_new_client_from_config_dict (self ):
1355
+ client = new_client_from_config_dict (
1356
+ config_dict = self .TEST_KUBE_CONFIG , context = "simple_token" )
1357
+ self .assertEqual (TEST_HOST , client .configuration .host )
1358
+ self .assertEqual (BEARER_TOKEN_FORMAT % TEST_DATA_BASE64 ,
1359
+ client .configuration .api_key ['authorization' ])
1360
+
1354
1361
def test_no_users_section (self ):
1355
1362
expected = FakeConfig (host = TEST_HOST )
1356
1363
actual = FakeConfig ()
You can’t perform that action at this time.
0 commit comments