Skip to content

Commit ca92fb0

Browse files
committed
wait for save of kubeconfig to finish (#640)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent f501828 commit ca92fb0

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ open class AllContexts(
143143
this.client.get()
144144
)
145145
this.current?.close()
146+
newClient.config.save().join()
146147
all.clear() // causes reload of all contexts when accessed afterwards
147148
val newCurrent = this.current // gets new current from all
148149
if (toWatch != null) {
@@ -197,7 +198,6 @@ open class AllContexts(
197198
private fun replaceClient(new: ClientAdapter<out KubernetesClient>, old: ClientAdapter<out KubernetesClient>?)
198199
: ClientAdapter<out KubernetesClient> {
199200
old?.close()
200-
new.config.save()
201201
this.client.set(new)
202202
return new
203203
}

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/client/ClientConfig.kt

+27-20
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ package com.redhat.devtools.intellij.kubernetes.model.client
1212

1313
import com.intellij.openapi.application.ApplicationManager
1414
import com.redhat.devtools.intellij.common.utils.ConfigHelper
15+
import com.redhat.devtools.intellij.kubernetes.CompletableFutureUtils.PLATFORM_EXECUTOR
1516
import io.fabric8.kubernetes.api.model.Context
1617
import io.fabric8.kubernetes.api.model.NamedContext
1718
import io.fabric8.kubernetes.client.Client
1819
import io.fabric8.kubernetes.client.Config
1920
import io.fabric8.kubernetes.client.internal.KubeConfigUtils
21+
import java.util.concurrent.CompletableFuture
2022

2123
/**
2224
* An adapter to access [io.fabric8.kubernetes.client.Config].
@@ -45,26 +47,31 @@ open class ClientConfig(private val client: Client) {
4547
KubeConfigAdapter()
4648
}
4749

48-
fun save() {
49-
runAsync {
50-
if (!kubeConfig.exists()) {
51-
return@runAsync
52-
}
53-
val fromFile = kubeConfig.load() ?: return@runAsync
54-
val currentContextInFile = KubeConfigUtils.getCurrentContext(fromFile)
55-
if (setCurrentContext(
56-
currentContext,
57-
currentContextInFile,
58-
fromFile
59-
).or( // no short-circuit
60-
setCurrentNamespace(
61-
currentContext?.context,
62-
currentContextInFile?.context)
63-
)
64-
) {
65-
kubeConfig.save(fromFile)
66-
}
67-
}
50+
fun save(): CompletableFuture<Boolean> {
51+
return CompletableFuture.supplyAsync(
52+
{
53+
if (!kubeConfig.exists()) {
54+
return@supplyAsync false
55+
}
56+
val fromFile = kubeConfig.load() ?: return@supplyAsync false
57+
val currentContextInFile = KubeConfigUtils.getCurrentContext(fromFile)
58+
if (setCurrentContext(
59+
currentContext,
60+
currentContextInFile,
61+
fromFile
62+
).or( // no short-circuit
63+
setCurrentNamespace(
64+
currentContext?.context,
65+
currentContextInFile?.context
66+
)
67+
)
68+
) {
69+
kubeConfig.save(fromFile)
70+
}
71+
return@supplyAsync true
72+
},
73+
PLATFORM_EXECUTOR
74+
)
6875
}
6976

7077
private fun setCurrentContext(

0 commit comments

Comments
 (0)