Repository: aws/aws-cli

Issue:
`Empty KUBERNETES_EXEC_INFO` warning when running `aws eks get-token`
### Describe the bug

This is likely related to https://github.com/kubernetes/kubectl/issues/1210

Using the newest update contained the in above patch, `kubectl` auth commands run as expected. However any requests to `aws eks get-token` that don't come from `kubectl` itself (or a tool using a similar mechanism) result in the following warning:
```shell
Empty KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1alpha1. This is likely a bug in your Kubernetes client. Please update your Kubernetes client.
```
This might just need some documentation to prevent confusion, but I'm already seeing users run into it and ask. And the usual [reddit suspects](https://www.reddit.com/r/kubernetes/comments/um1wa1/what_is_kubernetes_exec_info_and_why_would_it_be/)

### Expected Behavior

- More detailed warning message? 
- Suppression of warnings when an interactive prompt is detected?
- Documentation notes?

### Current Behavior

`aws eks get-token` (with valid credentials)
Output:
```shell
Empty KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1alpha1. This is likely a bug in your Kubernetes client. Please update your Kubernetes client.
<token>
```

### Reproduction Steps

`aws eks get-token`

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CLI version used

`aws-cli/2.6.3 Python/3.9.12 Darwin/21.4.0 source/arm64 prompt/off`

### Environment details (OS name and version, etc.)

macOS 12.3.1

Discussion:
codecov-commenter: # [Codecov](https://codecov.io/gh/aws/aws-cli/pull/6940?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws) Report
> Merging [#6940](https://codecov.io/gh/aws/aws-cli/pull/6940?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws) (946b014) into [develop](https://codecov.io/gh/aws/aws-cli/commit/d693aede43266c101ed650105d201d712b09d8c6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws) (d693aed) will **decrease** coverage by `0.24%`.
> The diff coverage is `100.00%`.

```diff
@@             Coverage Diff             @@
##           develop    #6940      +/-   ##
===========================================
- Coverage    92.87%   92.62%   -0.25%     
===========================================
  Files          204      204              
  Lines        16347    16179     -168     
===========================================
- Hits         15182    14986     -196     
- Misses        1165     1193      +28     
```


| [Impacted Files](https://codecov.io/gh/aws/aws-cli/pull/6940?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws) | Coverage Δ | |
|---|---|---|
| [awscli/customizations/eks/get\_token.py](https://codecov.io/gh/aws/aws-cli/pull/6940/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws#diff-YXdzY2xpL2N1c3RvbWl6YXRpb25zL2Vrcy9nZXRfdG9rZW4ucHk=) | `100.00% <100.00%> (ø)` | |
| [awscli/compat.py](https://codecov.io/gh/aws/aws-cli/pull/6940/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws#diff-YXdzY2xpL2NvbXBhdC5weQ==) | `48.07% <0.00%> (-7.48%)` | :arrow_down: |
| [awscli/commands.py](https://codecov.io/gh/aws/aws-cli/pull/6940/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws#diff-YXdzY2xpL2NvbW1hbmRzLnB5) | `86.66% <0.00%> (-3.34%)` | :arrow_down: |
| [awscli/testutils.py](https://codecov.io/gh/aws/aws-cli/pull/6940/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws#diff-YXdzY2xpL3Rlc3R1dGlscy5weQ==) | `64.25% <0.00%> (-1.16%)` | :arrow_down: |
| [awscli/customizations/ec2/decryptpassword.py](https://codecov.io/gh/aws/aws-cli/pull/6940/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws#diff-YXdzY2xpL2N1c3RvbWl6YXRpb25zL2VjMi9kZWNyeXB0cGFzc3dvcmQucHk=) | `84.74% <0.00%> (-0.97%)` | :arrow_down: |
| [awscli/help.py](https://codecov.io/gh/aws/aws-cli/pull/6940/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws#diff-YXdzY2xpL2hlbHAucHk=) | `96.19% <0.00%> (-0.81%)` | :arrow_down: |
| [awscli/arguments.py](https://codecov.io/gh/aws/aws-cli/pull/6940/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws#diff-YXdzY2xpL2FyZ3VtZW50cy5weQ==) | `94.23% <0.00%> (-0.77%)` | :arrow_down: |
| [awscli/table.py](https://codecov.io/gh/aws/aws-cli/pull/6940/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws#diff-YXdzY2xpL3RhYmxlLnB5) | `94.31% <0.00%> (-0.76%)` | :arrow_down: |
| [awscli/customizations/ec2/addcount.py](https://codecov.io/gh/aws/aws-cli/pull/6940/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws#diff-YXdzY2xpL2N1c3RvbWl6YXRpb25zL2VjMi9hZGRjb3VudC5weQ==) | `93.33% <0.00%> (-0.67%)` | :arrow_down: |
| [awscli/customizations/codeartifact/login.py](https://codecov.io/gh/aws/aws-cli/pull/6940/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws#diff-YXdzY2xpL2N1c3RvbWl6YXRpb25zL2NvZGVhcnRpZmFjdC9sb2dpbi5weQ==) | `97.42% <0.00%> (-0.42%)` | :arrow_down: |
| ... and [21 more](https://codecov.io/gh/aws/aws-cli/pull/6940/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/aws/aws-cli/pull/6940?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/aws/aws-cli/pull/6940?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws). Last update [d693aed...946b014](https://codecov.io/gh/aws/aws-cli/pull/6940?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws).


Patch:
diff --git a/.changes/next-release/bugfix-eks-27483.json b/.changes/next-release/bugfix-eks-27483.json
new file mode 100644
index 000000000..0d7b2c4c4
--- /dev/null
+++ b/.changes/next-release/bugfix-eks-27483.json
@@ -0,0 +1,5 @@
+{
+  "type": "bugfix",
+  "category": "``eks get-token``",
+  "description": "Correctly fallback to client.authentication.k8s.io/v1beta1 API if KUBERNETES_EXEC_INFO is undefined"
+}
diff --git a/.changes/next-release/feature-eksgettoken-97938.json b/.changes/next-release/feature-eksgettoken-97938.json
new file mode 100644
index 000000000..618d5cdb9
--- /dev/null
+++ b/.changes/next-release/feature-eksgettoken-97938.json
@@ -0,0 +1,5 @@
+{
+  "type": "feature",
+  "category": "``eks get-token``",
+  "description": "All eks get-token commands default to api version v1beta1."
+}
diff --git a/awscli/customizations/eks/get_token.py b/awscli/customizations/eks/get_token.py
index bc2b0ac00..3b30d3039 100644
--- a/awscli/customizations/eks/get_token.py
+++ b/awscli/customizations/eks/get_token.py
@@ -126,8 +126,8 @@ class GetTokenCommand(BasicCommand):
     def discover_api_version(self):
         """
         Parses the KUBERNETES_EXEC_INFO environment variable and returns the
-        API version. If the environment variable is empty, malformed, or
-        invalid, return the v1alpha1 response and print a message to stderr.
+        API version. If the environment variable is malformed or invalid,
+        return the v1beta1 response and print a message to stderr.
 
         If the v1alpha1 API is specified explicitly, a message is printed to
         stderr with instructions to update.
@@ -139,7 +139,7 @@ class GetTokenCommand(BasicCommand):
         # "v1beta1" will be removed. At or around that time, EKS will likely
         # support v1.22 through v1.28, in which client API version "v1beta1"
         # will be supported by all EKS versions.
-        fallback_api_version = ALPHA_API
+        fallback_api_version = BETA_API
 
         error_prefixes = {
             "error": "Error parsing",
@@ -148,16 +148,12 @@ class GetTokenCommand(BasicCommand):
 
         exec_info_raw = os.environ.get("KUBERNETES_EXEC_INFO", "")
         if not exec_info_raw:
-            # All kube clients should be setting this. Otherewise, we'll return
-            # the fallback and write an error.
-            uni_print(
-                ERROR_MSG_TPL.format(
-                    error_prefixes["empty"],
-                    fallback_api_version,
-                ),
-                sys.stderr,
-            )
-            uni_print("\n", sys.stderr)
+            # All kube clients should be setting this, but client-go clients
+            # (kubectl, kubelet, etc) < 1.20 were not setting this if the API
+            # version defined in the kubeconfig was not v1alpha1.
+            #
+            # This was changed in kubernetes/kubernetes#95489 so that
+            # KUBERNETES_EXEC_INFO is always provided
             return fallback_api_version
         try:
             exec_info = json.loads(exec_info_raw)
@@ -177,7 +173,7 @@ class GetTokenCommand(BasicCommand):
         if api_version_raw in FULLY_SUPPORTED_API_VERSIONS:
             return api_version_raw
         elif api_version_raw in DEPRECATED_API_VERSIONS:
-            uni_print(DEPRECATION_MSG_TPL.format(ALPHA_API), sys.stderr)
+            uni_print(DEPRECATION_MSG_TPL.format(api_version_raw), sys.stderr)
             uni_print("\n", sys.stderr)
             return api_version_raw
         else:


Test patch:
diff --git a/tests/functional/eks/test_get_token.py b/tests/functional/eks/test_get_token.py
index ecf64bed5..bf2165899 100644
--- a/tests/functional/eks/test_get_token.py
+++ b/tests/functional/eks/test_get_token.py
@@ -86,7 +86,7 @@ class TestGetTokenCommand(BaseAWSCommandParamsTest):
             response,
             {
                 "kind": "ExecCredential",
-                "apiVersion": "client.authentication.k8s.io/v1alpha1",
+                "apiVersion": "client.authentication.k8s.io/v1beta1",
                 "spec": {},
                 "status": {
                     "expirationTimestamp": "2019-10-23T23:14:00Z",
@@ -185,13 +185,13 @@ class TestGetTokenCommand(BaseAWSCommandParamsTest):
 
         self.assertEqual(
             response["apiVersion"],
-            "client.authentication.k8s.io/v1alpha1",
+            "client.authentication.k8s.io/v1beta1",
         )
 
         self.assertEqual(
             stderr,
             (
-                "Error parsing KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1alpha1. "
+                "Error parsing KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1beta1. "
                 "This is likely a bug in your Kubernetes client. Please update your Kubernetes client.\n"
             ),
         )
@@ -203,16 +203,10 @@ class TestGetTokenCommand(BaseAWSCommandParamsTest):
 
         self.assertEqual(
             response["apiVersion"],
-            "client.authentication.k8s.io/v1alpha1",
+            "client.authentication.k8s.io/v1beta1",
         )
 
-        self.assertEqual(
-            stderr,
-            (
-                "Empty KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1alpha1. "
-                "This is likely a bug in your Kubernetes client. Please update your Kubernetes client.\n"
-            ),
-        )
+        self.assertEqual(stderr, "",)
 
     def test_api_version_discovery_v1(self):
         self.set_kubernetes_exec_info('v1')
@@ -248,13 +242,13 @@ class TestGetTokenCommand(BaseAWSCommandParamsTest):
 
         self.assertEqual(
             response["apiVersion"],
-            "client.authentication.k8s.io/v1alpha1",
+            "client.authentication.k8s.io/v1beta1",
         )
 
         self.assertEqual(
             stderr,
             (
-                "Unrecognized API version in KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1alpha1. "
+                "Unrecognized API version in KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1beta1. "
                 "This is likely due to an outdated AWS CLI. Please update your AWS CLI.\n"
             ),
         )