Skip to content

Commit 6fa3a28

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

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import io.fabric8.kubernetes.api.model.NamedContext
1717
import io.fabric8.kubernetes.client.Client
1818
import io.fabric8.kubernetes.client.Config
1919
import io.fabric8.kubernetes.client.internal.KubeConfigUtils
20+
import java.util.concurrent.CompletableFuture
2021

2122
/**
2223
* An adapter to access [io.fabric8.kubernetes.client.Config].
@@ -45,12 +46,12 @@ open class ClientConfig(private val client: Client) {
4546
KubeConfigAdapter()
4647
}
4748

48-
fun save() {
49-
runAsync {
49+
fun save(): CompletableFuture<Boolean> {
50+
return CompletableFuture.supplyAsync {
5051
if (!kubeConfig.exists()) {
51-
return@runAsync
52+
return@supplyAsync false
5253
}
53-
val fromFile = kubeConfig.load() ?: return@runAsync
54+
val fromFile = kubeConfig.load() ?: return@supplyAsync false
5455
val currentContextInFile = KubeConfigUtils.getCurrentContext(fromFile)
5556
if (setCurrentContext(
5657
currentContext,
@@ -64,6 +65,7 @@ open class ClientConfig(private val client: Client) {
6465
) {
6566
kubeConfig.save(fromFile)
6667
}
68+
return@supplyAsync true
6769
}
6870
}
6971

0 commit comments

Comments
 (0)