k8s

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 15 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

type CertificateClient added in v1.2.7

type CertificateClient interface {
	// GetTLSSecret retrieves a TLS secret from the specified namespace
	GetTLSSecret(ctx context.Context, namespace, secretName string) (map[string]interface{}, error)
	// GetWebhookCABundle retrieves the CA bundle from a webhook configuration
	GetWebhookCABundle(ctx context.Context, webhookName string) (string, error)
	// PatchSecret applies a patch to a secret in the specified namespace
	PatchSecret(ctx context.Context, namespace, secretName string, patchData map[string]interface{}) error
	// PatchWebhookConfiguration applies patches to a webhook configuration
	PatchWebhookConfiguration(ctx context.Context, webhookName string, patches []certificate.WebhookPatch) error
}

CertificateClient defines the interface for Kubernetes certificate operations

func NewCertificateClient added in v1.2.7

func NewCertificateClient() (CertificateClient, error)

NewCertificateClient creates a new certificate client using the existing k8s client

func NewCertificateClientWithConfig added in v1.2.7

func NewCertificateClientWithConfig(config *rest.Config, clientset kubernetes.Interface) CertificateClient

NewCertificateClientWithConfig creates a new certificate client with provided config and clientset

type ConfigProvider added in v1.2.7

type ConfigProvider interface {
	// GetConfig returns a Kubernetes rest.Config
	GetConfig() (*rest.Config, error)
}

ConfigProvider defines the interface for Kubernetes configuration

func NewConfigProvider added in v1.2.7

func NewConfigProvider() ConfigProvider

NewConfigProvider creates a new ConfigProvider instance

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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