Skip to content

Commit 52ad428

Browse files
committed
fix: bump kubernetes-client to 7.0.0 (#794)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent 719d72c commit 52ad428

File tree

14 files changed

+620
-349
lines changed

14 files changed

+620
-349
lines changed

.github/workflows/IJ.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
IJ: [2023.1, 2023.2, 2023.3, 2024.1, 2024.2]
17+
IJ: [2023.1, 2023.2, 2023.3, 2024.1, 2024.2, 2024.3]
1818

1919
steps:
2020
- uses: actions/checkout@v4

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ dependencies {
6767

6868
// for unit tests
6969
testImplementation(libs.assertj.core)
70-
testImplementation(libs.mockito.inline)
70+
testImplementation(libs.mockito)
7171
testImplementation(libs.mockito.kotlin)
7272
testImplementation(libs.kotlin.test.junit)
7373

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jetBrainsChannel=stable
55
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
66
# if plugin uses intellij-common-ui-test library, 'platformType' and 'platformVersion' variables names MUST be used
77
# platformType = IC (not needed as hard-coded in gradle build directly)
8-
platformVersion=2024.2
8+
platformVersion=2024.3
99

1010
# Gradle Releases -> https://github.com/gradle/gradle/releases
1111
gradleVersion=8.5

gradle/libs.versions.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[versions]
22
# libraries
3-
kubernetes-client = "6.12.0"
3+
kubernetes-client = "7.0.0"
44
devtools-common = "1.9.7-SNAPSHOT"
55
jackson-core = "2.17.0"
66
commons-lang3 = "3.12.0"
77
assertj-core = "3.22.0"
8-
mockito-inline = "4.5.1"
8+
mockito = "5.12.0"
99
mockito-kotlin = "2.2.0"
1010
devtools-common-ui-test = "0.4.2"
1111
junit-platform = "1.10.3"
@@ -19,15 +19,15 @@ kotlinJvm = "2.0.20"
1919
[libraries]
2020
openshift-client = { group = "io.fabric8", name = "openshift-client", version.ref = "kubernetes-client" }
2121
kubernetes-client = { group = "io.fabric8", name = "kubernetes-client", version.ref = "kubernetes-client" }
22-
kubernetes-model = { group = "io.fabric8", name = "kubernetes-model", version.ref = "kubernetes-client" }
22+
kubernetes-model = { group = "io.fabric8", name = "kubernetes-model-core", version.ref = "kubernetes-client" }
2323
kubernetes-model-common = { group = "io.fabric8", name = "kubernetes-model-common", version.ref = "kubernetes-client" }
2424
kubernetes-httpclient-okhttp = { group = "io.fabric8", name = "kubernetes-httpclient-okhttp", version.ref = "kubernetes-client" }
2525
devtools-common = { group = "com.redhat.devtools.intellij", name = "intellij-common", version.ref = "devtools-common" }
2626
jackson-core = { group = "com.fasterxml.jackson.core", name = "jackson-core", version.ref = "jackson-core" }
2727
commons-lang3 = { group = "org.apache.commons", name = "commons-lang3", version.ref = "commons-lang3" }
2828
kotlin-test-junit = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit", version.ref = "kotlinJvm" }
2929
assertj-core = { group = "org.assertj", name = "assertj-core", version.ref = "assertj-core" }
30-
mockito-inline = { group = "org.mockito", name = "mockito-inline", version.ref = "mockito-inline" }
30+
mockito = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" }
3131
mockito-kotlin = { group = "com.nhaarman.mockitokotlin2", name = "mockito-kotlin", version.ref = "mockito-kotlin" }
3232
devtools-common-ui-test = { group = "com.redhat.devtools.intellij", name = "intellij-common-ui-test-library", version.ref = "devtools-common-ui-test" }
3333
junit-platform-launcher = { group = "org.junit.platform", name = "junit-platform-launcher", version.ref = "junit-platform" }

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

+12-19
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ package com.redhat.devtools.intellij.kubernetes.model
1212

1313
import com.intellij.openapi.application.ApplicationManager
1414
import com.intellij.openapi.diagnostic.logger
15-
import com.redhat.devtools.intellij.common.utils.ConfigHelper
1615
import com.redhat.devtools.intellij.common.utils.ConfigWatcher
1716
import com.redhat.devtools.intellij.common.utils.ExecHelper
1817
import com.redhat.devtools.intellij.kubernetes.model.client.ClientAdapter
@@ -30,7 +29,6 @@ import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.PROP_O
3029
import io.fabric8.kubernetes.api.model.HasMetadata
3130
import io.fabric8.kubernetes.client.Config
3231
import io.fabric8.kubernetes.client.KubernetesClient
33-
import java.nio.file.Paths
3432
import java.util.concurrent.CompletionException
3533
import java.util.concurrent.locks.ReentrantReadWriteLock
3634
import kotlin.concurrent.read
@@ -83,11 +81,13 @@ open class AllContexts(
8381
namespace: String?,
8482
context: String?
8583
) -> ClientAdapter<out KubernetesClient>
86-
= { namespace, context -> ClientAdapter.Factory.create(namespace, context) }
84+
= { namespace, config ->
85+
ClientAdapter.Factory.create(namespace, config)
86+
}
8787
) : IAllContexts {
8888

8989
init {
90-
watchKubeConfig()
90+
watchKubeConfigs()
9191
}
9292

9393
private val lock = ReentrantReadWriteLock()
@@ -148,7 +148,8 @@ open class AllContexts(
148148
) : IActiveContext<out HasMetadata, out KubernetesClient>? {
149149
lock.write {
150150
try {
151-
replaceClient(newClient, this.client.get())
151+
client.get()?.close()
152+
client.set(newClient)
152153
newClient.config.save().join()
153154
current?.close()
154155
clearAllContexts() // causes reload of all contexts when accessed afterwards
@@ -204,13 +205,6 @@ open class AllContexts(
204205
}
205206
}
206207

207-
private fun replaceClient(new: ClientAdapter<out KubernetesClient>, old: ClientAdapter<out KubernetesClient>?)
208-
: ClientAdapter<out KubernetesClient> {
209-
old?.close()
210-
this.client.set(new)
211-
return new
212-
}
213-
214208
private fun createActiveContext(client: ClientAdapter<out KubernetesClient>?)
215209
: IActiveContext<out HasMetadata, out KubernetesClient>? {
216210
if (client == null) {
@@ -241,8 +235,7 @@ open class AllContexts(
241235
}
242236
}
243237

244-
protected open fun watchKubeConfig() {
245-
val path = Paths.get(Config.getKubeconfigFilename())
238+
protected open fun watchKubeConfigs() {
246239
/**
247240
* [ConfigWatcher] cannot add/remove listeners nor can it get closed (and stop the [java.nio.file.WatchService]).
248241
* We therefore have to create a single instance in here rather than using it in a shielded/private way within
@@ -251,16 +244,16 @@ open class AllContexts(
251244
* The latter gets closed/recreated whenever the context changes in
252245
* [com.redhat.devtools.intellij.kubernetes.model.client.KubeConfigAdapter].
253246
*/
254-
val watcher = ConfigWatcher(path) { _, config: io.fabric8.kubernetes.api.model.Config? -> onKubeConfigChanged(config) }
247+
val watcher = ConfigWatcher { config: Config? -> onKubeConfigChanged(config) }
255248
runAsync(watcher::run)
256249
}
257250

258-
protected open fun onKubeConfigChanged(fileConfig: io.fabric8.kubernetes.api.model.Config?) {
251+
protected open fun onKubeConfigChanged(updated: Config?) {
259252
lock.read {
260-
fileConfig ?: return
253+
updated ?: return
261254
val client = client.get() ?: return
262-
val clientConfig = client.config.configuration
263-
if (ConfigHelper.areEqual(fileConfig, clientConfig)) {
255+
val existing = client.config
256+
if (existing.isEqualConfig(updated)) {
264257
return
265258
}
266259
this.client.reset() // create new client when accessed

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

+13-28
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ open class OSClientAdapter(client: OpenShiftClient, private val kubeClient: Kube
3333

3434
override val config by lazy {
3535
// openshift client configuration does not have kube config entries
36-
ClientConfig(kubeClient)
36+
ClientConfig(kubeClient.configuration)
3737
}
3838

3939
override fun isOpenShift(): Boolean {
@@ -56,47 +56,32 @@ open class KubeClientAdapter(client: KubernetesClient) :
5656
abstract class ClientAdapter<C : KubernetesClient>(private val fabric8Client: C) {
5757

5858
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-
}
6959

7060
fun create(
7161
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
7666
): ClientAdapter<out KubernetesClient> {
67+
val config = createConfig.invoke(context)
7768
setNamespace(namespace, config)
78-
val kubeClient = clientBuilder
69+
val builder = clientBuilder ?: KubernetesClientBuilder()
70+
val trustManager = externalTrustManagerProvider ?: IDEATrustManager()::configure
71+
val kubeClient = builder
7972
.withConfig(config)
80-
.withHttpClientBuilderConsumer { builder ->
81-
setSslContext(builder, config, externalTrustManagerProvider)
73+
.withHttpClientBuilderConsumer { httpClientBuilder ->
74+
setSslContext(httpClientBuilder, config, trustManager)
8275
}
8376
.build()
84-
return if (isOpenShift(kubeClient)) {
77+
return if (ClusterHelper.isOpenShift(kubeClient)) {
8578
val osClient = kubeClient.adapt(NamespacedOpenShiftClient::class.java)
8679
OSClientAdapter(osClient, kubeClient)
8780
} else {
8881
KubeClientAdapter(kubeClient)
8982
}
9083
}
9184

92-
private fun isOpenShift(client: KubernetesClient): Boolean {
93-
return try {
94-
ClusterHelper.isOpenShift(client)
95-
} catch (e: Exception) {
96-
false;
97-
}
98-
}
99-
10085
private fun setSslContext(
10186
builder: HttpClient.Builder,
10287
config: Config,
@@ -124,7 +109,7 @@ abstract class ClientAdapter<C : KubernetesClient>(private val fabric8Client: C)
124109
private val clients = ConcurrentHashMap<Class<out Client>, Client>()
125110

126111
open val config by lazy {
127-
ClientConfig(fabric8Client)
112+
ClientConfig(fabric8Client.configuration)
128113
}
129114

130115
abstract fun isOpenShift(): Boolean

0 commit comments

Comments
 (0)