Documentation ¶
Index ¶
- Variables
- func FileExists(path string) bool
- func IsPodReady(pod *kubernetes.Pod) bool
- func KubeContainerIDToTaggerEntityID(ctrID string) (string, error)
- func KubeIDToTaggerEntityID(entityName string) (string, error)
- func KubePodUIDToTaggerEntityID(podUID string) (string, error)
- func ParseMetricFromRaw(raw []byte, metric string) (string, error)
- func PodUIDToEntityName(uid string) string
- func PodUIDToTaggerEntityName(uid string) string
- func ResetCache()
- func ResetGlobalKubeUtil()
- func TrimRuntimeFromCID(cid string) string
- type KubeUtil
- func (ku *KubeUtil) ForceGetLocalPodList(ctx context.Context) ([]*kubernetes.Pod, error)
- func (ku *KubeUtil) GetKubeletAPIEndpoint() string
- func (ku *KubeUtil) GetLocalPodList(ctx context.Context) ([]*kubernetes.Pod, error)
- func (ku *KubeUtil) GetNodeInfo(ctx context.Context) (string, string, error)
- func (ku *KubeUtil) GetNodename(ctx context.Context) (string, error)
- func (ku *KubeUtil) GetPodForContainerID(ctx context.Context, containerID string) (*kubernetes.Pod, error)
- func (ku *KubeUtil) GetPodForEntityID(ctx context.Context, entityID string) (*kubernetes.Pod, error)
- func (ku *KubeUtil) GetPodFromUID(ctx context.Context, podUID string) (*kubernetes.Pod, error)
- func (ku *KubeUtil) GetRawConnectionInfo() map[string]string
- func (ku *KubeUtil) GetRawMetrics(ctx context.Context) ([]byte, error)
- func (ku *KubeUtil) GetSpecForContainerName(pod *kubernetes.Pod, containerName string) (kubernetes.ContainerSpec, error)
- func (ku *KubeUtil) GetStatusForContainerID(pod *kubernetes.Pod, containerID string) (kubernetes.ContainerStatus, error)
- func (ku *KubeUtil) IsAgentHostNetwork(ctx context.Context) (bool, error)
- func (ku *KubeUtil) ListContainers(ctx context.Context) ([]*containers.Container, error)
- func (ku *KubeUtil) QueryKubelet(ctx context.Context, path string) ([]byte, int, error)
- func (ku *KubeUtil) UpdateContainerMetrics(ctrList []*containers.Container) error
- type KubeUtilInterface
- type PodWatcher
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
KubeContainerIDToTaggerEntityID builds an entity ID from a container ID coming from the pod status (i.e. including the <runtime>:// prefix).
func KubeIDToTaggerEntityID ¶
KubeIDToTaggerEntityID builds a tagger entity ID from an entity ID belonging to a container or pod.
func KubePodUIDToTaggerEntityID ¶
KubePodUIDToTaggerEntityID builds an entity ID from a pod UID coming from the pod status (i.e. including the <runtime>:// prefix).
func ParseMetricFromRaw ¶
ParseMetricFromRaw parses a metric from raw prometheus text
func PodUIDToEntityName ¶
PodUIDToEntityName returns a prefixed entity name from a pod UID
func PodUIDToTaggerEntityName ¶
PodUIDToTaggerEntityName returns a prefixed tagger entity name from a pod UID
func ResetGlobalKubeUtil ¶
func ResetGlobalKubeUtil()
ResetGlobalKubeUtil is a helper to remove the current KubeUtil global It is ONLY to be used for tests
func TrimRuntimeFromCID ¶
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 ¶
ForceGetLocalPodList reset podList cache and call GetLocalPodList
func (*KubeUtil) GetKubeletAPIEndpoint ¶
GetKubeletAPIEndpoint returns the current endpoint used to perform QueryKubelet
func (*KubeUtil) GetLocalPodList ¶
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 ¶
GetNodeInfo returns the IP address and the hostname of the first valid pod in the PodList
func (*KubeUtil) GetNodename ¶
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 (*KubeUtil) GetRawConnectionInfo ¶
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 ¶
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 ¶
IsAgentHostNetwork returns whether the agent is running inside a container with `hostNetwork` or not
func (*KubeUtil) ListContainers ¶
ListContainers lists all non-excluded running containers, and retrieves their performance metrics
func (*KubeUtil) QueryKubelet ¶
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 ¶
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.