diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt index d3440bf58..edf978616 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt @@ -126,7 +126,6 @@ open class AllContexts( override fun setCurrentNamespace(namespace: String): IActiveContext? { val old = this.current ?: return null val newClient = clientFactory.invoke(namespace, old.context.name) - throwIfNotAccessible(namespace, newClient.get()) val new = setCurrentContext(newClient, old.getWatched()) if (new != null) { modelChange.fireCurrentNamespaceChanged(new, old) diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/context/ActiveContext.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/context/ActiveContext.kt index 2a2351819..2208a1d0f 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/context/ActiveContext.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/context/ActiveContext.kt @@ -119,9 +119,16 @@ abstract class ActiveContext( return if (!current.isNullOrEmpty()) { current } else { - val allNamespaces = getAllResources(namespaceKind, NO_NAMESPACE) - val namespace = allNamespaces.find { namespace:HasMetadata -> DEFAULT_NAMESPACE == namespace.metadata.name } ?: allNamespaces.firstOrNull() - return namespace?.metadata?.name + return try { + val allNamespaces = getAllResources(namespaceKind, NO_NAMESPACE) + val namespace = + allNamespaces.find { namespace: HasMetadata -> DEFAULT_NAMESPACE == namespace.metadata.name } + ?: allNamespaces.firstOrNull() + namespace?.metadata?.name + } catch (e: ResourceException) { + logger>().warn("Could not list all namespaces to use 1st as current namespace.", e) + null + } } } diff --git a/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt b/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt index e3ede0a1a..df5cbc036 100644 --- a/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt +++ b/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt @@ -384,20 +384,6 @@ class AllContextsTest { assertThat(contextName.allValues[1]).isEqualTo(activeContext.context.name) } - @Test(expected = ResourceException::class) - fun `#setCurrentNamespace(namespace) should throw if current namespace is forbidden`() { - // given - val client = client(KubernetesClientException("a disturbance in the force")) // throws upon client#namespaces - val clientConfig = clientConfig(currentContext, contexts, configuration) - val clientAdapter = clientAdapter(clientConfig, client) // no config so there are no contexts - val clientFactory = clientFactory(clientAdapter) - val allContexts = TestableAllContexts(modelChange, contextFactory, clientFactory) - // when - allContexts.setCurrentNamespace("dark side") - // then - verify(modelChange, never()).fireCurrentNamespaceChanged(anyOrNull(), anyOrNull()) - } - @Test fun `#onKubeConfigChanged() should NOT fire if new config is null`() { // given