@@ -12,11 +12,13 @@ package com.redhat.devtools.intellij.kubernetes.model.client
12
12
13
13
import com.intellij.openapi.application.ApplicationManager
14
14
import com.redhat.devtools.intellij.common.utils.ConfigHelper
15
+ import com.redhat.devtools.intellij.kubernetes.CompletableFutureUtils.PLATFORM_EXECUTOR
15
16
import io.fabric8.kubernetes.api.model.Context
16
17
import io.fabric8.kubernetes.api.model.NamedContext
17
18
import io.fabric8.kubernetes.client.Client
18
19
import io.fabric8.kubernetes.client.Config
19
20
import io.fabric8.kubernetes.client.internal.KubeConfigUtils
21
+ import java.util.concurrent.CompletableFuture
20
22
21
23
/* *
22
24
* An adapter to access [io.fabric8.kubernetes.client.Config].
@@ -45,26 +47,31 @@ open class ClientConfig(private val client: Client) {
45
47
KubeConfigAdapter ()
46
48
}
47
49
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
+ )
68
75
}
69
76
70
77
private fun setCurrentContext (
0 commit comments