k8s

package
v0.0.0-...-7dcb666 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
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

func CleanContainerIDFromPod(podContainerID string) (string, error)

CleanContainerIDFromPod cleans the full container ID from a pod to get the actual container ID.

func ContainerIDContains

func ContainerIDContains(containerID string, prefix string) bool

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

func ContainerIndexFunc(obj interface{}) ([]string, error)

ContainerIndexFunc index pod by container IDs.

func FindContainer

func FindContainer(containerID string, pods []interface{}) (*corev1.Pod, error)

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

func FindDockerIDFromCgroup(cgroups string) string

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

func LookupContainerID(cgroup string) string

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

func ProcsContainerID(pid uint32) (string, error)

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

func ProcsContainerIDOffset(subdir string) (string, int)

ProcsContainerIDOffset Returns the container ID and its offset This can fail, better use LookupContainerId to handle different container runtimes.

Types

type K8sPodWatcher

type K8sPodWatcher interface {
	FindPod(containerID string) *corev1.Pod
}

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.

func (*PodWatcher) FindPod

func (watcher *PodWatcher) FindPod(containerID string) (*corev1.Pod, error)

FindPod finds a pod by its container ID.

func (*PodWatcher) Start

func (watcher *PodWatcher) Start()

Start starts the PodWatcher.

Jump to

Keyboard shortcuts

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