Skip to content

Commit

Permalink
fix: bump kubernetes-client to 7.0.0 (#794)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Jan 13, 2025
1 parent 719d72c commit 52ad428
Show file tree
Hide file tree
Showing 14 changed files with 620 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/IJ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
IJ: [2023.1, 2023.2, 2023.3, 2024.1, 2024.2]
IJ: [2023.1, 2023.2, 2023.3, 2024.1, 2024.2, 2024.3]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies {

// for unit tests
testImplementation(libs.assertj.core)
testImplementation(libs.mockito.inline)
testImplementation(libs.mockito)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.kotlin.test.junit)

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jetBrainsChannel=stable
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
# if plugin uses intellij-common-ui-test library, 'platformType' and 'platformVersion' variables names MUST be used
# platformType = IC (not needed as hard-coded in gradle build directly)
platformVersion=2024.2
platformVersion=2024.3

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion=8.5
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]
# libraries
kubernetes-client = "6.12.0"
kubernetes-client = "7.0.0"
devtools-common = "1.9.7-SNAPSHOT"
jackson-core = "2.17.0"
commons-lang3 = "3.12.0"
assertj-core = "3.22.0"
mockito-inline = "4.5.1"
mockito = "5.12.0"
mockito-kotlin = "2.2.0"
devtools-common-ui-test = "0.4.2"
junit-platform = "1.10.3"
Expand All @@ -19,15 +19,15 @@ kotlinJvm = "2.0.20"
[libraries]
openshift-client = { group = "io.fabric8", name = "openshift-client", version.ref = "kubernetes-client" }
kubernetes-client = { group = "io.fabric8", name = "kubernetes-client", version.ref = "kubernetes-client" }
kubernetes-model = { group = "io.fabric8", name = "kubernetes-model", version.ref = "kubernetes-client" }
kubernetes-model = { group = "io.fabric8", name = "kubernetes-model-core", version.ref = "kubernetes-client" }
kubernetes-model-common = { group = "io.fabric8", name = "kubernetes-model-common", version.ref = "kubernetes-client" }
kubernetes-httpclient-okhttp = { group = "io.fabric8", name = "kubernetes-httpclient-okhttp", version.ref = "kubernetes-client" }
devtools-common = { group = "com.redhat.devtools.intellij", name = "intellij-common", version.ref = "devtools-common" }
jackson-core = { group = "com.fasterxml.jackson.core", name = "jackson-core", version.ref = "jackson-core" }
commons-lang3 = { group = "org.apache.commons", name = "commons-lang3", version.ref = "commons-lang3" }
kotlin-test-junit = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit", version.ref = "kotlinJvm" }
assertj-core = { group = "org.assertj", name = "assertj-core", version.ref = "assertj-core" }
mockito-inline = { group = "org.mockito", name = "mockito-inline", version.ref = "mockito-inline" }
mockito = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" }
mockito-kotlin = { group = "com.nhaarman.mockitokotlin2", name = "mockito-kotlin", version.ref = "mockito-kotlin" }
devtools-common-ui-test = { group = "com.redhat.devtools.intellij", name = "intellij-common-ui-test-library", version.ref = "devtools-common-ui-test" }
junit-platform-launcher = { group = "org.junit.platform", name = "junit-platform-launcher", version.ref = "junit-platform" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package com.redhat.devtools.intellij.kubernetes.model

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.logger
import com.redhat.devtools.intellij.common.utils.ConfigHelper
import com.redhat.devtools.intellij.common.utils.ConfigWatcher
import com.redhat.devtools.intellij.common.utils.ExecHelper
import com.redhat.devtools.intellij.kubernetes.model.client.ClientAdapter
Expand All @@ -30,7 +29,6 @@ import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.PROP_O
import io.fabric8.kubernetes.api.model.HasMetadata
import io.fabric8.kubernetes.client.Config
import io.fabric8.kubernetes.client.KubernetesClient
import java.nio.file.Paths
import java.util.concurrent.CompletionException
import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.read
Expand Down Expand Up @@ -83,11 +81,13 @@ open class AllContexts(
namespace: String?,
context: String?
) -> ClientAdapter<out KubernetesClient>
= { namespace, context -> ClientAdapter.Factory.create(namespace, context) }
= { namespace, config ->
ClientAdapter.Factory.create(namespace, config)
}
) : IAllContexts {

init {
watchKubeConfig()
watchKubeConfigs()
}

private val lock = ReentrantReadWriteLock()
Expand Down Expand Up @@ -148,7 +148,8 @@ open class AllContexts(
) : IActiveContext<out HasMetadata, out KubernetesClient>? {
lock.write {
try {
replaceClient(newClient, this.client.get())
client.get()?.close()
client.set(newClient)
newClient.config.save().join()
current?.close()
clearAllContexts() // causes reload of all contexts when accessed afterwards
Expand Down Expand Up @@ -204,13 +205,6 @@ open class AllContexts(
}
}

private fun replaceClient(new: ClientAdapter<out KubernetesClient>, old: ClientAdapter<out KubernetesClient>?)
: ClientAdapter<out KubernetesClient> {
old?.close()
this.client.set(new)
return new
}

private fun createActiveContext(client: ClientAdapter<out KubernetesClient>?)
: IActiveContext<out HasMetadata, out KubernetesClient>? {
if (client == null) {
Expand Down Expand Up @@ -241,8 +235,7 @@ open class AllContexts(
}
}

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

protected open fun onKubeConfigChanged(fileConfig: io.fabric8.kubernetes.api.model.Config?) {
protected open fun onKubeConfigChanged(updated: Config?) {
lock.read {
fileConfig ?: return
updated ?: return
val client = client.get() ?: return
val clientConfig = client.config.configuration
if (ConfigHelper.areEqual(fileConfig, clientConfig)) {
val existing = client.config
if (existing.isEqualConfig(updated)) {
return
}
this.client.reset() // create new client when accessed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ open class OSClientAdapter(client: OpenShiftClient, private val kubeClient: Kube

override val config by lazy {
// openshift client configuration does not have kube config entries
ClientConfig(kubeClient)
ClientConfig(kubeClient.configuration)
}

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

companion object Factory {
fun create(
namespace: String? = null,
context: String? = null,
clientBuilder: KubernetesClientBuilder = KubernetesClientBuilder(),
trustManagerProvider: ((toIntegrate: List<X509ExtendedTrustManager>) -> X509TrustManager)
= IDEATrustManager()::configure
): ClientAdapter<out KubernetesClient> {
val config = Config.autoConfigure(context)
return create(namespace, config, clientBuilder, trustManagerProvider)
}

fun create(
namespace: String? = null,
config: Config,
clientBuilder: KubernetesClientBuilder,
externalTrustManagerProvider: (toIntegrate: List<X509ExtendedTrustManager>) -> X509TrustManager
= IDEATrustManager()::configure
context: String? = null,
clientBuilder: KubernetesClientBuilder? = null,
createConfig: (context: String?) -> Config = { context -> Config.autoConfigure(context) },
externalTrustManagerProvider: ((toIntegrate: List<X509ExtendedTrustManager>) -> X509TrustManager)? = null
): ClientAdapter<out KubernetesClient> {
val config = createConfig.invoke(context)
setNamespace(namespace, config)
val kubeClient = clientBuilder
val builder = clientBuilder ?: KubernetesClientBuilder()
val trustManager = externalTrustManagerProvider ?: IDEATrustManager()::configure
val kubeClient = builder
.withConfig(config)
.withHttpClientBuilderConsumer { builder ->
setSslContext(builder, config, externalTrustManagerProvider)
.withHttpClientBuilderConsumer { httpClientBuilder ->
setSslContext(httpClientBuilder, config, trustManager)
}
.build()
return if (isOpenShift(kubeClient)) {
return if (ClusterHelper.isOpenShift(kubeClient)) {
val osClient = kubeClient.adapt(NamespacedOpenShiftClient::class.java)
OSClientAdapter(osClient, kubeClient)
} else {
KubeClientAdapter(kubeClient)
}
}

private fun isOpenShift(client: KubernetesClient): Boolean {
return try {
ClusterHelper.isOpenShift(client)
} catch (e: Exception) {
false;
}
}

private fun setSslContext(
builder: HttpClient.Builder,
config: Config,
Expand Down Expand Up @@ -124,7 +109,7 @@ abstract class ClientAdapter<C : KubernetesClient>(private val fabric8Client: C)
private val clients = ConcurrentHashMap<Class<out Client>, Client>()

open val config by lazy {
ClientConfig(fabric8Client)
ClientConfig(fabric8Client.configuration)
}

abstract fun isOpenShift(): Boolean
Expand Down
Loading

0 comments on commit 52ad428

Please sign in to comment.