@@ -26,10 +26,9 @@ import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.NAME_P
26
26
import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.PROP_IS_OPENSHIFT
27
27
import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.PROP_KUBERNETES_VERSION
28
28
import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.PROP_OPENSHIFT_VERSION
29
+ import io.fabric8.kubernetes.api.model.Config
29
30
import io.fabric8.kubernetes.api.model.HasMetadata
30
- import io.fabric8.kubernetes.client.Config
31
31
import io.fabric8.kubernetes.client.KubernetesClient
32
- import java.nio.file.Paths
33
32
import java.util.concurrent.CompletionException
34
33
import java.util.concurrent.locks.ReentrantReadWriteLock
35
34
import kotlin.concurrent.read
@@ -85,16 +84,14 @@ open class AllContexts(
85
84
= { namespace, context -> ClientAdapter .Factory .create(namespace, context) }
86
85
) : IAllContexts {
87
86
88
- init {
89
- watchKubeConfig()
90
- }
91
-
92
87
private val lock = ReentrantReadWriteLock ()
93
88
94
89
private val client = ResettableLazyProperty {
95
- lock.write {
90
+ val client = lock.write {
96
91
clientFactory.invoke(null , null )
97
92
}
93
+ watchKubeConfig(client)
94
+ client
98
95
}
99
96
100
97
override val current: IActiveContext <out HasMetadata , out KubernetesClient >?
@@ -109,10 +106,11 @@ open class AllContexts(
109
106
lock.write {
110
107
if (_all .isEmpty()) {
111
108
try {
112
- val all = createContexts(client.get(), client.get()?.config)
109
+ val client = client.get()
110
+ val all = createContexts(client, client?.config)
113
111
_all .addAll(all)
114
112
} catch (e: Exception ) {
115
- //
113
+ logger< AllContexts >().warn( " Could not load all contexts. " , e)
116
114
}
117
115
}
118
116
return _all
@@ -195,8 +193,10 @@ open class AllContexts(
195
193
return config.allContexts
196
194
.map {
197
195
if (config.isCurrent(it)) {
196
+ logger<AllContexts >().debug(" Adding active context ${it.name} " )
198
197
createActiveContext(client) ? : Context (it)
199
198
} else {
199
+ logger<AllContexts >().debug(" Adding inactive context ${it.name} " )
200
200
Context (it)
201
201
}
202
202
}
@@ -240,8 +240,9 @@ open class AllContexts(
240
240
}
241
241
}
242
242
243
- protected open fun watchKubeConfig () {
244
- val filename = Config .getKubeconfigFilename() ? : return
243
+ protected open fun watchKubeConfig (client : ClientAdapter <out KubernetesClient >) {
244
+ val files = client.config.files
245
+ val paths = files.map { file -> file.toPath() }
245
246
/* *
246
247
* [ConfigWatcher] cannot add/remove listeners nor can it get closed (and stop the [java.nio.file.WatchService]).
247
248
* 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(
250
251
* The latter gets closed/recreated whenever the context changes in
251
252
* [com.redhat.devtools.intellij.kubernetes.model.client.KubeConfigPersistence].
252
253
*/
253
- val watcher = ConfigWatcher (Paths .get(filename)) { _, config: io.fabric8.kubernetes.api.model.Config ? -> onKubeConfigChanged(config) }
254
+ val watcher = ConfigWatcher (paths) { _, config: Config ? ->
255
+ onKubeConfigChanged(config)
256
+ }
254
257
runAsync(watcher::run)
255
258
}
256
259
257
- protected open fun onKubeConfigChanged (fileConfig : io.fabric8.kubernetes.api.model. Config ? ) {
260
+ protected open fun onKubeConfigChanged (fileConfig : Config ? ) {
258
261
lock.read {
259
262
fileConfig ? : return
260
263
val client = client.get() ? : return
0 commit comments