Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
justindho committed May 6, 2022
1 parent 18fdfa3 commit 3124795
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .changes/next-release/enhancement-eksgettoken-91863.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "enhancement",
"category": "eks get-token",
"description": "Add support to respect env var KUBERNETES_EXEC_INFO in eks get-token"
"description": "Add support for respecting API version found in KUBERNETES_EXEC_INFO environment variable"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "enhancement",
"category": "eks update-kubeconfig",
"description": "Update default API version for eks update-kubeconfig"
"description": "Update default API version to v1beta1"
}
42 changes: 22 additions & 20 deletions awscli/customizations/eks/get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@
ALPHA_API,
]

ERROR_MSG_TPL = (
"{0} KUBERNETES_EXEC_INFO, defaulting to {1}. This is likely a "
"bug in your Kubernetes client. Please update your Kubernetes "
"client."
)
UNRECOGNIZED_MSG_TPL = (
"Unrecognized API version in KUBERNETES_EXEC_INFO, defaulting to "
"{0}. This is likely due to an outdated AWS "
"CLI. Please update your AWS CLI."
)
DEPRECATION_MSG_TPL = (
"Kubeconfig user entry is using deprecated API version {0}. Run "
"'aws eks update-kubeconfig' to update."
)

# Presigned url timeout in seconds
URL_TIMEOUT = 60

Expand Down Expand Up @@ -131,27 +146,12 @@ def discover_api_version(self):
"empty": "Empty",
}

error_msg_tpl = (
"{0} KUBERNETES_EXEC_INFO, defaulting to {1}. This is likely a "
"bug in your Kubernetes client. Please update your Kubernetes "
"client."
)
unrecognized_msg = (
"Unrecognized API version in KUBERNETES_EXEC_INFO, defaulting to "
f"{fallback_api_version}. This is likely due to an outdated AWS "
"CLI. Please update your AWS CLI."
)
deprecation_msg_tpl = (
"Kubeconfig user entry is using deprecated API version {0}. Run "
"'aws eks update-kubeconfig' to update."
)

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_MSG_TPL.format(
error_prefixes["empty"],
fallback_api_version,
),
Expand All @@ -164,7 +164,7 @@ def discover_api_version(self):
except json.JSONDecodeError:
# The environment variable was malformed
uni_print(
error_msg_tpl.format(
ERROR_MSG_TPL.format(
error_prefixes["error"],
fallback_api_version,
),
Expand All @@ -177,12 +177,14 @@ def discover_api_version(self):
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(ALPHA_API), sys.stderr)
uni_print("\n", sys.stderr)
return api_version_raw
else:
# write unrecognized api version message
uni_print(unrecognized_msg, sys.stderr)
uni_print(
UNRECOGNIZED_MSG_TPL.format(fallback_api_version),
sys.stderr,
)
uni_print("\n", sys.stderr)
return fallback_api_version

Expand Down
3 changes: 1 addition & 2 deletions tests/functional/eks/test_get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ def set_kubernetes_exec_info(self, api_version):
# api version
kubernetes_exec_info_tpl = (
'{{"kind":"ExecCredential",'
'"apiVersion":"client.authentication.k8s.io/{0}",'
f'"apiVersion":"client.authentication.k8s.io/{api_version}",'
'"spec":{{"interactive":true}}}}'
)
# kubernetes_exec_info_tpl = '{{"kind":"ExecCredential","apiVersion":"client.authentication.k8s.io/{}","spec":{{"interactive":true}}}}'
self.environ['KUBERNETES_EXEC_INFO'] = kubernetes_exec_info_tpl.format(
api_version,
)
Expand Down

0 comments on commit 3124795

Please sign in to comment.