Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion util/src/main/java/io/kubernetes/client/util/KubeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,15 @@ private Map<String, String> credentialsViaExecCredential(Map<String, Object> exe
Map<String, String> credentials = new HashMap<>();

String apiVersion = (String) execMap.get("apiVersion");
if (!"client.authentication.k8s.io/v1beta1".equals(apiVersion)
/**
* Some history here: v1 was added in kubernetes 1.21
* (https://github.com/kubernetes/kubernetes/pull/102890) v1alpha1 was removed in Kubernetes
* 1.24 (https://github.com/kubernetes/kubernetes/pull/108616) We need to leave v1alpha1 for now
* to support backwards compatability, but we will likely want to remove it eventually after
* Kubernetes 1.23 is no longer supported }
*/
if (!"client.authentication.k8s.io/v1".equals(apiVersion)
&& !"client.authentication.k8s.io/v1beta1".equals(apiVersion)
&& !"client.authentication.k8s.io/v1alpha1".equals(apiVersion)) {
log.error("Unrecognized user.exec.apiVersion: {}", apiVersion);
return null;
Expand Down
11 changes: 11 additions & 0 deletions util/src/test/java/io/kubernetes/client/util/KubeConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@ public void testExecCredentialsAlpha1() throws Exception {
assertEquals("abc123", kc.getCredentials().get(KubeConfig.CRED_TOKEN_KEY));
}

@Test
public void testExecCredentialsV1() throws Exception {
// TODO: test exec on Windows
if (System.getProperty("os.name").contains("Windows")) {
return;
}
KubeConfig kc =
KubeConfig.loadKubeConfig(new StringReader(KUBECONFIG_EXEC.replace("v1beta1", "v1")));
assertEquals("abc123", kc.getCredentials().get(KubeConfig.CRED_TOKEN_KEY));
}

private static final String KUBECONFIG_EXEC_ENV =
"apiVersion: v1\n"
+ "current-context: c\n"
Expand Down