Skip to content

Commit 7adf7e2

Browse files
author
Sergi Almacellas Abellana
committed
Use no user when the users section is missing in kubeconfig
Fixes kubernetes-client/python#236
1 parent 7c8e59b commit 7adf7e2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: config/kube_config.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ def set_active_context(self, context_name=None):
130130
context_name = self._config['current-context']
131131
self._current_context = self._config['contexts'].get_with_name(
132132
context_name)
133-
if self._current_context['context'].safe_get('user'):
133+
if (self._current_context['context'].safe_get('user')
134+
and self._config.safe_get('users')):
134135
self._user = self._config['users'].get_with_name(
135136
self._current_context['context']['user'])['user']
136137
else:

Diff for: config/kube_config_test.py

+11
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,17 @@ def test_new_client_from_config(self):
615615
self.assertEqual(BEARER_TOKEN_FORMAT % TEST_DATA_BASE64,
616616
client.config.api_key['authorization'])
617617

618+
def test_no_users_section(self):
619+
expected = FakeConfig(host=TEST_HOST)
620+
actual = FakeConfig()
621+
test_kube_config = self.TEST_KUBE_CONFIG.copy()
622+
del test_kube_config['users']
623+
KubeConfigLoader(
624+
config_dict=test_kube_config,
625+
active_context="gcp",
626+
client_configuration=actual).load_and_set()
627+
self.assertEqual(expected, actual)
628+
618629

619630
if __name__ == '__main__':
620631
unittest.main()

0 commit comments

Comments
 (0)