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

Commit 04feb9f

Browse files
authored
Merge pull request #223 from MridulS/empty_file_error
raise exception when an empty config file is passed to load_kube_config
2 parents 6e2e494 + 3c71987 commit 04feb9f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-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

+15
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,21 @@ 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_like_object(self):
1294+
config_file_like_object = io.StringIO()
1295+
self.assertRaises(
1296+
ConfigException,
1297+
load_kube_config,
1298+
config_file_like_object)
1299+
1300+
def test_load_kube_config_from_empty_file(self):
1301+
config_file = self._create_temp_file(
1302+
yaml.safe_dump(None))
1303+
self.assertRaises(
1304+
ConfigException,
1305+
load_kube_config,
1306+
config_file)
1307+
12931308
def test_list_kube_config_contexts(self):
12941309
config_file = self._create_temp_file(
12951310
yaml.safe_dump(self.TEST_KUBE_CONFIG))

0 commit comments

Comments
 (0)