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

Commit 8a3bdb8

Browse files
committed
take care of empty kube_config files
1 parent b002110 commit 8a3bdb8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

config/kube_config.py

+8
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,9 @@ def _load_config_from_file_like_object(self, string):
682682
else:
683683
config = yaml.safe_load(string.read())
684684

685+
if config is None:
686+
raise ConfigException(
687+
'Invalid kube-config.')
685688
if self.config_merged is None:
686689
self.config_merged = copy.deepcopy(config)
687690
# doesn't need to do any further merging
@@ -699,6 +702,11 @@ def load_config(self, path):
699702
with open(path) as f:
700703
config = yaml.safe_load(f)
701704

705+
if config is None:
706+
raise ConfigException(
707+
'Invalid kube-config. '
708+
'%s file is empty' % path)
709+
702710
if self.config_merged is None:
703711
config_merged = copy.deepcopy(config)
704712
for item in ('clusters', 'contexts', 'users'):

config/kube_config_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,15 @@ def test_load_kube_config_from_dict(self):
12901290
client_configuration=actual)
12911291
self.assertEqual(expected, actual)
12921292

1293+
def test_load_kube_config_from_empty_file(self):
1294+
config_file_like_object = io.StringIO()
1295+
self.assertRaises(ConfigException, load_kube_config, config_file_like_object)
1296+
1297+
def test_load_kube_config_from_empty_file_like_object(self):
1298+
config_file = self._create_temp_file(
1299+
yaml.safe_dump(None))
1300+
self.assertRaises(ConfigException, load_kube_config, config_file)
1301+
12931302
def test_list_kube_config_contexts(self):
12941303
config_file = self._create_temp_file(
12951304
yaml.safe_dump(self.TEST_KUBE_CONFIG))

0 commit comments

Comments
 (0)