pleg

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 16 Imported by: 49

Documentation

Overview

Package pleg contains types and a generic implementation of the pod lifecycle event generator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventedPLEG added in v1.26.0

type EventedPLEG struct {
	// contains filtered or unexported fields
}

func (*EventedPLEG) Healthy added in v1.26.0

func (e *EventedPLEG) Healthy() (bool, error)

Healthy check if PLEG work properly.

func (*EventedPLEG) Relist added in v1.26.0

func (e *EventedPLEG) Relist()

Relist relists all containers using GenericPLEG

func (*EventedPLEG) Start added in v1.26.0

func (e *EventedPLEG) Start()

Start starts the Evented PLEG

func (*EventedPLEG) Stop added in v1.26.0

func (e *EventedPLEG) Stop()

Stop stops the Evented PLEG

func (*EventedPLEG) Update added in v1.26.0

func (e *EventedPLEG) Update(relistDuration *RelistDuration)

Update the relisting period and threshold

func (*EventedPLEG) UpdateCache added in v1.27.0

func (e *EventedPLEG) UpdateCache(pod *kubecontainer.Pod, pid types.UID) (error, bool)

func (*EventedPLEG) Watch added in v1.26.0

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 added in v1.26.0

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) Start

func (g *GenericPLEG) Start()

Start spawns a goroutine to relist periodically.

func (*GenericPLEG) Stop added in v1.26.0

func (g *GenericPLEG) Stop()

func (*GenericPLEG) Update added in v1.26.0

func (g *GenericPLEG) Update(relistDuration *RelistDuration)

func (*GenericPLEG) UpdateCache added in v1.27.0

func (g *GenericPLEG) UpdateCache(pod *kubecontainer.Pod, pid types.UID) (error, bool)

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"
)

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)
	UpdateCache(*kubecontainer.Pod, types.UID) (error, bool)
}

PodLifecycleEventGenerator contains functions for generating pod life cycle events.

func NewEventedPLEG added in v1.26.0

func NewEventedPLEG(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(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 added in v1.26.0

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
}

Jump to

Keyboard shortcuts

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