Repository: aws/aws-cli

Issue:
EKS update-config should support naming the user with the passed in alias 
**Is your feature request related to a problem? Please describe.**
I have multiple aws role to k8s role mappings per cluster. The eks update-config command supports setting the `AWS_PROFILE` variable under the user config if you pass in `--profile`. However, it defaults the username to the cluster arn, so if I do this with multiple roles it gets overwritten  

**Describe the solution you'd like**
There is already precedent for overriding the context name by passing an `--alias`. If I run the following:
`aws eks update-kubeconfig --name <clustername> --alias prod-admin --profile prod-admin-role` 

AND

`aws eks update-kubeconfig --name <clustername> --alias prod-support --profile prod-support-role` 

I would like for the following config to be created:

```
- context:
    cluster: arn:aws:eks:us-west-2:redacted:cluster/prod-cluster
    user: prod-admin
  name: prod-admin
- context:
    cluster: arn:aws:eks:us-west-2:redacted:cluster/prod-cluster
    user: prod-support
  name: prod-support
kind: Config
preferences: {}
users:
- name: prod-admin
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - --region
      - us-west-2
      - eks
      - get-token
      - --cluster-name
      - prod-cluster
      command: aws
      env:
      - name: AWS_PROFILE
        value: prod-admin-role
- name: prod-support
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - --region
      - us-west-2
      - eks
      - get-token
      - --cluster-name
      - prod-cluster
      command: aws
      env:
      - name: AWS_PROFILE
        value: prod-support-role
```

This will allow me to simply run a command to loop through all my roles, list eks-clusters, and define contexts for each cluster and role.


**Describe alternatives you've considered**
I could create a separate utility to do this, but honestly even forking this repo and making the small change would be easier. 


**Additional context**

I have this working locally, and it is a 2 line change to match existing functionality with context naming.  




Discussion:
Here is an example loop command for setting up your kube config: 
```
for profile in $(cat ~/.aws/credentials | grep '\[' | column -t -s '[]');
 do for cluster in $(aws eks list-clusters --profile $profile --output text | awk '{ print $2 }'); 
do aws eks update-kubeconfig --name $cluster --profile $profile --alias $(<add sed/awk logic here for parsing cluster and profile names to create alias>) 
;done 
; done
```

Resolving patch:
diff --git a/awscli/customizations/eks/update_kubeconfig.py b/awscli/customizations/eks/update_kubeconfig.py
--- a/awscli/customizations/eks/update_kubeconfig.py
+++ b/awscli/customizations/eks/update_kubeconfig.py
@@ -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
         }
     ]
 
@@ -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", ""),
@@ -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.
@@ -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),


Test patch:
diff --git a/tests/unit/customizations/eks/test_update_kubeconfig.py b/tests/unit/customizations/eks/test_update_kubeconfig.py
--- a/tests/unit/customizations/eks/test_update_kubeconfig.py
+++ b/tests/unit/customizations/eks/test_update_kubeconfig.py
@@ -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")