Skip to content

Commit c939a3d

Browse files
authored
Update to io.kubernetes:client-java:23. Adapt code to the breaking changes introduced in io.kubernetes:client-java:20 (#111)
Signed-off-by: Artem Zatsarynnyi <[email protected]>
1 parent b9bf8ca commit c939a3d

File tree

6 files changed

+40
-69
lines changed

6 files changed

+40
-69
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
.qodana
44
build
55
.DS_Store
6+
.intellijPlatform/
7+
.kotlin/

build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ dependencies {
4343
// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file for plugin from JetBrains Marketplace.
4444
plugins(providers.gradleProperty("platformPlugins").map { it.split(',') })
4545

46-
instrumentationTools()
4746
pluginVerifier()
4847
zipSigner()
4948
testFramework(TestFrameworkType.JUnit5)
5049
}
5150

52-
implementation("io.kubernetes:client-java:18.0.1")
51+
implementation("io.kubernetes:client-java:23.0.0")
5352
}
5453

5554
// Configure IntelliJ Platform Gradle Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pluginUntilBuild = 243.*
1313
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
1414
platformType = GW
1515
#https://www.jetbrains.com/updates/updates.xml
16-
platformVersion = 243.21155.27
16+
platformVersion = 2024.3.3
1717

1818
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
1919
# Example: platformPlugins = com.jetbrains.php:203.4449.22, org.intellij.scala:2023.3.27@EAP

src/main/kotlin/com/redhat/devtools/gateway/openshift/DevWorkspaces.kt

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
package com.redhat.devtools.gateway.openshift
1313

1414
import com.google.gson.reflect.TypeToken
15+
import io.kubernetes.client.custom.V1Patch
1516
import io.kubernetes.client.openapi.ApiClient
1617
import io.kubernetes.client.openapi.ApiException
1718
import io.kubernetes.client.openapi.apis.CustomObjectsApi
19+
import io.kubernetes.client.util.PatchUtils
1820
import io.kubernetes.client.util.Watch
1921
import java.io.IOException
2022
import java.util.concurrent.Executors
@@ -36,18 +38,8 @@ class DevWorkspaces(private val client: ApiClient) {
3638
"workspace.devfile.io",
3739
"v1alpha2",
3840
namespace,
39-
"devworkspaces",
40-
"false",
41-
false,
42-
"",
43-
"",
44-
"",
45-
-1,
46-
"",
47-
"",
48-
-1,
49-
false
50-
)
41+
"devworkspaces"
42+
).execute()
5143

5244
val dwItems = Utils.getValue(response, arrayOf("items")) as List<*>
5345
return dwItems
@@ -64,7 +56,7 @@ class DevWorkspaces(private val client: ApiClient) {
6456
namespace,
6557
"devworkspaces",
6658
name
67-
)
59+
).execute()
6860
return DevWorkspace.from(dwObj)
6961
}
7062

@@ -120,45 +112,43 @@ class DevWorkspaces(private val client: ApiClient) {
120112
return phaseIsDesiredState
121113
}
122114

115+
// Example:
116+
// https://github.com/kubernetes-client/java/blob/master/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PatchExample.java
123117
@Throws(ApiException::class)
124118
private fun doPatch(namespace: String, name: String, body: Any) {
125119
val customApi = CustomObjectsApi(client)
126-
customApi.patchNamespacedCustomObject(
127-
"workspace.devfile.io",
128-
"v1alpha2",
129-
namespace,
130-
"devworkspaces",
131-
name,
132-
body,
133-
null,
134-
null,
135-
null
120+
PatchUtils.patch(
121+
DevWorkspace.javaClass,
122+
{
123+
customApi.patchNamespacedCustomObject(
124+
"workspace.devfile.io",
125+
"v1alpha2",
126+
namespace,
127+
"devworkspaces",
128+
name,
129+
body
130+
).buildCall(null)
131+
},
132+
V1Patch.PATCH_FORMAT_JSON_PATCH,
133+
customApi.apiClient
136134
)
137135
}
138136

139137
// Example:
140-
// https://github.com/kubernetes-client/java/blob/master/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/WatchExample.java
138+
// https://github.com/kubernetes-client/java/blob/master/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/WatchExample.java
141139
private fun createWatcher(namespace: String, fieldSelector: String = "", labelSelector: String = ""): Watch<Any> {
142140
val customObjectsApi = CustomObjectsApi(client)
143141
return Watch.createWatch(
144142
client,
145-
customObjectsApi.listNamespacedCustomObjectCall(
143+
customObjectsApi.listNamespacedCustomObject(
146144
"workspace.devfile.io",
147145
"v1alpha2",
148146
namespace,
149-
"devworkspaces",
150-
"false",
151-
false,
152-
"",
153-
fieldSelector,
154-
labelSelector,
155-
-1,
156-
"",
157-
"",
158-
0,
159-
true,
160-
null
161-
),
147+
"devworkspaces"
148+
).fieldSelector(fieldSelector)
149+
.labelSelector(labelSelector)
150+
.watch(true)
151+
.buildCall(null),
162152
object : TypeToken<Watch.Response<Any>>() {}.type
163153
)
164154
}

src/main/kotlin/com/redhat/devtools/gateway/openshift/Pods.kt

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ import java.net.ServerSocket
2828
import java.net.Socket
2929
import java.nio.channels.*
3030

31-
3231
class Pods(private val client: ApiClient) {
3332

3433
// Example:
35-
// https://github.com/kubernetes-client/java/blob/master/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ExecExample.java
34+
// https://github.com/kubernetes-client/java/blob/master/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ExecExample.java
3635
@Throws(IOException::class)
3736
fun exec(pod: V1Pod, command: Array<String>, container: String): String {
3837
val output = ByteArrayOutputStream()
@@ -52,7 +51,7 @@ class Pods(private val client: ApiClient) {
5251
}
5352

5453
// Example:
55-
// https://github.com/kubernetes-client/java/blob/master/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PortForwardExample.java
54+
// https://github.com/kubernetes-client/java/blob/master/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PortForwardExample.java
5655
@Throws(IOException::class)
5756
fun forward(pod: V1Pod, localPort: Int, remotePort: Int): Closeable {
5857
val serverSocket = ServerSocket(localPort, 50, InetAddress.getLoopbackAddress())
@@ -121,18 +120,9 @@ class Pods(private val client: ApiClient) {
121120

122121
@Throws(ApiException::class)
123122
private fun doList(namespace: String, labelSelector: String = ""): V1PodList {
124-
return CoreV1Api(client).listNamespacedPod(
125-
namespace,
126-
"false",
127-
false,
128-
"",
129-
"",
130-
labelSelector,
131-
-1,
132-
"",
133-
"",
134-
-1,
135-
false
136-
)
123+
return CoreV1Api(client)
124+
.listNamespacedPod(namespace)
125+
.labelSelector(labelSelector)
126+
.execute();
137127
}
138128
}

src/main/kotlin/com/redhat/devtools/gateway/openshift/Projects.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,8 @@ class Projects(private val client: ApiClient) {
2222
val response = customApi.listClusterCustomObject(
2323
"project.openshift.io",
2424
"v1",
25-
"projects",
26-
"false",
27-
false,
28-
"",
29-
"",
30-
"",
31-
-1,
32-
"",
33-
"",
34-
-1,
35-
false
36-
) as Map<*, *>
25+
"projects"
26+
).execute() as Map<*, *>
3727

3828
return response["items"] as List<*>
3929
}

0 commit comments

Comments
 (0)