From 9539075746d62a3e6cac39e5fc8982f1d14311b2 Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Tue, 30 Jan 2024 19:21:06 +0100 Subject: [PATCH] fix: report 'cluster unreachable' instead of 'failed to list secrets' (#682) Signed-off-by: Andre Dietisheim --- .../application/ApplicationsTreeStructure.java | 4 ++++ .../utils/KubernetesClientExceptionUtils.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationsTreeStructure.java b/src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationsTreeStructure.java index 41256c35a..dc1110a25 100644 --- a/src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationsTreeStructure.java +++ b/src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationsTreeStructure.java @@ -51,6 +51,7 @@ public class ApplicationsTreeStructure extends AbstractTreeStructure implements private final DevfileRegistriesNode registries; private static final String LOGIN = "Please log in to the cluster"; + private static final String CLUSTER_UNREACHABLE = "Error: Cluster not reachable"; public ApplicationsTreeStructure(Project project) { this.project = project; @@ -173,6 +174,9 @@ private MessageNode createErrorNode(ParentableNode parent, Exception e) { return new MessageNode<>(root, parent, kce.getCause().getMessage()); } else if (kce.getCause().getMessage().contains(Constants.DEFAULT_KUBE_URL)) { return new MessageNode<>(root, parent, LOGIN); + } else if (KubernetesClientExceptionUtils.isHostDown(kce) + || KubernetesClientExceptionUtils.isConnectionReset(kce)) { + return new MessageNode<>(root, parent, CLUSTER_UNREACHABLE); } } return new MessageNode<>(root, parent, "Could not get namespaces: " + ExceptionUtils.getMessage(e)); diff --git a/src/main/java/org/jboss/tools/intellij/openshift/utils/KubernetesClientExceptionUtils.java b/src/main/java/org/jboss/tools/intellij/openshift/utils/KubernetesClientExceptionUtils.java index fdc225187..060b380b8 100644 --- a/src/main/java/org/jboss/tools/intellij/openshift/utils/KubernetesClientExceptionUtils.java +++ b/src/main/java/org/jboss/tools/intellij/openshift/utils/KubernetesClientExceptionUtils.java @@ -25,5 +25,19 @@ public static boolean isForbidden(KubernetesClientException e) { public static boolean isUnauthorized(KubernetesClientException e) { return HttpURLConnection.HTTP_UNAUTHORIZED == e.getCode(); } + + public static boolean isHostDown(KubernetesClientException e) { + if (e.getCause() == null) { + return false; + } + return "Host is down".equals(e.getCause().getMessage()); + } + + public static boolean isConnectionReset(KubernetesClientException e) { + if (e.getCause() == null) { + return false; + } + return "Connection reset".equals(e.getCause().getMessage()); + } }