k8s

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package k8s gives a unified interface for k8s information to be retrieved.

Index

Constants

View Source
const EnvK8sNamespace = "K8S_NAMESPACE"

EnvK8sNamespace Kubernetes namespace that the application is running inside

View Source
const EnvK8sPodName = "K8S_POD_NAME"

EnvK8sPodName Kubernetes pod name the application is running inside

View Source
const EnvKubeConfigLocation = "KUBE_CONFIG_LOCATION"

EnvKubeConfigLocation Location of a valid kube config

Variables

This section is empty.

Functions

func GetClient

func GetClient() (*kubernetes.Clientset, error)

GetClient creates a new k8s client to use

func GetConfig

func GetConfig() (*rest.Config, error)

GetConfig returns a k8s config based on the environment detecting if we are on the prometheus pod or running on a machine with a kubeconfig file

If no config is found, an error will be thrown

Optionally, you can set the env variable `KUBE_CONFIG_LOCATION` to set where the function looks for a valid kube config file

func GetNamespace

func GetNamespace() (string, error)

GetNamespace gets the current kubernetes namespace if running in a pod.

This is parsed from the `K8S_NAMESPACE` environment variable.

This will return an error if the environment variable is not set or the value is empty.

func GetPodName

func GetPodName() (string, error)

GetPodName gets the current kubernetes pod name this app is running in

This is parsed from the `K8S_POD_NAME` environment variable.

This will return an error if the environment variable is not set or the value is empty.

func GetProviderID

func GetProviderID(ctx context.Context) (string, error)

GetProviderID uses the detected k8s namespace and pod name to query the API to get the cloud provider id.

This function requires setting both environment variables: `K8S_POD_NAME` and `K8S_NAMESPACE`

func GetVersion

func GetVersion() (string, error)

GetVersion returns the current kuberentes version when running inside of a pod

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL