Skip to content
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
5 changes: 5 additions & 0 deletions .changes/next-release/enhancement-eks-73766.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "enhancement",
"category": "eks",
"description": "Add exec-profile argument to update-kubeconfig command. Fixes `#9759 <https://github.com/aws/aws-cli/issues/9759>`__"
}
12 changes: 10 additions & 2 deletions awscli/customizations/eks/update_kubeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ class UpdateKubeconfigCommand(BasicCommand):
"Defaults to match cluster ARN."),
'required': False
},
{
'name': 'exec-profile',
'help_text': ("Profile to use when getting the access token "
"or assuming the role specified in --role-arn. "
"This overrides the current session profile, which "
"will otherwise be used."),
'required': False
},
{
'name': 'assume-role-arn',
'help_text': ('To assume a role for retrieving cluster information, '
Expand Down Expand Up @@ -356,10 +364,10 @@ def get_user_entry(self, user_alias=None):
self._parsed_args.role_arn
])

if self._session.profile:
if self._session.profile or getattr(self._parsed_args, 'exec_profile', None):
generated_user["user"]["exec"]["env"] = [OrderedDict([
("name", "AWS_PROFILE"),
("value", self._session.profile)
("value", getattr(self._parsed_args, 'exec_profile', None) or self._session.profile)
])]

return generated_user
16 changes: 16 additions & 0 deletions tests/unit/customizations/eks/test_update_kubeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,22 @@ def test_profile(self):
)
self._session.create_client.assert_called_once_with("eks")

def test_exec_profile(self):
self._session.profile = "session-profile"
self._client = EKSClient(self._session, parsed_args=Namespace(cluster_name="ExampleCluster", role_arn=None, exec_profile="exec-profile"))
self._correct_user_entry["user"]["exec"]["env"] = [
OrderedDict([
("name", "AWS_PROFILE"),
("value", "exec-profile")
])
]
self.assertEqual(self._client.get_user_entry(),
self._correct_user_entry)
self._mock_client.describe_cluster.assert_called_once_with(
name="ExampleCluster"
)
self._session.create_client.assert_called_once_with("eks")

def test_create_user_with_alias(self):
self._correct_user_entry["name"] = "alias"
self.assertEqual(self._client.get_user_entry(user_alias="alias"),
Expand Down