add a new method of config.kube_config.new_client_from_config_dict
Signed-off-by: WalkerWang731 <wxy1990731@hotmail.com>
This commit is contained in:
parent
3aa8b4c942
commit
8b306c0f57
@ -18,7 +18,7 @@ from .config_exception import ConfigException
|
||||
from .incluster_config import load_incluster_config
|
||||
from .kube_config import (KUBE_CONFIG_DEFAULT_LOCATION,
|
||||
list_kube_config_contexts, load_kube_config,
|
||||
load_kube_config_from_dict, new_client_from_config)
|
||||
load_kube_config_from_dict, new_client_from_config, new_client_from_config_dict)
|
||||
|
||||
|
||||
def load_config(**kwargs):
|
||||
|
||||
@ -871,3 +871,21 @@ def new_client_from_config(
|
||||
client_configuration=client_config,
|
||||
persist_config=persist_config)
|
||||
return ApiClient(configuration=client_config)
|
||||
|
||||
|
||||
def new_client_from_config_dict(
|
||||
config_dict=None,
|
||||
context=None,
|
||||
persist_config=True,
|
||||
temp_file_path=None):
|
||||
"""
|
||||
Loads configuration the same as load_kube_config_from_dict but returns an ApiClient
|
||||
to be used with any API object. This will allow the caller to concurrently
|
||||
talk with multiple clusters.
|
||||
"""
|
||||
client_config = type.__call__(Configuration)
|
||||
load_kube_config_from_dict(config_dict=config_dict, context=context,
|
||||
client_configuration=client_config,
|
||||
persist_config=persist_config,
|
||||
temp_file_path=temp_file_path)
|
||||
return ApiClient(configuration=client_config)
|
||||
|
||||
@ -37,7 +37,7 @@ from .kube_config import (ENV_KUBECONFIG_PATH_SEPARATOR, CommandTokenSource,
|
||||
_get_kube_config_loader,
|
||||
_get_kube_config_loader_for_yaml_file,
|
||||
list_kube_config_contexts, load_kube_config,
|
||||
load_kube_config_from_dict, new_client_from_config)
|
||||
load_kube_config_from_dict, new_client_from_config, new_client_from_config_dict)
|
||||
|
||||
BEARER_TOKEN_FORMAT = "Bearer %s"
|
||||
|
||||
@ -1351,6 +1351,13 @@ class TestKubeConfigLoader(BaseTestCase):
|
||||
self.assertEqual(BEARER_TOKEN_FORMAT % TEST_DATA_BASE64,
|
||||
client.configuration.api_key['authorization'])
|
||||
|
||||
def test_new_client_from_config_dict(self):
|
||||
client = new_client_from_config_dict(
|
||||
config_dict=self.TEST_KUBE_CONFIG, context="simple_token")
|
||||
self.assertEqual(TEST_HOST, client.configuration.host)
|
||||
self.assertEqual(BEARER_TOKEN_FORMAT % TEST_DATA_BASE64,
|
||||
client.configuration.api_key['authorization'])
|
||||
|
||||
def test_no_users_section(self):
|
||||
expected = FakeConfig(host=TEST_HOST)
|
||||
actual = FakeConfig()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user