File tree 3 files changed +45
-1
lines changed
src/main/kotlin/com/redhat/devtools/intellij/kubernetes
3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -81,14 +81,22 @@ abstract class ClientAdapter<C : KubernetesClient>(private val fabric8Client: C)
81
81
setSslContext(builder, config, externalTrustManagerProvider)
82
82
}
83
83
.build()
84
- return if (ClusterHelper . isOpenShift(kubeClient)) {
84
+ return if (isOpenShift(kubeClient)) {
85
85
val osClient = kubeClient.adapt(NamespacedOpenShiftClient ::class .java)
86
86
OSClientAdapter (osClient, kubeClient)
87
87
} else {
88
88
KubeClientAdapter (kubeClient)
89
89
}
90
90
}
91
91
92
+ private fun isOpenShift (client : KubernetesClient ): Boolean {
93
+ return try {
94
+ ClusterHelper .isOpenShift(client)
95
+ } catch (e: Exception ) {
96
+ false ;
97
+ }
98
+ }
99
+
92
100
private fun setSslContext (
93
101
builder : HttpClient .Builder ,
94
102
config : Config ,
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ fun toTitle(e: Throwable?): String {
24
24
25
25
fun toMessage (e : Throwable ? ): String {
26
26
return noCurrentContextMessage(e)
27
+ ? : unknownHostMessage(e)
27
28
? : recursiveGetMessage(e)
28
29
? : " Unknown Error"
29
30
}
@@ -48,3 +49,33 @@ fun noCurrentContextMessage(e: Throwable?): String? {
48
49
null
49
50
}
50
51
}
52
+
53
+ fun unknownHostMessage (e : Throwable ? ): String? {
54
+ val unknownHostException = recursiveGetThrowable(e) {
55
+ throwable -> throwable is UnknownHostException
56
+ }
57
+ return if (unknownHostException is UnknownHostException ) {
58
+ " Unreachable cluster at ${getHost(unknownHostException)} ."
59
+ } else {
60
+ null
61
+ }
62
+ }
63
+
64
+ private fun getHost (e : UnknownHostException ): String? {
65
+ val portions = e.message?.split(' :' ) ? : return e.message
66
+ return if (1 < portions.size) {
67
+ portions[1 ]
68
+ } else {
69
+ e.message
70
+ }
71
+ }
72
+
73
+ private fun recursiveGetThrowable (e : Throwable ? , predicate : (e: Throwable ? ) -> Boolean ): Throwable ? {
74
+ return if (e == null
75
+ || e == e.cause
76
+ || predicate.invoke(e)) {
77
+ e
78
+ } else {
79
+ recursiveGetThrowable(e.cause, predicate)
80
+ }
81
+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import com.redhat.devtools.intellij.kubernetes.model.util.hasDeletionTimestamp
30
30
import com.redhat.devtools.intellij.kubernetes.model.util.isSameResource
31
31
import com.redhat.devtools.intellij.kubernetes.model.util.isUnauthorized
32
32
import com.redhat.devtools.intellij.kubernetes.model.util.isWillBeDeleted
33
+ import com.redhat.devtools.intellij.kubernetes.model.util.unknownHostMessage
33
34
import io.fabric8.kubernetes.api.model.HasMetadata
34
35
import io.fabric8.kubernetes.client.KubernetesClientException
35
36
import javax.swing.Icon
@@ -264,6 +265,10 @@ open class TreeStructure(
264
265
}
265
266
266
267
private fun getMessage (e : Exception ? ): String {
268
+ val unknownHostMessage = unknownHostMessage(e)
269
+ if (unknownHostMessage != null ) {
270
+ return unknownHostMessage
271
+ }
267
272
val causeMessage = e?.cause?.message
268
273
return if (causeMessage == null ) {
269
274
getMessageOrDefault(e)
You can’t perform that action at this time.
0 commit comments