package pod
import "k8s.io/kubernetes/pkg/api/v1/pod"
Index ¶
- func FindPort(pod *v1.Pod, svcPort *v1.ServicePort) (int, error)
- func GetContainerStatus(statuses []v1.ContainerStatus, name string) (v1.ContainerStatus, bool)
- func GetContainersReadyCondition(status v1.PodStatus) *v1.PodCondition
- func GetExistingContainerStatus(statuses []v1.ContainerStatus, name string) v1.ContainerStatus
- func GetIndexOfContainerStatus(statuses []v1.ContainerStatus, name string) (int, bool)
- func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)
- func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodConditionType) (int, *v1.PodCondition)
- func GetPodObservedGenerationIfEnabled(pod *v1.Pod) int64
- func GetPodObservedGenerationIfEnabledOnCondition(podStatus *v1.PodStatus, generation int64, conditionType v1.PodConditionType) int64
- func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition
- func IsContainersReadyConditionTrue(status v1.PodStatus) bool
- func IsPodAvailable(pod *v1.Pod, minReadySeconds int32, now metav1.Time) bool
- func IsPodPhaseTerminal(phase v1.PodPhase) bool
- func IsPodReady(pod *v1.Pod) bool
- func IsPodReadyConditionTrue(status v1.PodStatus) bool
- func IsPodTerminal(pod *v1.Pod) bool
- func IsRestartableInitContainer(initContainer *v1.Container) bool
- func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool
- func VisitContainers(podSpec *v1.PodSpec, mask ContainerType, visitor ContainerVisitor) bool
- func VisitPodConfigmapNames(pod *v1.Pod, visitor Visitor) bool
- func VisitPodSecretNames(pod *v1.Pod, visitor Visitor) bool
- type ContainerType
- type ContainerVisitor
- type Visitor
Functions ¶
func FindPort ¶
FindPort locates the container port for the given pod and portName. If the targetPort is a number, use that. If the targetPort is a string, look that string up in all named ports in all containers in the target pod. If no match is found, fail.
func GetContainerStatus ¶
func GetContainerStatus(statuses []v1.ContainerStatus, name string) (v1.ContainerStatus, bool)
GetContainerStatus extracts the status of container "name" from "statuses". It returns true if "name" exists, else returns false.
func GetContainersReadyCondition ¶
func GetContainersReadyCondition(status v1.PodStatus) *v1.PodCondition
GetContainersReadyCondition extracts the containers ready condition from the given status and returns that. Returns nil if the condition is not present.
func GetExistingContainerStatus ¶
func GetExistingContainerStatus(statuses []v1.ContainerStatus, name string) v1.ContainerStatus
GetExistingContainerStatus extracts the status of container "name" from "statuses", It also returns if "name" exists.
func GetIndexOfContainerStatus ¶
func GetIndexOfContainerStatus(statuses []v1.ContainerStatus, name string) (int, bool)
GetIndexOfContainerStatus gets the index of status of container "name" from "statuses", It returns (index, true) if "name" exists, else returns (0, false).
func GetPodCondition ¶
func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)
GetPodCondition extracts the provided condition from the given status and returns that. Returns nil and -1 if the condition is not present, and the index of the located condition.
func GetPodConditionFromList ¶
func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodConditionType) (int, *v1.PodCondition)
GetPodConditionFromList extracts the provided condition from the given list of condition and returns the index of the condition and the condition. Returns -1 and nil if the condition is not present.
func GetPodObservedGenerationIfEnabled ¶
We will emit status.observedGeneration if the feature is enabled OR if status.observedGeneration is already set. This protects against an infinite loop of kubelet trying to clear the value after the FG is turned off, and the API server preserving existing values when an incoming update tries to clear it.
func GetPodObservedGenerationIfEnabledOnCondition ¶
func GetPodObservedGenerationIfEnabledOnCondition(podStatus *v1.PodStatus, generation int64, conditionType v1.PodConditionType) int64
We will emit condition.observedGeneration if the feature is enabled OR if condition.observedGeneration is already set. This protects against an infinite loop of kubelet trying to clear the value after the FG is turned off, and the API server preserving existing values when an incoming update tries to clear it.
func GetPodReadyCondition ¶
func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition
GetPodReadyCondition extracts the pod ready condition from the given status and returns that. Returns nil if the condition is not present.
func IsContainersReadyConditionTrue ¶
IsContainersReadyConditionTrue returns true if a pod is ready; false otherwise.
func IsPodAvailable ¶
IsPodAvailable returns true if a pod is available; false otherwise. Precondition for an available pod is that it must be ready. On top of that, there are two cases when a pod can be considered available: 1. minReadySeconds == 0, or 2. LastTransitionTime (is set) + minReadySeconds < current time
func IsPodPhaseTerminal ¶
IsPodPhaseTerminal returns true if the pod's phase is terminal.
func IsPodReady ¶
IsPodReady returns true if a pod is ready; false otherwise.
func IsPodReadyConditionTrue ¶
IsPodReadyConditionTrue returns true if a pod is ready; false otherwise.
func IsPodTerminal ¶
IsPodTerminal returns true if a pod is terminal, all containers are stopped and cannot ever regress.
func IsRestartableInitContainer ¶
IsRestartableInitContainer returns true if the container has ContainerRestartPolicyAlways. This function is not checking if the container passed to it is indeed an init container. It is just checking if the container restart policy has been set to always.
func UpdatePodCondition ¶
func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool
UpdatePodCondition updates existing pod condition or creates a new one. Sets LastTransitionTime to now if the status has changed. Returns true if pod condition has changed or has been added.
func VisitContainers ¶
func VisitContainers(podSpec *v1.PodSpec, mask ContainerType, visitor ContainerVisitor) bool
VisitContainers invokes the visitor function with a pointer to every container spec in the given pod spec with type set in mask. If visitor returns false, visiting is short-circuited. VisitContainers returns true if visiting completes, false if visiting was short-circuited.
func VisitPodConfigmapNames ¶
VisitPodConfigmapNames invokes the visitor function with the name of every configmap referenced by the pod spec. If visitor returns false, visiting is short-circuited. Transitive references (e.g. pod -> pvc -> pv -> secret) are not visited. Returns true if visiting completed, false if visiting was short-circuited.
func VisitPodSecretNames ¶
VisitPodSecretNames invokes the visitor function with the name of every secret referenced by the pod spec. If visitor returns false, visiting is short-circuited. Transitive references (e.g. pod -> pvc -> pv -> secret) are not visited. Returns true if visiting completed, false if visiting was short-circuited.
Types ¶
type ContainerType ¶
type ContainerType int
ContainerType signifies container type
const ( // Containers is for normal containers Containers ContainerType = 1 << iota // InitContainers is for init containers InitContainers // EphemeralContainers is for ephemeral containers EphemeralContainers )
const AllContainers ContainerType = InitContainers | Containers | EphemeralContainers
AllContainers specifies that all containers be visited
func AllFeatureEnabledContainers ¶
func AllFeatureEnabledContainers() ContainerType
AllFeatureEnabledContainers returns a ContainerType mask which includes all container types except for the ones guarded by feature gate.
type ContainerVisitor ¶
type ContainerVisitor func(container *v1.Container, containerType ContainerType) (shouldContinue bool)
ContainerVisitor is called with each container spec, and returns true if visiting should continue.
type Visitor ¶
Visitor is called with each object name, and returns true if visiting should continue
Source Files ¶
util.go
- Version
- v1.33.0 (latest)
- Published
- Apr 23, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 3 hours ago –
Tools for package owners.