All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.instaclustr.kubernetes.KubernetesHelper Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
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];
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy