Skip to content

Commit

Permalink
wait for save of kubeconfig to finish (redhat-developer#640)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Jul 24, 2023
1 parent f501828 commit 6fa3a28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ open class AllContexts(
this.client.get()
)
this.current?.close()
newClient.config.save().join()
all.clear() // causes reload of all contexts when accessed afterwards
val newCurrent = this.current // gets new current from all
if (toWatch != null) {
Expand Down Expand Up @@ -197,7 +198,6 @@ open class AllContexts(
private fun replaceClient(new: ClientAdapter<out KubernetesClient>, old: ClientAdapter<out KubernetesClient>?)
: ClientAdapter<out KubernetesClient> {
old?.close()
new.config.save()
this.client.set(new)
return new
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.fabric8.kubernetes.api.model.NamedContext
import io.fabric8.kubernetes.client.Client
import io.fabric8.kubernetes.client.Config
import io.fabric8.kubernetes.client.internal.KubeConfigUtils
import java.util.concurrent.CompletableFuture

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

fun save() {
runAsync {
fun save(): CompletableFuture<Boolean> {
return CompletableFuture.supplyAsync {
if (!kubeConfig.exists()) {
return@runAsync
return@supplyAsync false
}
val fromFile = kubeConfig.load() ?: return@runAsync
val fromFile = kubeConfig.load() ?: return@supplyAsync false
val currentContextInFile = KubeConfigUtils.getCurrentContext(fromFile)
if (setCurrentContext(
currentContext,
Expand All @@ -64,6 +65,7 @@ open class ClientConfig(private val client: Client) {
) {
kubeConfig.save(fromFile)
}
return@supplyAsync true
}
}

Expand Down

0 comments on commit 6fa3a28

Please sign in to comment.