Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: copy KUBECONFIG as defined in shell to system properties (#826) #827

Merged
merged 1 commit into from
Jan 31, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ abstract class ClientAdapter<C : KubernetesClient>(private val fabric8Client: C)
createConfig: (context: String?) -> Config = { context -> Config.autoConfigure(context) },
externalTrustManagerProvider: ((toIntegrate: List<X509ExtendedTrustManager>) -> X509TrustManager)? = null
): ClientAdapter<out KubernetesClient> {
KubeConfigEnvVar.copyToSystemProperties()
val config = createConfig.invoke(context)
setNamespace(namespace, config)
val builder = clientBuilder ?: KubernetesClientBuilder()
Expand Down
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
}
}
}
Loading