From 3124795897979a6532cc2913b7400c3ae15335ef Mon Sep 17 00:00:00 2001 From: Justin Ho Date: Thu, 5 May 2022 17:18:25 -0700 Subject: [PATCH] Address PR feedback --- .../enhancement-eksgettoken-91863.json | 2 +- ...enhancement-eksupdatekubeconfig-63017.json | 2 +- awscli/customizations/eks/get_token.py | 42 ++++++++++--------- tests/functional/eks/test_get_token.py | 3 +- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.changes/next-release/enhancement-eksgettoken-91863.json b/.changes/next-release/enhancement-eksgettoken-91863.json index 81c9102f3797..2215ce64194f 100644 --- a/.changes/next-release/enhancement-eksgettoken-91863.json +++ b/.changes/next-release/enhancement-eksgettoken-91863.json @@ -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" } diff --git a/.changes/next-release/enhancement-eksupdatekubeconfig-63017.json b/.changes/next-release/enhancement-eksupdatekubeconfig-63017.json index 33dc9461243e..713b37daed95 100644 --- a/.changes/next-release/enhancement-eksupdatekubeconfig-63017.json +++ b/.changes/next-release/enhancement-eksupdatekubeconfig-63017.json @@ -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" } diff --git a/awscli/customizations/eks/get_token.py b/awscli/customizations/eks/get_token.py index 0a60fe0372ff..bc2b0ac00d35 100644 --- a/awscli/customizations/eks/get_token.py +++ b/awscli/customizations/eks/get_token.py @@ -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 @@ -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, ), @@ -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, ), @@ -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 diff --git a/tests/functional/eks/test_get_token.py b/tests/functional/eks/test_get_token.py index 6f5cba5a0ed9..e73554f03e1a 100644 --- a/tests/functional/eks/test_get_token.py +++ b/tests/functional/eks/test_get_token.py @@ -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, )