com.instaclustr.kubernetes.KubernetesHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons Show documentation
Show all versions of commons Show documentation
Common classes and utilities integrated with various projects
package com.instaclustr.kubernetes;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class KubernetesHelper {
public static final String KUBERNETES_SERVICE_HOST = "KUBERNETES_SERVICE_HOST";
public static final String KUBERNETES_SERVICE_PORT = "KUBERNETES_SERVICE_PORT";
public static boolean isRunningInKubernetes() {
return System.getenv(KUBERNETES_SERVICE_HOST) != null && System.getenv(KUBERNETES_SERVICE_PORT) != null && !isPretendingToRunOutsideKubernetes();
}
public static boolean isRunningAsClient() {
return Boolean.parseBoolean(System.getProperty("kubernetes.client", "false"));
}
public static String getHostname() throws UnknownHostException {
return InetAddress.getLocalHost().getHostName();
}
public static boolean isPretendingToRunOutsideKubernetes() {
return Boolean.parseBoolean(System.getProperty("pretend.not.running.in.kubernetes", "false"));
}
public static String getPodName() throws UnknownHostException {
return getHostname().split("\\.")[0];
}
}