Skip to content

Commit

Permalink
Default to beta API for eks get-token
Browse files Browse the repository at this point in the history
* Stop logging a warning on an empty KUBERNETES_EXEC_INFO

Signed-off-by: Micah Hausler <mhausler@amazon.com>
  • Loading branch information
micahhausler committed May 11, 2022
1 parent d693aed commit 7ba16e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
22 changes: 9 additions & 13 deletions awscli/customizations/eks/get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def _run_main(self, parsed_args, parsed_globals):
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.
Expand All @@ -139,7 +139,7 @@ def discover_api_version(self):
# "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",
Expand All @@ -148,16 +148,12 @@ def discover_api_version(self):

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)
Expand Down
10 changes: 2 additions & 8 deletions tests/functional/eks/test_get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,10 @@ def test_api_version_discovery_empty(self):

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')
Expand Down

0 comments on commit 7ba16e5

Please sign in to comment.