Skip to content

Commit c72e5c6

Browse files
committed
fix: copy KUBECONFIG as defined in shell to system properties (#826)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent a374bca commit c72e5c6

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/client/ClientAdapter.kt

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ abstract class ClientAdapter<C : KubernetesClient>(private val fabric8Client: C)
6464
createConfig: (context: String?) -> Config = { context -> Config.autoConfigure(context) },
6565
externalTrustManagerProvider: ((toIntegrate: List<X509ExtendedTrustManager>) -> X509TrustManager)? = null
6666
): ClientAdapter<out KubernetesClient> {
67+
KubeConfigEnvVar.copyToSystemProperties()
6768
val config = createConfig.invoke(context)
6869
setNamespace(namespace, config)
6970
val builder = clientBuilder ?: KubernetesClientBuilder()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.kubernetes.model.client
12+
13+
import com.intellij.openapi.util.SystemInfo
14+
import com.intellij.util.EnvironmentUtil
15+
16+
object KubeConfigEnvVar {
17+
18+
private const val KUBECONFIG_ENV_VAR = "KUBECONFIG"
19+
20+
/**
21+
* Copies the "KUBECONFIG" env variable and it's value to the system properties.
22+
* This env variable is used to list multiple config files and is supported by `kubectl`.
23+
*
24+
* example:
25+
* ```
26+
* export KUBECONFIG=${HOME}/.kube/config:${HOME}/.kube/minikube.yaml
27+
* ```
28+
* On MacOS env variables present in the shell are not present in IDEA
29+
* because applications that are launched from the dock don't get
30+
* env variables that are exported for the shell (`~/.zshrc`, `~/.bashrc`, `~/.zprofile`, etc.).
31+
* Therefore they are not present in [System.getProperties].
32+
* This method inspects the shell env variables and copies them over to the System properties.
33+
*
34+
* **See Also:** [issue #826](https://github.com/redhat-developer/intellij-kubernetes/issues/826)
35+
*/
36+
fun copyToSystemProperties() {
37+
if (SystemInfo.isMac) {
38+
val kubeconfig = EnvironmentUtil.getValue(KUBECONFIG_ENV_VAR) ?: return
39+
System.getProperties()[KUBECONFIG_ENV_VAR] = kubeconfig
40+
System.getProperties()[KUBECONFIG_ENV_VAR.lowercase()] = kubeconfig
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)