kubelet

package
v0.0.0-...-5655933 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotCompiled is returned if kubelet support is not compiled in.
	// User classes should handle that case as gracefully as possible.
	ErrNotCompiled = errors.New("kubelet support not compiled in")

	// KubePodEntityName is the entity name for Kubernetes pods.
	KubePodEntityName = "kubernetes_pod"

	// KubePodPrefix is the entity prefix for Kubernetes pods
	KubePodPrefix = KubePodEntityName + containers.EntitySeparator

	// KubePodTaggerEntityName is the tagger entity name for Kubernetes pods
	KubePodTaggerEntityName = "kubernetes_pod_uid"

	// KubePodTaggerEntityPrefix is the tagger entity prefix for Kubernetes pods
	KubePodTaggerEntityPrefix = KubePodTaggerEntityName + containers.EntitySeparator
)

Functions

func FileExists

func FileExists(path string) bool

FileExists returns true if a file exists and is accessible, false otherwise

func IsPodReady

func IsPodReady(pod *kubernetes.Pod) bool

IsPodReady return a bool if the Pod is ready

func KubeContainerIDToTaggerEntityID

func KubeContainerIDToTaggerEntityID(ctrID string) (string, error)

KubeContainerIDToTaggerEntityID builds an entity ID from a container ID coming from the pod status (i.e. including the <runtime>:// prefix).

func KubeIDToTaggerEntityID

func KubeIDToTaggerEntityID(entityName string) (string, error)

KubeIDToTaggerEntityID builds a tagger entity ID from an entity ID belonging to a container or pod.

func KubePodUIDToTaggerEntityID

func KubePodUIDToTaggerEntityID(podUID string) (string, error)

KubePodUIDToTaggerEntityID builds an entity ID from a pod UID coming from the pod status (i.e. including the <runtime>:// prefix).

func ParseMetricFromRaw

func ParseMetricFromRaw(raw []byte, metric string) (string, error)

ParseMetricFromRaw parses a metric from raw prometheus text

func PodUIDToEntityName

func PodUIDToEntityName(uid string) string

PodUIDToEntityName returns a prefixed entity name from a pod UID

func PodUIDToTaggerEntityName

func PodUIDToTaggerEntityName(uid string) string

PodUIDToTaggerEntityName returns a prefixed tagger entity name from a pod UID

func ResetCache

func ResetCache()

ResetCache deletes existing kubeutil related cache

func ResetGlobalKubeUtil

func ResetGlobalKubeUtil()

ResetGlobalKubeUtil is a helper to remove the current KubeUtil global It is ONLY to be used for tests

func TrimRuntimeFromCID

func TrimRuntimeFromCID(cid string) string

TrimRuntimeFromCID takes a full containerID with runtime prefix and only returns the short cID, compatible with a docker container ID

Types

type KubeUtil

type KubeUtil struct {
	// contains filtered or unexported fields
}

KubeUtil is a struct to hold the kubelet api url Instantiate with GetKubeUtil

func NewKubeUtil

func NewKubeUtil() *KubeUtil

func (*KubeUtil) ForceGetLocalPodList

func (ku *KubeUtil) ForceGetLocalPodList(ctx context.Context) ([]*kubernetes.Pod, error)

ForceGetLocalPodList reset podList cache and call GetLocalPodList

func (*KubeUtil) GetKubeletAPIEndpoint

func (ku *KubeUtil) GetKubeletAPIEndpoint() string

GetKubeletAPIEndpoint returns the current endpoint used to perform QueryKubelet

func (*KubeUtil) GetLocalPodList

func (ku *KubeUtil) GetLocalPodList(ctx context.Context) ([]*kubernetes.Pod, error)

GetLocalPodList returns the list of pods running on the node. If kubernetes_pod_expiration_duration is set, old exited pods will be filtered out to keep the podlist size down: see json.go

func (*KubeUtil) GetNodeInfo

func (ku *KubeUtil) GetNodeInfo(ctx context.Context) (string, string, error)

GetNodeInfo returns the IP address and the hostname of the first valid pod in the PodList

func (*KubeUtil) GetNodename

func (ku *KubeUtil) GetNodename(ctx context.Context) (string, error)

GetNodename returns the nodename of the first pod.spec.nodeName in the PodList

func (*KubeUtil) GetPodForContainerID

func (ku *KubeUtil) GetPodForContainerID(ctx context.Context, containerID string) (*kubernetes.Pod, error)

GetPodForContainerID fetches the podList and returns the pod running a given container on the node. Reset the cache if needed. Returns a nil pointer if not found.

func (*KubeUtil) GetPodForEntityID

func (ku *KubeUtil) GetPodForEntityID(ctx context.Context, entityID string) (*kubernetes.Pod, error)

GetPodForEntityID returns a pointer to the pod that corresponds to an entity ID. If the pod is not found it returns nil and an error.

func (*KubeUtil) GetPodFromUID

func (ku *KubeUtil) GetPodFromUID(ctx context.Context, podUID string) (*kubernetes.Pod, error)

func (*KubeUtil) GetRawConnectionInfo

func (ku *KubeUtil) GetRawConnectionInfo() map[string]string

GetRawConnectionInfo returns a map containging the url and credentials to connect to the kubelet Possible map entries:

  • url: full url with scheme (required)
  • verify_tls: "true" or "false" string
  • ca_cert: path to the kubelet CA cert if set
  • token: content of the bearer token if set
  • client_crt: path to the client cert if set
  • client_key: path to the client key if set

func (*KubeUtil) GetRawMetrics

func (ku *KubeUtil) GetRawMetrics(ctx context.Context) ([]byte, error)

GetRawMetrics returns the raw kubelet metrics payload

func (*KubeUtil) GetSpecForContainerName

func (ku *KubeUtil) GetSpecForContainerName(pod *kubernetes.Pod, containerName string) (kubernetes.ContainerSpec, error)

GetSpecForContainerName returns the container spec from the pod given a name It searches spec.containers then spec.initContainers

func (*KubeUtil) GetStatusForContainerID

func (ku *KubeUtil) GetStatusForContainerID(pod *kubernetes.Pod, containerID string) (kubernetes.ContainerStatus, error)

GetStatusForContainerID returns the container status from the pod given an ID

func (*KubeUtil) IsAgentHostNetwork

func (ku *KubeUtil) IsAgentHostNetwork(ctx context.Context) (bool, error)

IsAgentHostNetwork returns whether the agent is running inside a container with `hostNetwork` or not

func (*KubeUtil) ListContainers

func (ku *KubeUtil) ListContainers(ctx context.Context) ([]*containers.Container, error)

ListContainers lists all non-excluded running containers, and retrieves their performance metrics

func (*KubeUtil) QueryKubelet

func (ku *KubeUtil) QueryKubelet(ctx context.Context, path string) ([]byte, int, error)

QueryKubelet allows to query the KubeUtil registered kubelet API on the parameter path path commonly used are /healthz, /pods, /metrics return the content of the response, the response HTTP status code and an error in case of

func (*KubeUtil) UpdateContainerMetrics

func (ku *KubeUtil) UpdateContainerMetrics(ctrList []*containers.Container) error

UpdateContainerMetrics updates cgroup / network performance metrics for a provided list of Container objects

type KubeUtilInterface

type KubeUtilInterface interface {
	GetNodeInfo(ctx context.Context) (string, string, error)
	GetNodename(ctx context.Context) (string, error)
	GetLocalPodList(ctx context.Context) ([]*kubernetes.Pod, error)
	ForceGetLocalPodList(ctx context.Context) ([]*kubernetes.Pod, error)
	GetPodForContainerID(ctx context.Context, containerID string) (*kubernetes.Pod, error)
	GetStatusForContainerID(pod *kubernetes.Pod, containerID string) (kubernetes.ContainerStatus, error)
	GetSpecForContainerName(pod *kubernetes.Pod, containerName string) (kubernetes.ContainerSpec, error)
	GetPodFromUID(ctx context.Context, podUID string) (*kubernetes.Pod, error)
	GetPodForEntityID(ctx context.Context, entityID string) (*kubernetes.Pod, error)
	QueryKubelet(ctx context.Context, path string) ([]byte, int, error)
	GetKubeletAPIEndpoint() string
	GetRawConnectionInfo() map[string]string
	GetRawMetrics(ctx context.Context) ([]byte, error)
	IsAgentHostNetwork(ctx context.Context) (bool, error)
	ListContainers(ctx context.Context) ([]*containers.Container, error)
	UpdateContainerMetrics(ctrList []*containers.Container) error
}

KubeUtilInterface defines the interface for kubelet api see `kubelet_orchestrator` for orchestrator-only interface

func GetKubeUtil

func GetKubeUtil() (KubeUtilInterface, error)

GetKubeUtil returns an instance of KubeUtil.

func GetKubeUtilWithRetrier

func GetKubeUtilWithRetrier() (KubeUtilInterface, *retry.Retrier)

GetKubeUtilWithRetrier returns an instance of KubeUtil or a retrier

type PodWatcher

type PodWatcher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PodWatcher regularly pools the kubelet for new/changed/removed containers. It keeps an internal state to only send the updated pods.

func NewPodWatcher

func NewPodWatcher(expiryDuration time.Duration, isWatchingTags bool) (*PodWatcher, error)

NewPodWatcher creates a new watcher given an expiry duration and if the watcher should watch label/annotation changes on pods. User call must then trigger PullChanges and Expire when needed.

func (*PodWatcher) Expire

func (w *PodWatcher) Expire() ([]string, error)

Expire returns a list of entities (containers and pods) that are not listed in the podlist anymore. It must be called immediately after a PullChanges. For containers, string is kubernetes container ID (with runtime name) For pods, string is "kubernetes_pod://uid" format

func (*PodWatcher) GetPodForEntityID

func (w *PodWatcher) GetPodForEntityID(ctx context.Context, entityID string) (*kubernetes.Pod, error)

GetPodForEntityID finds the pod corresponding to an entity. EntityIDs can be Docker container IDs or pod UIDs (prefixed). Returns a nil pointer if not found.

func (*PodWatcher) PullChanges

func (w *PodWatcher) PullChanges(ctx context.Context) ([]*kubernetes.Pod, error)

PullChanges pulls a new podList from the kubelet and returns Pod objects for new / updated pods. Updated pods will be sent entirely, user must replace previous info for these pods.

Jump to

Keyboard shortcuts

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