Skip to content

Commit 3124795

Browse files
committed
Address PR feedback
1 parent 18fdfa3 commit 3124795

4 files changed

Lines changed: 25 additions & 24 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"type": "enhancement",
33
"category": "eks get-token",
4-
"description": "Add support to respect env var KUBERNETES_EXEC_INFO in eks get-token"
4+
"description": "Add support for respecting API version found in KUBERNETES_EXEC_INFO environment variable"
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"type": "enhancement",
33
"category": "eks update-kubeconfig",
4-
"description": "Update default API version for eks update-kubeconfig"
4+
"description": "Update default API version to v1beta1"
55
}

awscli/customizations/eks/get_token.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@
4040
ALPHA_API,
4141
]
4242

43+
ERROR_MSG_TPL = (
44+
"{0} KUBERNETES_EXEC_INFO, defaulting to {1}. This is likely a "
45+
"bug in your Kubernetes client. Please update your Kubernetes "
46+
"client."
47+
)
48+
UNRECOGNIZED_MSG_TPL = (
49+
"Unrecognized API version in KUBERNETES_EXEC_INFO, defaulting to "
50+
"{0}. This is likely due to an outdated AWS "
51+
"CLI. Please update your AWS CLI."
52+
)
53+
DEPRECATION_MSG_TPL = (
54+
"Kubeconfig user entry is using deprecated API version {0}. Run "
55+
"'aws eks update-kubeconfig' to update."
56+
)
57+
4358
# Presigned url timeout in seconds
4459
URL_TIMEOUT = 60
4560

@@ -131,27 +146,12 @@ def discover_api_version(self):
131146
"empty": "Empty",
132147
}
133148

134-
error_msg_tpl = (
135-
"{0} KUBERNETES_EXEC_INFO, defaulting to {1}. This is likely a "
136-
"bug in your Kubernetes client. Please update your Kubernetes "
137-
"client."
138-
)
139-
unrecognized_msg = (
140-
"Unrecognized API version in KUBERNETES_EXEC_INFO, defaulting to "
141-
f"{fallback_api_version}. This is likely due to an outdated AWS "
142-
"CLI. Please update your AWS CLI."
143-
)
144-
deprecation_msg_tpl = (
145-
"Kubeconfig user entry is using deprecated API version {0}. Run "
146-
"'aws eks update-kubeconfig' to update."
147-
)
148-
149149
exec_info_raw = os.environ.get("KUBERNETES_EXEC_INFO", "")
150150
if not exec_info_raw:
151151
# All kube clients should be setting this. Otherewise, we'll return
152152
# the fallback and write an error.
153153
uni_print(
154-
error_msg_tpl.format(
154+
ERROR_MSG_TPL.format(
155155
error_prefixes["empty"],
156156
fallback_api_version,
157157
),
@@ -164,7 +164,7 @@ def discover_api_version(self):
164164
except json.JSONDecodeError:
165165
# The environment variable was malformed
166166
uni_print(
167-
error_msg_tpl.format(
167+
ERROR_MSG_TPL.format(
168168
error_prefixes["error"],
169169
fallback_api_version,
170170
),
@@ -177,12 +177,14 @@ def discover_api_version(self):
177177
if api_version_raw in FULLY_SUPPORTED_API_VERSIONS:
178178
return api_version_raw
179179
elif api_version_raw in DEPRECATED_API_VERSIONS:
180-
uni_print(deprecation_msg_tpl.format(ALPHA_API), sys.stderr)
180+
uni_print(DEPRECATION_MSG_TPL.format(ALPHA_API), sys.stderr)
181181
uni_print("\n", sys.stderr)
182182
return api_version_raw
183183
else:
184-
# write unrecognized api version message
185-
uni_print(unrecognized_msg, sys.stderr)
184+
uni_print(
185+
UNRECOGNIZED_MSG_TPL.format(fallback_api_version),
186+
sys.stderr,
187+
)
186188
uni_print("\n", sys.stderr)
187189
return fallback_api_version
188190

tests/functional/eks/test_get_token.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ def set_kubernetes_exec_info(self, api_version):
7373
# api version
7474
kubernetes_exec_info_tpl = (
7575
'{{"kind":"ExecCredential",'
76-
'"apiVersion":"client.authentication.k8s.io/{0}",'
76+
f'"apiVersion":"client.authentication.k8s.io/{api_version}",'
7777
'"spec":{{"interactive":true}}}}'
7878
)
79-
# kubernetes_exec_info_tpl = '{{"kind":"ExecCredential","apiVersion":"client.authentication.k8s.io/{}","spec":{{"interactive":true}}}}'
8079
self.environ['KUBERNETES_EXEC_INFO'] = kubernetes_exec_info_tpl.format(
8180
api_version,
8281
)

0 commit comments

Comments
 (0)