Skip to content

Commit

Permalink
Add Support for creating user entries with alias flag
Browse files Browse the repository at this point in the history
Resolves: aws#5164
  • Loading branch information
elijah-roberts authored and elysahall committed Apr 5, 2023
1 parent 3a8ba23 commit 7ff9e09
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/enhancement-eks-48703.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "enhancement",
"category": "eks",
"description": "Add user-alias argument to update-kubeconfig command. Implements `#5164 <https://github.com/aws/aws-cli/issues/5164>`__"
}
12 changes: 9 additions & 3 deletions awscli/customizations/eks/update_kubeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class UpdateKubeconfigCommand(BasicCommand):
'help_text': ("Alias for the cluster context name. "
"Defaults to match cluster ARN."),
'required': False
},
{
'name': 'user-alias',
'help_text': ("Alias for the generated user name. "
"Defaults to match cluster ARN."),
'required': False
}
]

Expand All @@ -117,7 +123,7 @@ def _run_main(self, parsed_args, parsed_globals):
parsed_args.role_arn,
parsed_globals)
new_cluster_dict = client.get_cluster_entry()
new_user_dict = client.get_user_entry()
new_user_dict = client.get_user_entry(user_alias=parsed_args.user_alias)

config_selector = KubeconfigSelector(
os.environ.get("KUBECONFIG", ""),
Expand Down Expand Up @@ -283,7 +289,7 @@ def get_cluster_entry(self):
("name", arn)
])

def get_user_entry(self):
def get_user_entry(self, user_alias=None):
"""
Return a user entry generated using
the previously obtained description.
Expand All @@ -301,7 +307,7 @@ def get_user_entry(self):
cluster_identification_value = cluster_description.get("id")

generated_user = OrderedDict([
("name", self._get_cluster_description().get("arn", "")),
("name", user_alias or self._get_cluster_description().get("arn", "")),
("user", OrderedDict([
("exec", OrderedDict([
("apiVersion", API_VERSION),
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/customizations/eks/test_update_kubeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,20 @@ def test_profile(self):
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"),
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_without_alias(self):
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")

0 comments on commit 7ff9e09

Please sign in to comment.