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 nixpanic committed Nov 8, 2023
1 parent 5d3cbd0 commit 5ae4f91
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 5ae4f91

Please sign in to comment.