Skip to content

Commit 835393f

Browse files
micahhauslerstealthycoin
authored andcommitted
Default to beta API for eks get-token
* Stop logging a warning on an empty KUBERNETES_EXEC_INFO * Respond with correct deprecated version in warning message Signed-off-by: Micah Hausler <[email protected]>
1 parent d693aed commit 835393f

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "bugfix",
3+
"category": "eks get-token",
4+
"description": "Correctly fallback to client.authentication.k8s.io/v1beta1 API if KUBERNETES_EXEC_INFO is undefined"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "feature",
3+
"category": "eks get-token",
4+
"description": "All eks get-token commands default to api version v1beta1."
5+
}

awscli/customizations/eks/get_token.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def _run_main(self, parsed_args, parsed_globals):
126126
def discover_api_version(self):
127127
"""
128128
Parses the KUBERNETES_EXEC_INFO environment variable and returns the
129-
API version. If the environment variable is empty, malformed, or
130-
invalid, return the v1alpha1 response and print a message to stderr.
129+
API version. If the environment variable is malformed or invalid,
130+
return the v1beta1 response and print a message to stderr.
131131
132132
If the v1alpha1 API is specified explicitly, a message is printed to
133133
stderr with instructions to update.
@@ -139,7 +139,7 @@ def discover_api_version(self):
139139
# "v1beta1" will be removed. At or around that time, EKS will likely
140140
# support v1.22 through v1.28, in which client API version "v1beta1"
141141
# will be supported by all EKS versions.
142-
fallback_api_version = ALPHA_API
142+
fallback_api_version = BETA_API
143143

144144
error_prefixes = {
145145
"error": "Error parsing",
@@ -148,16 +148,12 @@ def discover_api_version(self):
148148

149149
exec_info_raw = os.environ.get("KUBERNETES_EXEC_INFO", "")
150150
if not exec_info_raw:
151-
# All kube clients should be setting this. Otherewise, we'll return
152-
# the fallback and write an error.
153-
uni_print(
154-
ERROR_MSG_TPL.format(
155-
error_prefixes["empty"],
156-
fallback_api_version,
157-
),
158-
sys.stderr,
159-
)
160-
uni_print("\n", sys.stderr)
151+
# All kube clients should be setting this, but client-go clients
152+
# (kubectl, kubelet, etc) < 1.20 were not setting this if the API
153+
# version defined in the kubeconfig was not v1alpha1.
154+
#
155+
# This was changed in kubernetes/kubernetes#95489 so that
156+
# KUBERNETES_EXEC_INFO is always provided
161157
return fallback_api_version
162158
try:
163159
exec_info = json.loads(exec_info_raw)
@@ -177,7 +173,7 @@ def discover_api_version(self):
177173
if api_version_raw in FULLY_SUPPORTED_API_VERSIONS:
178174
return api_version_raw
179175
elif api_version_raw in DEPRECATED_API_VERSIONS:
180-
uni_print(DEPRECATION_MSG_TPL.format(ALPHA_API), sys.stderr)
176+
uni_print(DEPRECATION_MSG_TPL.format(api_version_raw), sys.stderr)
181177
uni_print("\n", sys.stderr)
182178
return api_version_raw
183179
else:

tests/functional/eks/test_get_token.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_get_token(self, mock_datetime):
8686
response,
8787
{
8888
"kind": "ExecCredential",
89-
"apiVersion": "client.authentication.k8s.io/v1alpha1",
89+
"apiVersion": "client.authentication.k8s.io/v1beta1",
9090
"spec": {},
9191
"status": {
9292
"expirationTimestamp": "2019-10-23T23:14:00Z",
@@ -185,13 +185,13 @@ def test_api_version_discovery_malformed(self):
185185

186186
self.assertEqual(
187187
response["apiVersion"],
188-
"client.authentication.k8s.io/v1alpha1",
188+
"client.authentication.k8s.io/v1beta1",
189189
)
190190

191191
self.assertEqual(
192192
stderr,
193193
(
194-
"Error parsing KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1alpha1. "
194+
"Error parsing KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1beta1. "
195195
"This is likely a bug in your Kubernetes client. Please update your Kubernetes client.\n"
196196
),
197197
)
@@ -203,16 +203,10 @@ def test_api_version_discovery_empty(self):
203203

204204
self.assertEqual(
205205
response["apiVersion"],
206-
"client.authentication.k8s.io/v1alpha1",
206+
"client.authentication.k8s.io/v1beta1",
207207
)
208208

209-
self.assertEqual(
210-
stderr,
211-
(
212-
"Empty KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1alpha1. "
213-
"This is likely a bug in your Kubernetes client. Please update your Kubernetes client.\n"
214-
),
215-
)
209+
self.assertEqual(stderr, "",)
216210

217211
def test_api_version_discovery_v1(self):
218212
self.set_kubernetes_exec_info('v1')
@@ -248,13 +242,13 @@ def test_api_version_discovery_unknown(self):
248242

249243
self.assertEqual(
250244
response["apiVersion"],
251-
"client.authentication.k8s.io/v1alpha1",
245+
"client.authentication.k8s.io/v1beta1",
252246
)
253247

254248
self.assertEqual(
255249
stderr,
256250
(
257-
"Unrecognized API version in KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1alpha1. "
251+
"Unrecognized API version in KUBERNETES_EXEC_INFO, defaulting to client.authentication.k8s.io/v1beta1. "
258252
"This is likely due to an outdated AWS CLI. Please update your AWS CLI.\n"
259253
),
260254
)

0 commit comments

Comments
 (0)