forked from redhat-developer/intellij-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: copy KUBECONFIG as defined in shell to system properties (redhat…
…-developer#826) Signed-off-by: Andre Dietisheim <[email protected]>
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/client/KubeConfigEnvVar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.kubernetes.model.client | ||
|
||
import com.intellij.openapi.util.SystemInfo | ||
import com.intellij.util.EnvironmentUtil | ||
|
||
object KubeConfigEnvVar { | ||
|
||
private const val KUBECONFIG_ENV_VAR = "KUBECONFIG" | ||
|
||
/** | ||
* Copies the "KUBECONFIG" env variable and it's value to the system properties. | ||
* This env variable is used to list multiple config files and is supported by `kubectl`. | ||
* | ||
* example: | ||
* ``` | ||
* export KUBECONFIG=${HOME}/.kube/config:${HOME}/.kube/minikube.yaml | ||
* ``` | ||
* On MacOS env variables present in the shell are not present in IDEA | ||
* because applications that are launched from the dock don't get | ||
* env variables that are exported for the shell (`~/.zshrc`, `~/.bashrc`, `~/.zprofile`, etc.). | ||
* Therefore they are not present in [System.getProperties]. | ||
* This method inspects the shell env variables and copies them over to the System properties. | ||
* | ||
* **See Also:** [issue #826](https://github.com/redhat-developer/intellij-kubernetes/issues/826) | ||
*/ | ||
fun copyToSystemProperties() { | ||
if (SystemInfo.isMac) { | ||
val kubeconfig = EnvironmentUtil.getValue(KUBECONFIG_ENV_VAR) ?: return | ||
System.getProperties()[KUBECONFIG_ENV_VAR] = kubeconfig | ||
System.getProperties()[KUBECONFIG_ENV_VAR.lowercase()] = kubeconfig | ||
} | ||
} | ||
} |