Documentation
¶
Overview ¶
Package k8s gives a unified interface for k8s information to be retrieved.
Index ¶
Constants ¶
const EnvK8sNamespace = "K8S_NAMESPACE"
EnvK8sNamespace Kubernetes namespace that the application is running inside
const EnvK8sPodName = "K8S_POD_NAME"
EnvK8sPodName Kubernetes pod name the application is running inside
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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