Merge pull request #223 from MridulS/empty_file_error

raise exception when an empty config file is passed to load_kube_config
This commit is contained in:
Kubernetes Prow Robot 2021-02-09 09:26:22 -08:00 committed by GitHub
commit 04feb9ff90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -682,6 +682,9 @@ class KubeConfigMerger:
else:
config = yaml.safe_load(string.read())
if config is None:
raise ConfigException(
'Invalid kube-config.')
if self.config_merged is None:
self.config_merged = copy.deepcopy(config)
# doesn't need to do any further merging
@ -699,6 +702,11 @@ class KubeConfigMerger:
with open(path) as f:
config = yaml.safe_load(f)
if config is None:
raise ConfigException(
'Invalid kube-config. '
'%s file is empty' % path)
if self.config_merged is None:
config_merged = copy.deepcopy(config)
for item in ('clusters', 'contexts', 'users'):

View File

@ -1290,6 +1290,21 @@ class TestKubeConfigLoader(BaseTestCase):
client_configuration=actual)
self.assertEqual(expected, actual)
def test_load_kube_config_from_empty_file_like_object(self):
config_file_like_object = io.StringIO()
self.assertRaises(
ConfigException,
load_kube_config,
config_file_like_object)
def test_load_kube_config_from_empty_file(self):
config_file = self._create_temp_file(
yaml.safe_dump(None))
self.assertRaises(
ConfigException,
load_kube_config,
config_file)
def test_list_kube_config_contexts(self):
config_file = self._create_temp_file(
yaml.safe_dump(self.TEST_KUBE_CONFIG))