util: added RunsOnKubernetes() function

Signed-off-by: Praveen M <m.praveen@ibm.com>
This commit is contained in:
Praveen M 2023-11-02 11:30:08 +05:30 committed by mergify[bot]
parent 9cec05f484
commit 93f2ed681f

View File

@ -56,3 +56,11 @@ func NewK8sClient() (*kubernetes.Clientset, error) {
return client, nil
}
// RunsOnKubernetes checks if the application is running within a Kubernetes cluster
// by inspecting the presence of the KUBERNETES_SERVICE_HOST environment variable.
func RunsOnKubernetes() bool {
kubernetesServiceHost := os.Getenv("KUBERNETES_SERVICE_HOST")
return kubernetesServiceHost != ""
}