framework

package
v0.0.0-...-89e5b94 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 48 Imported by: 3

Documentation

Index

Constants

View Source
const (
	PodInitializing   = "PodInitializing"
	ContainerCreating = "ContainerCreating"
)

Container state reason list

View Source
const (
	// NetworkNotReadyErrorMsg is used to describe the error that network is not ready
	NetworkNotReadyErrorMsg = "network is not ready"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type KillPodOptions

type KillPodOptions struct {
	// CompletedCh is closed when the kill request completes (syncTerminatingPod has completed
	// without error) or if the pod does not exist, or if the pod has already terminated. This
	// could take an arbitrary amount of time to be closed, but is never left open once
	// CouldHaveRunningContainers() returns false.
	CompletedCh chan<- struct{}
	// Evict is true if this is a pod triggered eviction - once a pod is evicted some resources are
	// more aggressively reaped than during normal pod operation (stopped containers).
	Evict bool
	// PodStatusFunc is invoked (if set) and overrides the status of the pod at the time the pod is killed.
	// The provided status is populated from the latest state.
	PodStatusFunc PodStatusFunc
	// PodTerminationGracePeriodSecondsOverride is optional override to use if a pod is being killed as part of kill operation.
	PodTerminationGracePeriodSecondsOverride *int64
}

KillPodOptions are options when performing a pod update whose update type is kill.

type NodeController

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

NodeController deals with creating and managing a node object in Kubernetes. It can register a node with Kubernetes and periodically update its status. NodeController manages a single node entity.

func NewNodeController

func NewNodeController(namespace string, p kri.NodeProvider, nodes v1.NodeInterface, leaseStub coordtypes.LeaseInterface, cfg *config.NodeCfg) (*NodeController, error)

NewNodeController creates a new node controller. This does not have any side-effects on the system or kubernetes.

Use the node's `Run` method to register and run the loops to update the node in Kubernetes.

Note: When if there are multiple NodeControllerOpts which apply against the same underlying options, the last NodeControllerOpt will win.

func (*NodeController) GetNode

func (nc *NodeController) GetNode() (*corev1.Node, error)

func (*NodeController) NotifyAgentReady

func (nc *NodeController) NotifyAgentReady()

NotifyAgentReady tells k8s master I'm ready.

func (*NodeController) Ready

func (nc *NodeController) Ready() <-chan struct{}

Ready returns a channel that gets closed when the node is fully up and running. Note that if there is an error on startup this channel will never be started.

func (*NodeController) Run

func (nc *NodeController) Run(ctx context.Context) error

Run registers the node in kubernetes and starts loops for updating the node status in Kubernetes.

The node status must be updated periodically in Kubernetes to keep the node active. Newer versions of Kubernetes support node leases, which are essentially light weight pings. Older versions of Kubernetes require updating the node status periodically.

If Kubernetes supports node leases this will use leases with a much slower node status update (because some things still expect the node to be updated periodically), otherwise it will only use node status update with the configured ping interval.

func (*NodeController) Stop

func (nc *NodeController) Stop()

func (*NodeController) WaitAgentReady

func (nc *NodeController) WaitAgentReady(ctx context.Context)

type NodeGetter

type NodeGetter interface {
	GetNode() (*corev1.Node, error)
}

type OnCompleteFunc

type OnCompleteFunc func(err error)

OnCompleteFunc is a function that is invoked when an operation completes. If err is non-nil, the operation did not complete successfully.

type PodStateProvider

type PodStateProvider interface {
	IsPodTerminationRequested(types.UID) bool
	ShouldPodContentBeRemoved(types.UID) bool
	ShouldPodRuntimeBeRemoved(types.UID) bool
}

PodStateProvider can determine if none of the elements are necessary to retain (pod content) or if none of the runtime elements are necessary to retain (containers)

type PodStatusFunc

type PodStatusFunc func(podStatus *v1.PodStatus)

PodStatusFunc is a function that is invoked to override the pod status when a pod is killed.

type PodWorkType

type PodWorkType int

PodWorkType classifies the three phases of pod lifecycle - setup (sync), teardown of containers (terminating), cleanup (terminated).

const (
	// SyncPodWork is when the pod is expected to be started and running.
	SyncPodWork PodWorkType = iota
	// TerminatingPodWork is when the pod is no longer being set up, but some
	// containers may be running and are being torn down.
	TerminatingPodWork
	// TerminatedPodWork indicates the pod is stopped, can have no more running
	// containers, and any foreground cleanup can be executed.
	TerminatedPodWork
)

type PodWorkerState

type PodWorkerState int

PodWorkType classifies the status of pod as seen by the pod worker - setup (sync), teardown of containers (terminating), cleanup (terminated), or recreated with the same UID (kill -> create while terminating)

const (
	// SyncPod is when the pod is expected to be started and running.
	SyncPod PodWorkerState = iota
	// TerminatingPod is when the pod is no longer being set up, but some
	// containers may be running and are being torn down.
	TerminatingPod
	// TerminatedPod indicates the pod is stopped, can have no more running
	// containers, and any foreground cleanup can be executed.
	TerminatedPod
	// TerminatedAndRecreatedPod indicates that after the pod was terminating a
	// request to recreate the pod was received. The pod is terminated and can
	// now be restarted by sending a create event to the pod worker.
	TerminatedAndRecreatedPod
)

type PodWorkers

type PodWorkers interface {
	// UpdatePod notifies the pod worker of a change to a pod, which will then
	// be processed in FIFO order by a goroutine per pod UID. The state of the
	// pod will be passed to the syncPod method until either the pod is marked
	// as deleted, it reaches a terminal phase (Succeeded/Failed), or the pod
	// is evicted by the kubelet. Once that occurs the syncTerminatingPod method
	// will be called until it exits successfully, and after that all further
	// UpdatePod() calls will be ignored for that pod until it has been forgotten
	// due to significant time passing. A pod that is terminated will never be
	// restarted.
	UpdatePod(options UpdatePodOptions)
	// SyncKnownPods removes workers for pods that are not in the desiredPods set
	// and have been terminated for a significant period of time. Once this method
	// has been called once, the workers are assumed to be fully initialized and
	// subsequent calls to ShouldPodContentBeRemoved on unknown pods will return
	// true. It returns a map describing the state of each known pod worker.
	SyncKnownPods(desiredPods []*v1.Pod) map[types.UID]PodWorkerState

	// IsPodKnownTerminated returns true if the provided pod UID is known by the pod
	// worker to be terminated. If the pod has been force deleted and the pod worker
	// has completed termination this method will return false, so this method should
	// only be used to filter out pods from the desired set such as in admission.
	//
	// Intended for use by the kubelet config loops, but not subsystems, which should
	// use ShouldPod*().
	IsPodKnownTerminated(uid types.UID) bool
	// CouldHaveRunningContainers returns true before the pod workers have synced,
	// once the pod workers see the pod (syncPod could be called), and returns false
	// after the pod has been terminated (running containers guaranteed stopped).
	//
	// Intended for use by the kubelet config loops, but not subsystems, which should
	// use ShouldPod*().
	CouldHaveRunningContainers(uid types.UID) bool
	// IsPodTerminationRequested returns true when pod termination has been requested
	// until the termination completes and the pod is removed from config. This should
	// not be used in cleanup loops because it will return false if the pod has already
	// been cleaned up - use ShouldPodContainersBeTerminating instead. Also, this method
	// may return true while containers are still being initialized by the pod worker.
	//
	// Intended for use by the kubelet sync* methods, but not subsystems, which should
	// use ShouldPod*().
	IsPodTerminationRequested(uid types.UID) bool

	// ShouldPodContainersBeTerminating returns false before pod workers have synced,
	// or once a pod has started terminating. This check is similar to
	// ShouldPodRuntimeBeRemoved but is also true after pod termination is requested.
	//
	// Intended for use by subsystem sync loops to avoid performing background setup
	// after termination has been requested for a pod. Callers must ensure that the
	// syncPod method is non-blocking when their data is absent.
	ShouldPodContainersBeTerminating(uid types.UID) bool
	// ShouldPodRuntimeBeRemoved returns true if runtime managers within the Kubelet
	// should aggressively cleanup pod resources that are not containers or on disk
	// content, like attached volumes. This is true when a pod is not yet observed
	// by a worker after the first sync (meaning it can't be running yet) or after
	// all running containers are stopped.
	// TODO: Once pod logs are separated from running containers, this method should
	// be used to gate whether containers are kept.
	//
	// Intended for use by subsystem sync loops to know when to start tearing down
	// resources that are used by running containers. Callers should ensure that
	// runtime content they own is not required for post-termination - for instance
	// containers are required in docker to preserve pod logs until after the pod
	// is deleted.
	ShouldPodRuntimeBeRemoved(uid types.UID) bool
	// ShouldPodContentBeRemoved returns true if resource managers within the Kubelet
	// should aggressively cleanup all content related to the pod. This is true
	// during pod eviction (when we wish to remove that content to free resources)
	// as well as after the request to delete a pod has resulted in containers being
	// stopped (which is a more graceful action). Note that a deleting pod can still
	// be evicted.
	//
	// Intended for use by subsystem sync loops to know when to start tearing down
	// resources that are used by non-deleted pods. Content is generally preserved
	// until deletion+removal_from_etcd or eviction, although garbage collection
	// can free content when this method returns false.
	ShouldPodContentBeRemoved(uid types.UID) bool
	// IsPodForMirrorPodTerminatingByFullName returns true if a static pod with the
	// provided pod name is currently terminating and has yet to complete. It is
	// intended to be used only during orphan mirror pod cleanup to prevent us from
	// deleting a terminating static pod from the apiserver before the pod is shut
	// down.
	IsPodForMirrorPodTerminatingByFullName(podFullname string) bool
}

PodWorkers is an abstract interface for testability.

type PodsController

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

PodsController is the controller implementation for Pod resources.

func NewPodsController

func NewPodsController(cfg *PodsControllerConfig) (*PodsController, error)

NewPodsController creates a new pod controller with the provided config.

func (*PodsController) GetPodStateProvider

func (pc *PodsController) GetPodStateProvider() PodStateProvider

func (*PodsController) GetStatusManager

func (pc *PodsController) GetStatusManager() status.Manager

func (*PodsController) HandlePodAdditions

func (pc *PodsController) HandlePodAdditions(pods []*corev1.Pod)

HandlePodAdditions is the callback in SyncHandler for pods being added from a config source.

func (*PodsController) HandlePodCleanups

func (pc *PodsController) HandlePodCleanups(ctx context.Context) error

HandlePodCleanups performs a series of cleanup work, including terminating pod workers, killing unwanted pods, and removing orphaned volumes/pod directories. No config changes are sent to pod workers while this method is executing which means no new pods can appear. NOTE: This function is executed by the main sync loop, so it should not contain any blocking calls.

func (*PodsController) HandlePodReconcile

func (pc *PodsController) HandlePodReconcile(pods []*corev1.Pod)

HandlePodReconcile is the callback in the SyncHandler interface for pods that should be reconciled.

func (*PodsController) HandlePodRemoves

func (pc *PodsController) HandlePodRemoves(pods []*corev1.Pod)

HandlePodRemoves is the callback in the SyncHandler interface for pods being removed from a config source.

func (*PodsController) HandlePodSyncByUID

func (pc *PodsController) HandlePodSyncByUID(uid types.UID)

func (*PodsController) HandlePodSyncs

func (pc *PodsController) HandlePodSyncs(pods []*corev1.Pod)

HandlePodSyncs is the callback in the syncHandler interface for pods that should be dispatched to pod workers for sync.

func (*PodsController) HandlePodUpdates

func (pc *PodsController) HandlePodUpdates(pods []*corev1.Pod)

HandlePodUpdates is the callback in the SyncHandler interface for pods being updated from a config source.

func (*PodsController) PodCouldHaveRunningContainers

func (pc *PodsController) PodCouldHaveRunningContainers(pod *corev1.Pod) bool

PodCouldHaveRunningContainers returns true if the pod with the given UID could still have running containers. This returns false if the pod has not yet been started or the pod is unknown.

func (*PodsController) PodResourcesAreReclaimed

func (pc *PodsController) PodResourcesAreReclaimed(pod *corev1.Pod, status corev1.PodStatus) bool

PodResourcesAreReclaimed returns true if all required node-level resources that a pod was consuming have been reclaimed by the kubelet. Reclaiming resources is a prerequisite to deleting a pod from the API server.

func (*PodsController) Ready

func (pc *PodsController) Ready() <-chan struct{}

Ready returns a channel which gets closed once the PodsController is ready to handle scheduled pods. This channel will never close if there is an error on startup. The status of this channel after shutdown is indeterminate.

func (*PodsController) RegisterProvider

func (pc *PodsController) RegisterProvider(provider kri.PodProvider)

func (*PodsController) Run

func (pc *PodsController) Run(ctx context.Context) error

Run will set up the event handlers for types we are interested in, as well as syncing informer caches and starting workers. It will block until the context is cancelled, at which point it will shutdown the work queue and wait for workers to finish processing their current work items prior to returning.

Once this returns, you should not re-use the controller.

func (*PodsController) Stop

func (pc *PodsController) Stop() chan struct{}

type PodsControllerConfig

type PodsControllerConfig struct {
	Namespace string
	NodeName  string
	NodeIP    string

	ConfigCh     <-chan kubetypes.PodUpdate
	FrameworkCfg *config.FrameworkCfg
	RegistryCfg  *config.RegistryCfg

	KubeClient clientset.Interface

	NodeGetter NodeGetter

	EventRecorder record.EventRecorder

	SourcesReady SourcesReady
}

PodsControllerConfig is used to configure a new PodsController.

type SourcesReady

type SourcesReady interface {
	// AllReady returns true if the currently configured sources have all been seen.
	AllReady() bool
}

SourcesReady tracks the set of configured sources seen by the agent.

type SyncHandler

type SyncHandler interface {
	HandlePodAdditions(pods []*corev1.Pod)
	HandlePodUpdates(pods []*corev1.Pod)
	HandlePodRemoves(pods []*corev1.Pod)
	HandlePodReconcile(pods []*corev1.Pod)
	HandlePodSyncs(pods []*corev1.Pod)
	HandlePodSyncByUID(uid types.UID)
	HandlePodCleanups(ctx context.Context) error
}

SyncHandler is an interface implemented by agent

type UpdatePodOptions

type UpdatePodOptions struct {
	// The type of update (create, update, sync, kill).
	UpdateType kubetypes.SyncPodType
	// StartTime is an optional timestamp for when this update was created. If set,
	// when this update is fully realized by the pod worker it will be recorded in
	// the PodWorkerDuration metric.
	StartTime time.Time
	// Pod to update. Required.
	Pod *v1.Pod
	// MirrorPod is the mirror pod if Pod is a static pod. Optional when UpdateType
	// is kill or terminated.
	MirrorPod *v1.Pod
	// RunningPod is a runtime pod that is no longer present in config. Required
	// if Pod is nil, ignored if Pod is set.
	RunningPod *pkgcontainer.Pod
	// KillPodOptions is used to override the default termination behavior of the
	// pod or to update the pod status after an operation is completed. Since a
	// pod can be killed for multiple reasons, PodStatusFunc is invoked in order
	// and later kills have an opportunity to override the status (i.e. a preemption
	// may be later turned into an eviction).
	KillPodOptions *KillPodOptions
}

UpdatePodOptions is an options struct to pass to a UpdatePod operation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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