kubernetes

package
v0.0.0-...-6fb76d5 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package kubernetes provides several helpers to interact with a Kubernetes cluster.

Index

Constants

View Source
const (
	DefaultServiceAccountPath      = "/var/run/secrets/kubernetes.io/serviceaccount"
	DefaultServiceAccountTokenPath = DefaultServiceAccountPath + "/token"
	DefaultServiceAccountCAPath    = DefaultServiceAccountPath + "/ca.crt"
)

Kubernetes constants

View Source
const (
	// EnvTagLabelKey is the label key of the env standard tag
	EnvTagLabelKey = "tags.datadoghq.com/env"
	// ServiceTagLabelKey is the label key of the service standard tag
	ServiceTagLabelKey = "tags.datadoghq.com/service"
	// VersionTagLabelKey is the label key of the version standard tag
	VersionTagLabelKey = "tags.datadoghq.com/version"

	// KubeAppNameLabelKey is the label key of the name of the application
	KubeAppNameLabelKey = "app.kubernetes.io/name"
	// KubeAppInstanceLabelKey is the label key of unique name identifying the instance of an application
	KubeAppInstanceLabelKey = "app.kubernetes.io/instance"
	// KubeAppVersionLabelKey is the label key of the current version of the application
	KubeAppVersionLabelKey = "app.kubernetes.io/version"
	// KubeAppComponentLabelKey is the label key of the component within the architecture
	KubeAppComponentLabelKey = "app.kubernetes.io/component"
	// KubeAppPartOfLabelKey is the label key of the name of a higher level application one's part of
	KubeAppPartOfLabelKey = "app.kubernetes.io/part-of"
	// KubeAppManagedByLabelKey is the label key of the tool being used to manage the operation of an application
	KubeAppManagedByLabelKey = "app.kubernetes.io/managed-by"

	// RcIDAnnotKey is the key of the RC ID annotation
	RcIDAnnotKey = "admission.datadoghq.com/rc.id"

	// RcRevisionAnnotKey is the key of the RC revision annotation
	RcRevisionAnnotKey = "admission.datadoghq.com/rc.rev"

	// EnvTagEnvVar is the environment variable of the env standard tag
	EnvTagEnvVar = "DD_ENV"
	// ServiceTagEnvVar is the environment variable of the service standard tag
	ServiceTagEnvVar = "DD_SERVICE"
	// VersionTagEnvVar is the environment variable of the version standard tag
	VersionTagEnvVar = "DD_VERSION"

	// KubeNodeRoleTagName is the role label tag name
	KubeNodeRoleTagName = "kube_node_role"

	// PodKind represents the Pod object kind
	PodKind = "Pod"
	// DeploymentKind represents the Deployment object kind
	DeploymentKind = "Deployment"
	// ReplicaSetKind represents the ReplicaSet object kind
	ReplicaSetKind = "ReplicaSet"
	// ReplicationControllerKind represents the ReplicaSetController object kind
	ReplicationControllerKind = "ReplicationController"
	// StatefulSetKind represents the StatefulSet object kind
	StatefulSetKind = "StatefulSet"
	// DaemonSetKind represents the DaemonSet object kind
	DaemonSetKind = "DaemonSet"
	// JobKind represents the Job object kind
	JobKind = "Job"
	// CronJobKind represents the CronJob object kind
	CronJobKind = "CronJob"
	// ServiceKind represents the ServiceKind object kind
	ServiceKind = "Service"
	// NamespaceKind represents the NamespaceKind object kind
	NamespaceKind = "Namespace"

	// CriContainerNamespaceLabel is the label set on containers by runtimes with Pod Namespace
	CriContainerNamespaceLabel = "io.kubernetes.pod.namespace"
)
View Source
const Digits = "1234567890"

Digits holds the digits used for naming replicasets in kubenetes < 1.8

View Source
const KubeAllowedEncodeStringAlphaNums = "bcdfghjklmnpqrstvwxz2456789"

KubeAllowedEncodeStringAlphaNums holds the charactes allowed in replicaset names from as parent deployment Taken from https://github.com/kow3ns/kubernetes/blob/96067e6d7b24a05a6a68a0d94db622957448b5ab/staging/src/k8s.io/apimachinery/pkg/util/rand/rand.go#L76

Variables

This section is empty.

Functions

func GetBearerToken

func GetBearerToken(authTokenPath string) (string, error)

GetBearerToken reads the serviceaccount token

func GetCertificateAuthority

func GetCertificateAuthority(certPath string) (*x509.CertPool, error)

GetCertificateAuthority loads the issuing certificate authority

func GetCertificates

func GetCertificates(certFilePath, keyFilePath string) ([]tls.Certificate, error)

GetCertificates loads the certificate and the private key

func GetKubeAPIServerHostname

func GetKubeAPIServerHostname(context.Context) (string, error)

GetKubeAPIServerHostname returns the hostname from kubeapiserver

func ParseCronJobForJob added in v0.9.0

func ParseCronJobForJob(name string) (string, int)

ParseCronJobForJob gets the cronjob name from a job, or returns an empty string if no parent cronjob is found. https://github.com/kubernetes/kubernetes/blob/b4e3bd381bd4d7c0db1959341b39558b45187345/pkg/controller/cronjob/utils.go#L156

func ParseDeploymentForPodName

func ParseDeploymentForPodName(name string) string

ParseDeploymentForPodName gets the deployment name from a pod name, or returns an empty string if no parent deployment is found.

func ParseDeploymentForReplicaSet added in v0.9.0

func ParseDeploymentForReplicaSet(name string) string

ParseDeploymentForReplicaSet gets the deployment name from a replicaset, or returns an empty string if no parent deployment is found.

func ParseReplicaSetForPodName

func ParseReplicaSetForPodName(name string) string

ParseReplicaSetForPodName gets the replica set name from a pod name, or returns an empty string if no parent replica set is found.

func TimeWithoutWall added in v0.9.0

func TimeWithoutWall(t time.Time) time.Time

TimeWithoutWall fixes the `wall` issue in unit tests. THIS FUNCTION SHOULD NOT BE USED OUTSIDE OF TESTS. Unstructured serializes time to string in RFC3339 without Nano seconds. when it's parsed back, the Go time.Time does not have the `wall` field as it's used for nanosecs.

Types

This section is empty.

Directories

Path Synopsis
Package apiserver provides an API client for the Kubernetes API server.
Package apiserver provides an API client for the Kubernetes API server.
controllers
Package controllers is responsible for running the Kubernetes controllers needed by the Datadog Cluster Agent
Package controllers is responsible for running the Kubernetes controllers needed by the Datadog Cluster Agent
leaderelection
Package leaderelection provides functions related with the leader election mechanism offered in Kubernetes.
Package leaderelection provides functions related with the leader election mechanism offered in Kubernetes.
leaderelection/metrics
Package metrics provides telemetry to know who's the leader in Kubernetes objects that implement the leader/follower pattern.
Package metrics provides telemetry to know who's the leader in Kubernetes objects that implement the leader/follower pattern.
Package clustername provides helpers to get a Kubernetes cluster name.
Package clustername provides helpers to get a Kubernetes cluster name.
Package hostinfo provides functions to get annotations, labels, etc.
Package hostinfo provides functions to get annotations, labels, etc.
Package kubelet provides a client for the Kubelet API.
Package kubelet provides a client for the Kubelet API.

Jump to

Keyboard shortcuts

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