Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit 8b306c0

Browse files
committed
add a new method of config.kube_config.new_client_from_config_dict
Signed-off-by: WalkerWang731 <[email protected]>
1 parent 3aa8b4c commit 8b306c0

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .incluster_config import load_incluster_config
1919
from .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

2424
def load_config(**kwargs):

config/kube_config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

config/kube_config_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
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

4242
BEARER_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()

0 commit comments

Comments
 (0)