package pleg
import "k8s.io/kubernetes/pkg/kubelet/pleg"
Package pleg contains types and a generic implementation of the pod lifecycle event generator.
Index ¶
- type EventedPLEG
- func (e *EventedPLEG) Healthy() (bool, error)
- func (e *EventedPLEG) Relist()
- func (e *EventedPLEG) SetPodWatchCondition(podUID types.UID, conditionKey string, condition WatchCondition)
- func (e *EventedPLEG) Start()
- func (e *EventedPLEG) Stop()
- func (e *EventedPLEG) Update(relistDuration *RelistDuration)
- func (e *EventedPLEG) Watch() chan *PodLifecycleEvent
- type GenericPLEG
- func (g *GenericPLEG) Healthy() (bool, error)
- func (g *GenericPLEG) Relist()
- func (g *GenericPLEG) SetPodWatchCondition(podUID types.UID, conditionKey string, condition WatchCondition)
- func (g *GenericPLEG) Start()
- func (g *GenericPLEG) Stop()
- func (g *GenericPLEG) Update(relistDuration *RelistDuration)
- func (g *GenericPLEG) Watch() chan *PodLifecycleEvent
- type PodLifeCycleEventType
- type PodLifecycleEvent
- type PodLifecycleEventGenerator
- func NewEventedPLEG(logger klog.Logger, runtime kubecontainer.Runtime, runtimeService internalapi.RuntimeService, eventChannel chan *PodLifecycleEvent, cache kubecontainer.Cache, genericPleg PodLifecycleEventGenerator, eventedPlegMaxStreamRetries int, relistDuration *RelistDuration, clock clock.Clock) (PodLifecycleEventGenerator, error)
- func NewGenericPLEG(logger klog.Logger, runtime kubecontainer.Runtime, eventChannel chan *PodLifecycleEvent, relistDuration *RelistDuration, cache kubecontainer.Cache, clock clock.Clock) PodLifecycleEventGenerator
- type RelistDuration
- type WatchCondition
Types ¶
type EventedPLEG ¶
type EventedPLEG struct {
// contains filtered or unexported fields
}
func (*EventedPLEG) Healthy ¶
func (e *EventedPLEG) Healthy() (bool, error)
Healthy check if PLEG work properly.
func (*EventedPLEG) Relist ¶
func (e *EventedPLEG) Relist()
Relist relists all containers using GenericPLEG
func (*EventedPLEG) SetPodWatchCondition ¶
func (e *EventedPLEG) SetPodWatchCondition(podUID types.UID, conditionKey string, condition WatchCondition)
func (*EventedPLEG) Start ¶
func (e *EventedPLEG) Start()
Start starts the Evented PLEG
func (*EventedPLEG) Stop ¶
func (e *EventedPLEG) Stop()
Stop stops the Evented PLEG
func (*EventedPLEG) Update ¶
func (e *EventedPLEG) Update(relistDuration *RelistDuration)
Update the relisting period and threshold
func (*EventedPLEG) Watch ¶
func (e *EventedPLEG) Watch() chan *PodLifecycleEvent
Watch returns a channel from which the subscriber can receive PodLifecycleEvent events.
type GenericPLEG ¶
type GenericPLEG struct {
// contains filtered or unexported fields
}
GenericPLEG is an extremely simple generic PLEG that relies solely on periodic listing to discover container changes. It should be used as temporary replacement for container runtimes do not support a proper event generator yet.
Note that GenericPLEG assumes that a container would not be created, terminated, and garbage collected within one relist period. If such an incident happens, GenenricPLEG would miss all events regarding this container. In the case of relisting failure, the window may become longer. Note that this assumption is not unique -- many kubelet internal components rely on terminated containers as tombstones for bookkeeping purposes. The garbage collector is implemented to work with such situations. However, to guarantee that kubelet can handle missing container events, it is recommended to set the relist period short and have an auxiliary, longer periodic sync in kubelet as the safety net.
func (*GenericPLEG) Healthy ¶
func (g *GenericPLEG) Healthy() (bool, error)
Healthy check if PLEG work properly. relistThreshold is the maximum interval between two relist.
func (*GenericPLEG) Relist ¶
func (g *GenericPLEG) Relist()
Relist queries the container runtime for list of pods/containers, compare with the internal pods/containers, and generates events accordingly.
func (*GenericPLEG) SetPodWatchCondition ¶
func (g *GenericPLEG) SetPodWatchCondition(podUID types.UID, conditionKey string, condition WatchCondition)
SetPodWatchCondition flags the pod for reinspection on every Relist iteration until the watch condition is met. The condition is keyed so it can be updated before the condition is met.
func (*GenericPLEG) Start ¶
func (g *GenericPLEG) Start()
Start spawns a goroutine to relist periodically.
func (*GenericPLEG) Stop ¶
func (g *GenericPLEG) Stop()
func (*GenericPLEG) Update ¶
func (g *GenericPLEG) Update(relistDuration *RelistDuration)
func (*GenericPLEG) Watch ¶
func (g *GenericPLEG) Watch() chan *PodLifecycleEvent
Watch returns a channel from which the subscriber can receive PodLifecycleEvent events. TODO: support multiple subscribers.
type PodLifeCycleEventType ¶
type PodLifeCycleEventType string
PodLifeCycleEventType define the event type of pod life cycle events.
const ( // ContainerStarted - event type when the new state of container is running. ContainerStarted PodLifeCycleEventType = "ContainerStarted" // ContainerDied - event type when the new state of container is exited. ContainerDied PodLifeCycleEventType = "ContainerDied" // ContainerRemoved - event type when the old state of container is exited. ContainerRemoved PodLifeCycleEventType = "ContainerRemoved" // PodSync is used to trigger syncing of a pod when the observed change of // the state of the pod cannot be captured by any single event above. PodSync PodLifeCycleEventType = "PodSync" // ContainerChanged - event type when the new state of container is unknown. ContainerChanged PodLifeCycleEventType = "ContainerChanged" // ConditionMet - event type triggered when any number of watch conditions are met. ConditionMet PodLifeCycleEventType = "ConditionMet" )
type PodLifecycleEvent ¶
type PodLifecycleEvent struct { // The pod ID. ID types.UID // The type of the event. Type PodLifeCycleEventType // The accompanied data which varies based on the event type. // - ContainerStarted/ContainerStopped: the container name (string). // - All other event types: unused. Data interface{} }
PodLifecycleEvent is an event that reflects the change of the pod state.
type PodLifecycleEventGenerator ¶
type PodLifecycleEventGenerator interface { Start() Watch() chan *PodLifecycleEvent Healthy() (bool, error) // SetPodWatchCondition flags the pod for reinspection on every Relist iteration until the watch // condition is met. The condition is keyed so it can be updated before the condition // is met. SetPodWatchCondition(podUID types.UID, conditionKey string, condition WatchCondition) }
PodLifecycleEventGenerator contains functions for generating pod life cycle events.
func NewEventedPLEG ¶
func NewEventedPLEG(logger klog.Logger, runtime kubecontainer.Runtime, runtimeService internalapi.RuntimeService, eventChannel chan *PodLifecycleEvent, cache kubecontainer.Cache, genericPleg PodLifecycleEventGenerator, eventedPlegMaxStreamRetries int, relistDuration *RelistDuration, clock clock.Clock) (PodLifecycleEventGenerator, error)
NewEventedPLEG instantiates a new EventedPLEG object and return it.
func NewGenericPLEG ¶
func NewGenericPLEG(logger klog.Logger, runtime kubecontainer.Runtime, eventChannel chan *PodLifecycleEvent, relistDuration *RelistDuration, cache kubecontainer.Cache, clock clock.Clock) PodLifecycleEventGenerator
NewGenericPLEG instantiates a new GenericPLEG object and return it.
type RelistDuration ¶
type RelistDuration struct { // The period for relisting. RelistPeriod time.Duration // The relisting threshold needs to be greater than the relisting period + // the relisting time, which can vary significantly. Set a conservative // threshold to avoid flipping between healthy and unhealthy. RelistThreshold time.Duration }
type WatchCondition ¶
type WatchCondition = func(*kubecontainer.PodStatus) bool
WatchCondition takes the latest PodStatus, and returns whether the condition is met.
func RunningContainerWatchCondition ¶
func RunningContainerWatchCondition(containerName string, condition func(*kubecontainer.Status) bool) WatchCondition
RunningContainerWatchCondition wraps a condition on the container status to make a pod WatchCondition. If the container is no longer running, the condition is implicitly cleared.
Source Files ¶
doc.go evented.go generic.go pleg.go
- Version
- v1.33.0 (latest)
- Published
- Apr 23, 2025
- Platform
- linux/amd64
- Imports
- 16 packages
- Last checked
- 3 hours ago –
Tools for package owners.