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 1818from .incluster_config import load_incluster_config
1919from .kube_config import (KUBE_CONFIG_DEFAULT_LOCATION ,
2020 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 )
2222
2323
2424def load_config (** kwargs ):
Original file line number Diff line number Diff line change @@ -871,3 +871,21 @@ def new_client_from_config(
871871 client_configuration = client_config ,
872872 persist_config = persist_config )
873873 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 3737 _get_kube_config_loader ,
3838 _get_kube_config_loader_for_yaml_file ,
3939 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 )
4141
4242BEARER_TOKEN_FORMAT = "Bearer %s"
4343
@@ -1351,6 +1351,13 @@ def test_new_client_from_config(self):
13511351 self .assertEqual (BEARER_TOKEN_FORMAT % TEST_DATA_BASE64 ,
13521352 client .configuration .api_key ['authorization' ])
13531353
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+
13541361 def test_no_users_section (self ):
13551362 expected = FakeConfig (host = TEST_HOST )
13561363 actual = FakeConfig ()
You can’t perform that action at this time.
0 commit comments