Skip to content

Commit b570730

Browse files
authored
Merge pull request #2300 from brendandburns/auth_config
Add support for v1 exec credentials (and a brief explanation)
2 parents 3243ebb + c0233a5 commit b570730

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

util/src/main/java/io/kubernetes/client/util/KubeConfig.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,15 @@ private Map<String, String> credentialsViaExecCredential(Map<String, Object> exe
272272
Map<String, String> credentials = new HashMap<>();
273273

274274
String apiVersion = (String) execMap.get("apiVersion");
275-
if (!"client.authentication.k8s.io/v1beta1".equals(apiVersion)
275+
/**
276+
* Some history here: v1 was added in kubernetes 1.21
277+
* (https://github.com/kubernetes/kubernetes/pull/102890) v1alpha1 was removed in Kubernetes
278+
* 1.24 (https://github.com/kubernetes/kubernetes/pull/108616) We need to leave v1alpha1 for now
279+
* to support backwards compatability, but we will likely want to remove it eventually after
280+
* Kubernetes 1.23 is no longer supported }
281+
*/
282+
if (!"client.authentication.k8s.io/v1".equals(apiVersion)
283+
&& !"client.authentication.k8s.io/v1beta1".equals(apiVersion)
276284
&& !"client.authentication.k8s.io/v1alpha1".equals(apiVersion)) {
277285
log.error("Unrecognized user.exec.apiVersion: {}", apiVersion);
278286
return null;

util/src/test/java/io/kubernetes/client/util/KubeConfigTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,17 @@ public void testExecCredentialsAlpha1() throws Exception {
374374
assertEquals("abc123", kc.getCredentials().get(KubeConfig.CRED_TOKEN_KEY));
375375
}
376376

377+
@Test
378+
public void testExecCredentialsV1() throws Exception {
379+
// TODO: test exec on Windows
380+
if (System.getProperty("os.name").contains("Windows")) {
381+
return;
382+
}
383+
KubeConfig kc =
384+
KubeConfig.loadKubeConfig(new StringReader(KUBECONFIG_EXEC.replace("v1beta1", "v1")));
385+
assertEquals("abc123", kc.getCredentials().get(KubeConfig.CRED_TOKEN_KEY));
386+
}
387+
377388
private static final String KUBECONFIG_EXEC_ENV =
378389
"apiVersion: v1\n"
379390
+ "current-context: c\n"

0 commit comments

Comments
 (0)