renaming functions and setting to internal

This commit is contained in:
Dylan Shepard 2020-08-31 12:01:11 -07:00
parent aac4e35ca9
commit f85a41fa31
No known key found for this signature in database
GPG Key ID: F8150643D5643467
2 changed files with 18 additions and 15 deletions

View File

@ -669,21 +669,15 @@ class KubeConfigMerger:
self.config_files = {}
self.config_merged = None
if hasattr(paths, 'read'):
self.load_config_from_fileish(paths)
self._load_config_from_file_like_object(paths)
else:
for path in paths.split(ENV_KUBECONFIG_PATH_SEPARATOR):
if path:
path = os.path.expanduser(path)
if os.path.exists(path):
self.paths.append(path)
self.load_config(path)
self.config_saved = copy.deepcopy(self.config_files)
self._load_config_from_file_path(paths)
@property
def config(self):
return self.config_merged
def load_config_from_fileish(self, string):
def _load_config_from_file_like_object(self, string):
if hasattr(string, 'getvalue'):
config = yaml.safe_load(string.getvalue())
else:
@ -693,6 +687,15 @@ class KubeConfigMerger:
self.config_merged = copy.deepcopy(config)
# doesn't need to do any further merging
def _load_config_from_file_path(self, string):
for path in string.split(ENV_KUBECONFIG_PATH_SEPARATOR):
if path:
path = os.path.expanduser(path)
if os.path.exists(path):
self.paths.append(path)
self.load_config(path)
self.config_saved = copy.deepcopy(self.config_files)
def load_config(self, path):
with open(path) as f:
config = yaml.safe_load(f)

View File

@ -1248,7 +1248,7 @@ class TestKubeConfigLoader(BaseTestCase):
finally:
shutil.rmtree(temp_dir)
def test_load_kube_config(self):
def test_load_kube_config_from_file_path(self):
expected = FakeConfig(host=TEST_HOST,
token=BEARER_TOKEN_FORMAT % TEST_DATA_BASE64)
config_file = self._create_temp_file(
@ -1258,19 +1258,19 @@ class TestKubeConfigLoader(BaseTestCase):
client_configuration=actual)
self.assertEqual(expected, actual)
def test_load_kube_config_from_fileish(self):
def test_load_kube_config_from_file_like_object(self):
expected = FakeConfig(host=TEST_HOST,
token=BEARER_TOKEN_FORMAT % TEST_DATA_BASE64)
config_fileish = io.StringIO()
config_fileish.write(yaml.safe_dump(self.TEST_KUBE_CONFIG))
config_file_like_object = io.StringIO()
config_file_like_object.write(yaml.safe_dump(self.TEST_KUBE_CONFIG))
actual = FakeConfig()
load_kube_config(config_file=config_fileish, context="simple_token", client_configuration=actual)
load_kube_config(config_file=config_file_like_object, context="simple_token",
client_configuration=actual)
self.assertEqual(expected, actual)
def test_load_kube_config_from_dict(self):
expected = FakeConfig(host=TEST_HOST,
token=BEARER_TOKEN_FORMAT % TEST_DATA_BASE64)
actual = FakeConfig()
load_kube_config_from_dict(config_dict=self.TEST_KUBE_CONFIG,
context="simple_token",