Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

populate cluster config from client.authentication.k8s.io/exec extension #2396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion 6 kubernetes/base/config/exec_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, exec_config, cwd, cluster=None):
else:
self.cluster = None
self.cwd = cwd or None

@property
def shell(self):
# for windows systems `shell` should be `True`
Expand All @@ -81,6 +81,10 @@ def run(self, previous_response=None):
kubernetes_exec_info['spec']['response'] = previous_response
if self.cluster:
kubernetes_exec_info['spec']['cluster'] = self.cluster.value
for extension in self.cluster.value["extensions"]:
if extension["name"] == "client.authentication.k8s.io/exec":
kubernetes_exec_info["spec"]["cluster"]["config"] = extension["extension"]
break

self.env['KUBERNETES_EXEC_INFO'] = json.dumps(kubernetes_exec_info)
process = subprocess.Popen(
Expand Down
33 changes: 33 additions & 0 deletions 33 kubernetes/base/config/exec_provider_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,39 @@ def test_with_cluster_info(self, mock):
obj = json.loads(mock.call_args.kwargs['env']['KUBERNETES_EXEC_INFO'])
self.assertEqual(obj['spec']['cluster']['server'], 'name.company.com')

@mock.patch("subprocess.Popen")
def test_with_cluster_info_from_exec_extension(self, mock):
instance = mock.return_value
instance.wait.return_value = 0
instance.communicate.return_value = (self.output_ok, "")
ep = ExecProvider(
self.input_with_cluster,
None,
ConfigNode(
"cluster",
{
"server": "name.company.com",
"extensions": [
{
"name": "client.authentication.k8s.io/exec",
"extension": {
"namespace": "myproject",
"name": "mycluster",
},
},
],
},
),
)
result = ep.run()
self.assertTrue(isinstance(result, dict))
self.assertTrue("token" in result)

obj = json.loads(mock.call_args.kwargs["env"]["KUBERNETES_EXEC_INFO"])
self.assertEqual(obj["spec"]["cluster"]["server"], "name.company.com")
self.assertEqual(obj["spec"]["cluster"]["config"]["namespace"], "myproject")
self.assertEqual(obj["spec"]["cluster"]["config"]["name"], "mycluster")


if __name__ == '__main__':
unittest.main()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.