Created
July 13, 2021 06:34
-
-
Save rohanKanojia/742c8b7ce67dea45162d8f2e12421ef7 to your computer and use it in GitHub Desktop.
Fabric8 Kubernetes Client Connection Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package io.fabric8.testing; | |
| import io.fabric8.kubernetes.client.DefaultKubernetesClient; | |
| import io.fabric8.kubernetes.client.KubernetesClient; | |
| import io.fabric8.kubernetes.client.KubernetesClientException; | |
| import java.net.UnknownHostException; | |
| public class ConnectionTest { | |
| public static void main(String[] args) { | |
| System.out.printf("%s to Kubernetes Cluster", isConnected() ? "Connected" : "Not Connected"); | |
| } | |
| private static boolean isConnected() { | |
| try (KubernetesClient client = new DefaultKubernetesClient()) { | |
| client.getVersion(); | |
| } catch (KubernetesClientException e) { | |
| if (e.getCause() instanceof UnknownHostException) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| // Not Supported: But it would be nice to have. | |
| // try (KubernetesClient client = new DefaultKubernetesClient()) { | |
| // client.getVersion(); | |
| // } catch (KubernetesNotFoundException e) { | |
| // return false; | |
| // } | |
| // return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment