From c8709c0aec15caa9d26febdd54900e3f8bb33f16 Mon Sep 17 00:00:00 2001 From: msivasubramaniaan Date: Thu, 18 Jun 2026 14:40:31 +0530 Subject: [PATCH 1/4] filter if resourceVersion is null and resolved warnings Signed-off-by: msivasubramaniaan --- .../gateway/devworkspace/DevWorkspaceWatcher.kt | 11 +++-------- .../view/steps/DevSpacesWorkspacesStepView.kt | 12 +++++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaceWatcher.kt b/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaceWatcher.kt index bb477666..7804e9ff 100644 --- a/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaceWatcher.kt +++ b/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaceWatcher.kt @@ -12,9 +12,6 @@ package com.redhat.devtools.gateway.devworkspace import com.intellij.openapi.application.EDT -import com.redhat.devtools.gateway.openshift.Projects -import com.redhat.devtools.gateway.openshift.Utils -import io.kubernetes.client.openapi.ApiClient import io.kubernetes.client.util.Watch import kotlinx.coroutines.* @@ -82,7 +79,6 @@ class DevWorkspaceWatcher( } class DevWorkspaceWatchManager( - private val client: ApiClient, private val createWatcher: (String, String?) -> Watch, private val createFilter: (String) -> ((DevWorkspace) -> Boolean), private val listener: DevWorkspaceListener, @@ -90,9 +86,8 @@ class DevWorkspaceWatchManager( ) { private val watchers = mutableListOf() - fun start(lastResourceVersions: Map? = null) { - Projects(client).list().onEach { project -> - val ns = Utils.getValue(project, arrayOf("metadata","name")) as String + fun start(lastResourceVersions: Map = emptyMap()) { + lastResourceVersions.forEach { (ns, resourceVersion) -> val w = DevWorkspaceWatcher( namespace = ns, createWatcher = createWatcher, @@ -101,7 +96,7 @@ class DevWorkspaceWatchManager( scope = scope ) watchers += w - w.start(lastResourceVersions?.get(ns)) + w.start(resourceVersion) } } diff --git a/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesWorkspacesStepView.kt b/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesWorkspacesStepView.kt index 98990592..fbd5702c 100644 --- a/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesWorkspacesStepView.kt +++ b/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesWorkspacesStepView.kt @@ -17,7 +17,6 @@ import com.intellij.openapi.application.invokeLater import com.intellij.openapi.application.runInEdt import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.progress.ProgressManager -import com.intellij.openapi.ui.MessageDialogBuilder import com.intellij.openapi.util.Disposer import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager import com.intellij.ui.ColoredListCellRenderer @@ -143,7 +142,7 @@ class DevSpacesWorkspacesStepView( return false } devSpacesContext.devWorkspace = workspace - val serverStatus = try { + try { getServerStatus() } catch (e: Exception) { if (e.isCancellationException()) { @@ -205,7 +204,11 @@ class DevSpacesWorkspacesStepView( .map { Utils.getValue(it, arrayOf("metadata", "name")) as String } .flatMap { namespace -> val dwListResult = DevWorkspaces(devSpacesContext.client).listWithResult(namespace) - lastResourceVersions[namespace] = dwListResult.resourceVersion + + dwListResult.resourceVersion?.let { rv -> + lastResourceVersions[namespace] = rv + } + dwListResult.items } @@ -503,12 +506,11 @@ class DevSpacesWorkspacesStepView( } private class WorkspacesWatch( - private val client: ApiClient, + client: ApiClient, private val workspacesDataModel: DefaultListModel ) { private val devWorkspaces = DevWorkspaces(client) private val watchManager = DevWorkspaceWatchManager( - client = client, createWatcher = { ns, latestResourceVersion -> devWorkspaces.createWatcher(ns, latestResourceVersion = latestResourceVersion) }, From ed78286aac0648367530c4f60ca15727bdc47400 Mon Sep 17 00:00:00 2001 From: msivasubramaniaan Date: Thu, 18 Jun 2026 15:43:33 +0530 Subject: [PATCH 2/4] filter if resourceVersion is null and resolved warnings Signed-off-by: msivasubramaniaan --- .../devworkspace/DevWorkspaceWatcher.kt | 6 ++- .../gateway/devworkspace/DevWorkspaces.kt | 53 +++++++++++-------- .../view/steps/DevSpacesWorkspacesStepView.kt | 20 +++---- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaceWatcher.kt b/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaceWatcher.kt index 7804e9ff..99f46dca 100644 --- a/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaceWatcher.kt +++ b/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaceWatcher.kt @@ -88,6 +88,9 @@ class DevWorkspaceWatchManager( fun start(lastResourceVersions: Map = emptyMap()) { lastResourceVersions.forEach { (ns, resourceVersion) -> + if (resourceVersion == null) { + return@forEach + } val w = DevWorkspaceWatcher( namespace = ns, createWatcher = createWatcher, @@ -104,5 +107,4 @@ class DevWorkspaceWatchManager( watchers.forEach { it.stop() } watchers.clear() } -} - +} \ No newline at end of file diff --git a/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt b/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt index 3680221b..accca111 100644 --- a/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt +++ b/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt @@ -12,8 +12,8 @@ package com.redhat.devtools.gateway.devworkspace import com.google.gson.reflect.TypeToken -import com.redhat.devtools.gateway.openshift.Utils import com.intellij.openapi.diagnostic.thisLogger +import com.redhat.devtools.gateway.openshift.Utils import io.kubernetes.client.openapi.ApiClient import io.kubernetes.client.openapi.ApiException import io.kubernetes.client.openapi.apis.CustomObjectsApi @@ -23,7 +23,6 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeoutOrNull import java.io.IOException import java.util.concurrent.CancellationException -import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds data class DevWorkspaceListResult( @@ -140,28 +139,38 @@ class DevWorkspaces(private val client: ApiClient) { // Returns a map of DW Owner UID tp list of DW Templates private fun getTemplateMap(namespace: String): Map> { - val dwTemplateList = customApi - .listNamespacedCustomObject( - "workspace.devfile.io", - "v1alpha2", - namespace, - "devworkspacetemplates", - ) - .execute() - - val items = Utils.getValue(dwTemplateList, arrayOf("items")) as? List<*> ?: emptyList() - return items - .map { DevWorkspaceTemplate.from(it) } - .flatMap { templ -> - templ.ownerRefencesUids.map { uid -> uid to templ } + try { + val dwTemplateList = customApi + .listNamespacedCustomObject( + "workspace.devfile.io", + "v1alpha2", + namespace, + "devworkspacetemplates", + ) + .execute() + + val items = Utils.getValue(dwTemplateList, arrayOf("items")) as? List<*> ?: emptyList() + return items + .map { DevWorkspaceTemplate.from(it) } + .flatMap { templ -> + templ.ownerRefencesUids.map { uid -> uid to templ } + } + .groupBy( + keySelector = { it.first }, // UID + valueTransform = { it.second } // DevWorkspaceTemplate + ) + } catch (e: ApiException) { + thisLogger().info(e.message) + + if (e.code == 403) { + return emptyMap() } - .groupBy( - keySelector = { it.first }, // UID - valueTransform = { it.second } // DevWorkspaceTemplate - ) + + throw e + } } - @Throws(ApiException::class) +@Throws(ApiException::class) fun start(namespace: String, name: String) { DevWorkspacePatch(namespace, name, client) { get(namespace, name) @@ -276,7 +285,7 @@ class DevWorkspaces(private val client: ApiClient) { val devWorkspace = try { DevWorkspaces(client).get(namespace, name) - } catch (e: Exception) { + } catch (_: Exception) { delay(1.seconds) continue } diff --git a/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesWorkspacesStepView.kt b/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesWorkspacesStepView.kt index fbd5702c..274153ca 100644 --- a/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesWorkspacesStepView.kt +++ b/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesWorkspacesStepView.kt @@ -86,10 +86,10 @@ class DevSpacesWorkspacesStepView( row { cell(JBScrollPane(listDevWorkspaces) - .apply { - preferredSize = Dimension(preferredSize.width, 200) - minimumSize = Dimension(minimumSize.width, 100) - }) + .apply { + preferredSize = Dimension(preferredSize.width, 200) + minimumSize = Dimension(minimumSize.width, 100) + }) .align(AlignX.FILL) .align(AlignY.FILL) }.resizableRow().bottomGap(BottomGap.MEDIUM) @@ -204,11 +204,7 @@ class DevSpacesWorkspacesStepView( .map { Utils.getValue(it, arrayOf("metadata", "name")) as String } .flatMap { namespace -> val dwListResult = DevWorkspaces(devSpacesContext.client).listWithResult(namespace) - - dwListResult.resourceVersion?.let { rv -> - lastResourceVersions[namespace] = rv - } - + lastResourceVersions[namespace] = dwListResult.resourceVersion dwListResult.items } @@ -345,7 +341,7 @@ class DevSpacesWorkspacesStepView( } } - private fun connect() { + private fun connect() { ProgressManager.getInstance().runProcessWithProgressSynchronously( { try { @@ -506,7 +502,7 @@ class DevSpacesWorkspacesStepView( } private class WorkspacesWatch( - client: ApiClient, + private val client: ApiClient, private val workspacesDataModel: DefaultListModel ) { private val devWorkspaces = DevWorkspaces(client) @@ -577,4 +573,4 @@ class DevSpacesWorkspacesStepView( watchManager.stop() } } -} +} \ No newline at end of file From 8661b7adfb7e38cf576841169f7a0ed334f8537a Mon Sep 17 00:00:00 2001 From: msivasubramaniaan Date: Thu, 18 Jun 2026 16:08:52 +0530 Subject: [PATCH 3/4] revert warning Signed-off-by: msivasubramaniaan --- .../com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt b/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt index accca111..44f8029d 100644 --- a/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt +++ b/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt @@ -285,7 +285,7 @@ class DevWorkspaces(private val client: ApiClient) { val devWorkspace = try { DevWorkspaces(client).get(namespace, name) - } catch (_: Exception) { + } catch (e: Exception) { delay(1.seconds) continue } From 261f579a0ce1e6dff42dc01ae79fa4ca77eda792 Mon Sep 17 00:00:00 2001 From: msivasubramaniaan Date: Thu, 18 Jun 2026 16:25:53 +0530 Subject: [PATCH 4/4] fixed review comments by coderabbitai Signed-off-by: msivasubramaniaan --- .../devtools/gateway/devworkspace/DevWorkspaces.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt b/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt index 44f8029d..87fa26c6 100644 --- a/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt +++ b/src/main/kotlin/com/redhat/devtools/gateway/devworkspace/DevWorkspaces.kt @@ -249,9 +249,12 @@ class DevWorkspaces(private val client: ApiClient) { checkCancelled?.invoke() val devWorkspace = try { DevWorkspaces(client).get(namespace, name) - } catch (_: Exception) { - delay(1.seconds) - continue + } catch (e: ApiException) { + if (e.code in setOf(429, 500, 502, 503, 504)) { + delay(1.seconds) + continue + } + throw e } checkCancelled?.invoke()