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