From 93f2ed681f62c3d7958ac449415f1bab09c94195 Mon Sep 17 00:00:00 2001 From: Praveen M Date: Thu, 2 Nov 2023 11:30:08 +0530 Subject: [PATCH] util: added RunsOnKubernetes() function Signed-off-by: Praveen M --- internal/util/k8s/client.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/util/k8s/client.go b/internal/util/k8s/client.go index 29db2ce3ab8..d5629fee54d 100644 --- a/internal/util/k8s/client.go +++ b/internal/util/k8s/client.go @@ -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 != "" +}