Skip to content

Commit

Permalink
util: added RunsOnKubernetes() function
Browse files Browse the repository at this point in the history
Signed-off-by: Praveen M <[email protected]>
  • Loading branch information
iPraveenParihar authored and mergify[bot] committed Nov 8, 2023
1 parent 9cec05f commit 93f2ed6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/util/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ""
}

0 comments on commit 93f2ed6

Please sign in to comment.