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

Commit

Permalink
Merge pull request #198 from ACXLM/fix/load-kube-config
Browse files Browse the repository at this point in the history
fix cfg is none, load kube config error
  • Loading branch information
k8s-ci-robot committed Jun 25, 2020
2 parents 70d6639 + 30d9e2a commit 3ea8003
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
3 changes: 1 addition & 2 deletions config/kube_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,8 @@ def load_config(self, path):
for item in ('clusters', 'contexts', 'users'):
config_merged[item] = []
self.config_merged = ConfigNode(path, config_merged, path)

for item in ('clusters', 'contexts', 'users'):
self._merge(item, config.get(item, {}), path)
self._merge(item, config.get(item, []) or [], path)
self.config_files[path] = config

def _merge(self, item, add_cfg, path):
Expand Down
25 changes: 23 additions & 2 deletions config/kube_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ def test__get_kube_config_loader_for_yaml_file_persist(self):
actual = _get_kube_config_loader_for_yaml_file(config_file,
persist_config=True)
self.assertTrue(callable(actual._config_persister))
self.assertEquals(actual._config_persister.__name__, "save_changes")
self.assertEqual(actual._config_persister.__name__, "save_changes")

def test__get_kube_config_loader_file_no_persist(self):
expected = FakeConfig(host=TEST_HOST,
Expand Down Expand Up @@ -1553,6 +1553,26 @@ class TestKubeConfigMerger(BaseTestCase):
}
]
}
TEST_KUBE_CONFIG_PART6 = {
"current-context": "no_user",
"contexts": [
{
"name": "no_user",
"context": {
"cluster": "default"
}
},
],
"clusters": [
{
"name": "default",
"cluster": {
"server": TEST_HOST
}
},
],
"users": None
}

def _create_multi_config(self):
files = []
Expand All @@ -1561,7 +1581,8 @@ def _create_multi_config(self):
self.TEST_KUBE_CONFIG_PART2,
self.TEST_KUBE_CONFIG_PART3,
self.TEST_KUBE_CONFIG_PART4,
self.TEST_KUBE_CONFIG_PART5):
self.TEST_KUBE_CONFIG_PART5,
self.TEST_KUBE_CONFIG_PART6):
files.append(self._create_temp_file(yaml.safe_dump(part)))
return ENV_KUBECONFIG_PATH_SEPARATOR.join(files)

Expand Down

0 comments on commit 3ea8003

Please sign in to comment.