@@ -33,7 +33,7 @@ open class OSClientAdapter(client: OpenShiftClient, private val kubeClient: Kube
33
33
34
34
override val config by lazy {
35
35
// openshift client configuration does not have kube config entries
36
- ClientConfig (kubeClient)
36
+ ClientConfig (kubeClient.configuration )
37
37
}
38
38
39
39
override fun isOpenShift (): Boolean {
@@ -56,47 +56,32 @@ open class KubeClientAdapter(client: KubernetesClient) :
56
56
abstract class ClientAdapter <C : KubernetesClient >(private val fabric8Client : C ) {
57
57
58
58
companion object Factory {
59
- fun create (
60
- namespace : String? = null,
61
- context : String? = null,
62
- clientBuilder : KubernetesClientBuilder = KubernetesClientBuilder (),
63
- trustManagerProvider : ((toIntegrate: List <X509ExtendedTrustManager >) -> X509TrustManager )
64
- = IDEATrustManager ()::configure
65
- ): ClientAdapter <out KubernetesClient > {
66
- val config = Config .autoConfigure(context)
67
- return create(namespace, config, clientBuilder, trustManagerProvider)
68
- }
69
59
70
60
fun create (
71
61
namespace : String? = null,
72
- config : Config ,
73
- clientBuilder : KubernetesClientBuilder ,
74
- externalTrustManagerProvider : (toIntegrate: List < X509ExtendedTrustManager > ) -> X509TrustManager
75
- = IDEATrustManager ()::configure
62
+ context : String? = null ,
63
+ clientBuilder : KubernetesClientBuilder ? = null ,
64
+ createConfig : (context: String? ) -> Config = { context -> Config .autoConfigure(context) },
65
+ externalTrustManagerProvider : ((toIntegrate: List < X509ExtendedTrustManager >) -> X509TrustManager ) ? = null
76
66
): ClientAdapter <out KubernetesClient > {
67
+ val config = createConfig.invoke(context)
77
68
setNamespace(namespace, config)
78
- val kubeClient = clientBuilder
69
+ val builder = clientBuilder ? : KubernetesClientBuilder ()
70
+ val trustManager = externalTrustManagerProvider ? : IDEATrustManager ()::configure
71
+ val kubeClient = builder
79
72
.withConfig(config)
80
- .withHttpClientBuilderConsumer { builder ->
81
- setSslContext(builder , config, externalTrustManagerProvider )
73
+ .withHttpClientBuilderConsumer { httpClientBuilder ->
74
+ setSslContext(httpClientBuilder , config, trustManager )
82
75
}
83
76
.build()
84
- return if (isOpenShift(kubeClient)) {
77
+ return if (ClusterHelper . isOpenShift(kubeClient)) {
85
78
val osClient = kubeClient.adapt(NamespacedOpenShiftClient ::class .java)
86
79
OSClientAdapter (osClient, kubeClient)
87
80
} else {
88
81
KubeClientAdapter (kubeClient)
89
82
}
90
83
}
91
84
92
- private fun isOpenShift (client : KubernetesClient ): Boolean {
93
- return try {
94
- ClusterHelper .isOpenShift(client)
95
- } catch (e: Exception ) {
96
- false ;
97
- }
98
- }
99
-
100
85
private fun setSslContext (
101
86
builder : HttpClient .Builder ,
102
87
config : Config ,
@@ -124,7 +109,7 @@ abstract class ClientAdapter<C : KubernetesClient>(private val fabric8Client: C)
124
109
private val clients = ConcurrentHashMap <Class <out Client >, Client > ()
125
110
126
111
open val config by lazy {
127
- ClientConfig (fabric8Client)
112
+ ClientConfig (fabric8Client.configuration )
128
113
}
129
114
130
115
abstract fun isOpenShift (): Boolean
0 commit comments