diff --git a/gradle.properties b/gradle.properties index 9ba7cbf39..baa4c91d4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ jetBrainsToken=invalid jetBrainsChannel=stable intellijPluginVersion=1.16.1 kotlinJvmPluginVersion=1.8.0 -intellijCommonVersion=1.9.6-SNAPSHOT +intellijCommonVersion=1.9.7-SNAPSHOT telemetryPluginVersion=1.1.0.52 kotlin.stdlib.default.dependency = false kotlinVersion=1.6.21 diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt index 0b76294bd..809a5e744 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt @@ -26,10 +26,9 @@ import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.NAME_P import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.PROP_IS_OPENSHIFT import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.PROP_KUBERNETES_VERSION import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.PROP_OPENSHIFT_VERSION +import io.fabric8.kubernetes.api.model.Config import io.fabric8.kubernetes.api.model.HasMetadata -import io.fabric8.kubernetes.client.Config import io.fabric8.kubernetes.client.KubernetesClient -import java.nio.file.Paths import java.util.concurrent.CompletionException import java.util.concurrent.locks.ReentrantReadWriteLock import kotlin.concurrent.read @@ -85,16 +84,14 @@ open class AllContexts( = { namespace, context -> ClientAdapter.Factory.create(namespace, context) } ) : IAllContexts { - init { - watchKubeConfig() - } - private val lock = ReentrantReadWriteLock() private val client = ResettableLazyProperty { - lock.write { + val client = lock.write { clientFactory.invoke(null, null) } + watchKubeConfig(client) + client } override val current: IActiveContext? @@ -109,10 +106,11 @@ open class AllContexts( lock.write { if (_all.isEmpty()) { try { - val all = createContexts(client.get(), client.get()?.config) + val client = client.get() + val all = createContexts(client, client?.config) _all.addAll(all) } catch (e: Exception) { - // + logger().warn("Could not load all contexts.", e) } } return _all @@ -195,8 +193,10 @@ open class AllContexts( return config.allContexts .map { if (config.isCurrent(it)) { + logger().debug("Adding active context ${it.name}") createActiveContext(client) ?: Context(it) } else { + logger().debug("Adding inactive context ${it.name}") Context(it) } } @@ -240,8 +240,9 @@ open class AllContexts( } } - protected open fun watchKubeConfig() { - val filename = Config.getKubeconfigFilename() ?: return + protected open fun watchKubeConfig(client: ClientAdapter) { + val files = client.config.files + val paths = files.map { file -> file.toPath() } /** * [ConfigWatcher] cannot add/remove listeners nor can it get closed (and stop the [java.nio.file.WatchService]). * We therefore have to create a single instance in here rather than using it in a shielded/private way within @@ -250,11 +251,13 @@ open class AllContexts( * The latter gets closed/recreated whenever the context changes in * [com.redhat.devtools.intellij.kubernetes.model.client.KubeConfigPersistence]. */ - val watcher = ConfigWatcher(Paths.get(filename)) { _, config: io.fabric8.kubernetes.api.model.Config? -> onKubeConfigChanged(config) } + val watcher = ConfigWatcher(paths) { _, config: Config? -> + onKubeConfigChanged(config) + } runAsync(watcher::run) } - protected open fun onKubeConfigChanged(fileConfig: io.fabric8.kubernetes.api.model.Config?) { + protected open fun onKubeConfigChanged(fileConfig: Config?) { lock.read { fileConfig ?: return val client = client.get() ?: return diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/client/ClientConfig.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/client/ClientConfig.kt index e41571cf3..4f753f5c2 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/client/ClientConfig.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/client/ClientConfig.kt @@ -45,6 +45,11 @@ open class ClientConfig( client.configuration } + val files: List + get() { + return configuration.files + } + fun save(): CompletableFuture { return CompletableFuture.supplyAsync( { diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/context/IActiveContext.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/context/IActiveContext.kt index 37abc2621..e362073bf 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/context/IActiveContext.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/context/IActiveContext.kt @@ -10,6 +10,7 @@ ******************************************************************************/ package com.redhat.devtools.intellij.kubernetes.model.context +import com.intellij.openapi.diagnostic.logger import com.redhat.devtools.intellij.common.kubernetes.ClusterInfo import com.redhat.devtools.intellij.kubernetes.model.IResourceModelObservable import com.redhat.devtools.intellij.kubernetes.model.client.ClientAdapter @@ -34,12 +35,14 @@ interface IActiveContext: IContext { ): IActiveContext? { val currentContext = client.config.currentContext ?: return null return if (client.isOpenShift()) { + logger().warn("Current context ${currentContext.name} is OpenShift") OpenShiftContext( currentContext, observable, client as OSClientAdapter ) } else { + logger().warn("Current context ${currentContext.name} is Kubernetes") KubernetesContext( currentContext, observable, diff --git a/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt b/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt index 7ef19075c..22cfd3daf 100644 --- a/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt +++ b/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt @@ -464,7 +464,7 @@ class AllContextsTest { runnable.invoke() // run directly, not in IDEA pooled threads } - override fun watchKubeConfig() { + override fun watchKubeConfig(client: ClientAdapter) { // don't watch filesystem (override super method) watchStarted = true }