Skip to main content

GetPrimaryContainerName

Retrieves the name of the primary container for a given Kubernetes Pod. It first checks for annotations 'kubectl.kubernetes.io/default-container' and then 'primary-container', falling back to a container with the same name as the pod, or the first container if no specific primary container is identified.

def GetPrimaryContainerName(
pod: *v1.Pod
) - > string

Retrieves the name of the primary container for a given Kubernetes Pod. This function determines the primary container by checking specific annotations first, then by matching the container name with the pod name, and finally defaults to the first container if no other primary container is identified.

Parameters

NameTypeDescription
pod*v1.PodThe Kubernetes Pod object for which to determine the primary container name.

Returns

TypeDescription
stringThe name of the primary container, or an empty string if no containers are found.