diff --git a/.changes/next-release/enhancement-eks-73766.json b/.changes/next-release/enhancement-eks-73766.json new file mode 100644 index 000000000000..fc794502ab5f --- /dev/null +++ b/.changes/next-release/enhancement-eks-73766.json @@ -0,0 +1,5 @@ +{ + "type": "enhancement", + "category": "eks", + "description": "Add exec-profile argument to update-kubeconfig command. Fixes `#9759 `__" +} diff --git a/awscli/customizations/eks/update_kubeconfig.py b/awscli/customizations/eks/update_kubeconfig.py index 72157594ad07..b4a72bd87937 100644 --- a/awscli/customizations/eks/update_kubeconfig.py +++ b/awscli/customizations/eks/update_kubeconfig.py @@ -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, ' @@ -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 diff --git a/tests/unit/customizations/eks/test_update_kubeconfig.py b/tests/unit/customizations/eks/test_update_kubeconfig.py index ecfae4e9395d..cc1750bf1185 100644 --- a/tests/unit/customizations/eks/test_update_kubeconfig.py +++ b/tests/unit/customizations/eks/test_update_kubeconfig.py @@ -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"),