Skip to content

Commit

Permalink
fix: report 'cluster unreachable' instead of 'failed to list secrets' (
Browse files Browse the repository at this point in the history
…redhat-developer#682)

Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Jan 30, 2024
1 parent 590ff1d commit 9539075
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 9539075

Please sign in to comment.