Use no user when the users section is missing in kubeconfig

Fixes kubernetes-incubator/client-python#236
This commit is contained in:
Sergi Almacellas Abellana 2017-06-05 12:47:05 +02:00
parent 7c8e59b58d
commit 7adf7e280d
2 changed files with 13 additions and 1 deletions

View File

@ -130,7 +130,8 @@ class KubeConfigLoader(object):
context_name = self._config['current-context']
self._current_context = self._config['contexts'].get_with_name(
context_name)
if self._current_context['context'].safe_get('user'):
if (self._current_context['context'].safe_get('user')
and self._config.safe_get('users')):
self._user = self._config['users'].get_with_name(
self._current_context['context']['user'])['user']
else:

View File

@ -615,6 +615,17 @@ class TestKubeConfigLoader(BaseTestCase):
self.assertEqual(BEARER_TOKEN_FORMAT % TEST_DATA_BASE64,
client.config.api_key['authorization'])
def test_no_users_section(self):
expected = FakeConfig(host=TEST_HOST)
actual = FakeConfig()
test_kube_config = self.TEST_KUBE_CONFIG.copy()
del test_kube_config['users']
KubeConfigLoader(
config_dict=test_kube_config,
active_context="gcp",
client_configuration=actual).load_and_set()
self.assertEqual(expected, actual)
if __name__ == '__main__':
unittest.main()