Skip to content

Commit 1bb30b4

Browse files
authored
Add proxy-url option to eks update-kubeconfig (#9762)
1 parent d0dba24 commit 1bb30b4

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "enhancement",
3+
"category": "``eks``",
4+
"description": "Add ``proxy-url`` to ``aws eks update-kubeconfig``"
5+
}

awscli/customizations/eks/update_kubeconfig.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ class UpdateKubeconfigCommand(BasicCommand):
8383
),
8484
'required': False,
8585
},
86+
{
87+
'name': 'proxy-url',
88+
'help_text': (
89+
"Optionally specify a proxy url to route "
90+
"traffic via when connecting to a cluster."
91+
),
92+
'required': False,
93+
},
8694
{
8795
'name': 'dry-run',
8896
'action': 'store_true',
@@ -172,15 +180,11 @@ def _run_main(self, parsed_args, parsed_globals):
172180

173181
if updating_existing:
174182
uni_print(
175-
"Updated context {0} in {1}\n".format(
176-
new_context_dict["name"], config.path
177-
)
183+
f"Updated context {new_context_dict['name']} in {config.path}\n"
178184
)
179185
else:
180186
uni_print(
181-
"Added new context {0} to {1}\n".format(
182-
new_context_dict["name"], config.path
183-
)
187+
f"Added new context {new_context_dict['name']} to {config.path}\n"
184188
)
185189

186190
if parsed_args.verbose:
@@ -327,7 +331,7 @@ def get_cluster_entry(self):
327331
endpoint = self.cluster_description.get("endpoint")
328332
arn = self.cluster_description.get("arn")
329333

330-
return OrderedDict(
334+
generated_cluster = OrderedDict(
331335
[
332336
(
333337
"cluster",
@@ -342,6 +346,13 @@ def get_cluster_entry(self):
342346
]
343347
)
344348

349+
if self._parsed_args.proxy_url is not None:
350+
generated_cluster["cluster"]["proxy-url"] = (
351+
self._parsed_args.proxy_url
352+
)
353+
354+
return generated_cluster
355+
345356
def get_user_entry(self, user_alias=None):
346357
"""
347358
Return a user entry generated using

tests/unit/customizations/eks/test_update_kubeconfig.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def setUp(self):
282282
self._client = EKSClient(
283283
self._session,
284284
parsed_args=Namespace(
285-
cluster_name="ExampleCluster", role_arn=None
285+
cluster_name="ExampleCluster", role_arn=None, proxy_url=None
286286
),
287287
)
288288

@@ -316,6 +316,49 @@ def test_get_cluster_entry(self):
316316
)
317317
self._session.create_client.assert_called_once_with("eks")
318318

319+
def test_get_cluster_entry_with_proxy_url_passed(self):
320+
proxy_url = "https://myproxy.com"
321+
correct_cluster_entry_with_proxy_url = OrderedDict(
322+
[
323+
(
324+
"cluster",
325+
OrderedDict(
326+
[
327+
(
328+
"certificate-authority-data",
329+
describe_cluster_response()["cluster"][
330+
"certificateAuthority"
331+
]["data"],
332+
),
333+
(
334+
"server",
335+
describe_cluster_response()["cluster"][
336+
"endpoint"
337+
],
338+
),
339+
("proxy-url", proxy_url),
340+
]
341+
),
342+
),
343+
("name", describe_cluster_response()["cluster"]["arn"]),
344+
]
345+
)
346+
client = EKSClient(
347+
self._session,
348+
parsed_args=Namespace(
349+
cluster_name="ProxiedCluster",
350+
role_arn=None,
351+
proxy_url=proxy_url,
352+
),
353+
)
354+
self.assertEqual(
355+
client.get_cluster_entry(), correct_cluster_entry_with_proxy_url
356+
)
357+
self._mock_client.describe_cluster.assert_called_once_with(
358+
name="ProxiedCluster"
359+
)
360+
self._session.create_client.assert_called_once_with("eks")
361+
319362
def test_get_user_entry(self):
320363
self.assertEqual(
321364
self._client.get_user_entry(), self._correct_user_entry

0 commit comments

Comments
 (0)