Documentation ¶
Overview ¶
Package k8s provides tools for managing Pods and Containers in a Kubernetes environment. It includes functionalities for watching Pods, indexing them by container IDs, and finding a Pod given a container ID.
Index ¶
- Constants
- func CleanContainerIDFromPod(podContainerID string) (string, error)
- func ContainerIDContains(containerID string, prefix string) bool
- func ContainerIndexFunc(obj interface{}) ([]string, error)
- func FindContainer(containerID string, pods []interface{}) (*corev1.Pod, error)
- func FindDockerIDFromCgroup(cgroups string) string
- func LookupContainerID(cgroup string) string
- func ProcsContainerID(pid uint32) (string, error)
- func ProcsContainerIDOffset(subdir string) (string, int)
- type K8sPodWatcher
- type PodWatcher
Constants ¶
const ( // ContainerIDLength is the standard length of the Container ID ContainerIDLength = 64 // BpfContainerIDLength Minimum 31 chars to assume it is a Container ID // in case it was truncated BpfContainerIDLength = 31 // DockerIDLength is the length of a Docker container ID. DockerIDLength = 128 // HostProcDir is the directory where host process information is stored. HostProcDir = "/host/proc" )
Variables ¶
This section is empty.
Functions ¶
func CleanContainerIDFromPod ¶
CleanContainerIDFromPod cleans the full container ID from a pod to get the actual container ID.
func ContainerIDContains ¶
ContainerIDContains checks if a container ID contains a specified prefix. It splits the container ID by '//' and checks if the second part of the split string starts with the prefix. It returns true if the prefix is found, and false otherwise.
func ContainerIndexFunc ¶
ContainerIndexFunc index pod by container IDs.
func FindContainer ¶
FindContainer searches through a list of pods for a container with the specified ID. It checks each container in each pod and returns the first pod that contains the specified container. If no such container is found in any known pod, it returns an error.
func FindDockerIDFromCgroup ¶
FindDockerIDFromCgroup extracts the Docker container ID from a cgroup string. It does this by splitting the cgroup string into paths, and checking each path for the presence of a Docker container ID. If a valid ID is found, it is returned.
func LookupContainerID ¶
LookupContainerID returns the container ID as a 31 character string length from the full cgroup path cgroup argument is the full cgroup path Returns the container ID as a string of 31 characters and its offset on the full cgroup path, otherwise on errors an empty string and 0 as offset.
func ProcsContainerID ¶
ProcsContainerID returns the container ID for a given process ID (pid). It reads the cgroup file for the process and extracts the container ID from it. If an error occurs during this process, it is returned.
func ProcsContainerIDOffset ¶
ProcsContainerIDOffset Returns the container ID and its offset This can fail, better use LookupContainerId to handle different container runtimes.
Types ¶
type K8sPodWatcher ¶
K8sPodWatcher is an interface that defines the FindPod method.
type PodWatcher ¶
type PodWatcher struct {
// contains filtered or unexported fields
}
PodWatcher is a struct that implements the K8sPodWatcher interface.
func NewPodWatcher ¶
func NewPodWatcher(k8sClient *kubernetes.Clientset) (*PodWatcher, error)
NewPodWatcher creates a new PodWatcher.