queue

package
v1.30.3 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PodAdd is the event when a new pod is added to API server.
	PodAdd = "PodAdd"
	// ScheduleAttemptFailure is the event when a schedule attempt fails.
	ScheduleAttemptFailure = "ScheduleAttemptFailure"
	// BackoffComplete is the event when a pod finishes backoff.
	BackoffComplete = "BackoffComplete"
	// ForceActivate is the event when a pod is moved from unschedulablePods/backoffQ
	// to activeQ. Usually it's triggered by plugin implementations.
	ForceActivate = "ForceActivate"
	// PodUpdate is the event when a pod is updated
	PodUpdate = "PodUpdate"
)
View Source
const (
	// DefaultPodInitialBackoffDuration is the default value for the initial backoff duration
	// for unschedulable pods. To change the default podInitialBackoffDurationSeconds used by the
	// scheduler, update the ComponentConfig value in defaults.go
	DefaultPodInitialBackoffDuration time.Duration = 1 * time.Second
	// DefaultPodMaxBackoffDuration is the default value for the max backoff duration
	// for unschedulable pods. To change the default podMaxBackoffDurationSeconds used by the
	// scheduler, update the ComponentConfig value in defaults.go
	DefaultPodMaxBackoffDuration time.Duration = 10 * time.Second
)
View Source
const (
	// DefaultPodMaxInUnschedulablePodsDuration is the default value for the maximum
	// time a pod can stay in unschedulablePods. If a pod stays in unschedulablePods
	// for longer than this value, the pod will be moved from unschedulablePods to
	// backoffQ or activeQ. If this value is empty, the default value (5min)
	// will be used.
	DefaultPodMaxInUnschedulablePodsDuration time.Duration = 5 * time.Minute
)

Variables

View Source
var (
	// AssignedPodAdd is the event when a pod is added that causes pods with matching affinity terms
	// to be more schedulable.
	AssignedPodAdd = framework.ClusterEvent{Resource: framework.Pod, ActionType: framework.Add, Label: "AssignedPodAdd"}
	// NodeAdd is the event when a new node is added to the cluster.
	NodeAdd = framework.ClusterEvent{Resource: framework.Node, ActionType: framework.Add, Label: "NodeAdd"}
	// AssignedPodUpdate is the event when a pod is updated that causes pods with matching affinity
	// terms to be more schedulable.
	AssignedPodUpdate = framework.ClusterEvent{Resource: framework.Pod, ActionType: framework.Update, Label: "AssignedPodUpdate"}
	// AssignedPodDelete is the event when a pod is deleted that causes pods with matching affinity
	// terms to be more schedulable.
	AssignedPodDelete = framework.ClusterEvent{Resource: framework.Pod, ActionType: framework.Delete, Label: "AssignedPodDelete"}
	// NodeSpecUnschedulableChange is the event when unschedulable node spec is changed.
	NodeSpecUnschedulableChange = framework.ClusterEvent{Resource: framework.Node, ActionType: framework.UpdateNodeTaint, Label: "NodeSpecUnschedulableChange"}
	// NodeAllocatableChange is the event when node allocatable is changed.
	NodeAllocatableChange = framework.ClusterEvent{Resource: framework.Node, ActionType: framework.UpdateNodeAllocatable, Label: "NodeAllocatableChange"}
	// NodeLabelChange is the event when node label is changed.
	NodeLabelChange = framework.ClusterEvent{Resource: framework.Node, ActionType: framework.UpdateNodeLabel, Label: "NodeLabelChange"}
	// NodeAnnotationChange is the event when node annotation is changed.
	NodeAnnotationChange = framework.ClusterEvent{Resource: framework.Node, ActionType: framework.UpdateNodeAnnotation, Label: "NodeAnnotationChange"}
	// NodeTaintChange is the event when node taint is changed.
	NodeTaintChange = framework.ClusterEvent{Resource: framework.Node, ActionType: framework.UpdateNodeTaint, Label: "NodeTaintChange"}
	// NodeConditionChange is the event when node condition is changed.
	NodeConditionChange = framework.ClusterEvent{Resource: framework.Node, ActionType: framework.UpdateNodeCondition, Label: "NodeConditionChange"}
	// PvAdd is the event when a persistent volume is added in the cluster.
	PvAdd = framework.ClusterEvent{Resource: framework.PersistentVolume, ActionType: framework.Add, Label: "PvAdd"}
	// PvUpdate is the event when a persistent volume is updated in the cluster.
	PvUpdate = framework.ClusterEvent{Resource: framework.PersistentVolume, ActionType: framework.Update, Label: "PvUpdate"}
	// PvcAdd is the event when a persistent volume claim is added in the cluster.
	PvcAdd = framework.ClusterEvent{Resource: framework.PersistentVolumeClaim, ActionType: framework.Add, Label: "PvcAdd"}
	// PvcUpdate is the event when a persistent volume claim is updated in the cluster.
	PvcUpdate = framework.ClusterEvent{Resource: framework.PersistentVolumeClaim, ActionType: framework.Update, Label: "PvcUpdate"}
	// StorageClassAdd is the event when a StorageClass is added in the cluster.
	StorageClassAdd = framework.ClusterEvent{Resource: framework.StorageClass, ActionType: framework.Add, Label: "StorageClassAdd"}
	// StorageClassUpdate is the event when a StorageClass is updated in the cluster.
	StorageClassUpdate = framework.ClusterEvent{Resource: framework.StorageClass, ActionType: framework.Update, Label: "StorageClassUpdate"}
	// CSINodeAdd is the event when a CSI node is added in the cluster.
	CSINodeAdd = framework.ClusterEvent{Resource: framework.CSINode, ActionType: framework.Add, Label: "CSINodeAdd"}
	// CSINodeUpdate is the event when a CSI node is updated in the cluster.
	CSINodeUpdate = framework.ClusterEvent{Resource: framework.CSINode, ActionType: framework.Update, Label: "CSINodeUpdate"}
	// CSIDriverAdd is the event when a CSI driver is added in the cluster.
	CSIDriverAdd = framework.ClusterEvent{Resource: framework.CSIDriver, ActionType: framework.Add, Label: "CSIDriverAdd"}
	// CSIDriverUpdate is the event when a CSI driver is updated in the cluster.
	CSIDriverUpdate = framework.ClusterEvent{Resource: framework.CSIDriver, ActionType: framework.Update, Label: "CSIDriverUpdate"}
	// CSIStorageCapacityAdd is the event when a CSI storage capacity is added in the cluster.
	CSIStorageCapacityAdd = framework.ClusterEvent{Resource: framework.CSIStorageCapacity, ActionType: framework.Add, Label: "CSIStorageCapacityAdd"}
	// CSIStorageCapacityUpdate is the event when a CSI storage capacity is updated in the cluster.
	CSIStorageCapacityUpdate = framework.ClusterEvent{Resource: framework.CSIStorageCapacity, ActionType: framework.Update, Label: "CSIStorageCapacityUpdate"}
	// WildCardEvent semantically matches all resources on all actions.
	WildCardEvent = framework.ClusterEvent{Resource: framework.WildCard, ActionType: framework.All, Label: "WildCardEvent"}
	// UnschedulableTimeout is the event when a pod stays in unschedulable for longer than timeout.
	UnschedulableTimeout = framework.ClusterEvent{Resource: framework.WildCard, ActionType: framework.All, Label: "UnschedulableTimeout"}
)

Functions

func NewPodNominator added in v1.19.0

func NewPodNominator(podLister listersv1.PodLister) framework.PodNominator

NewPodNominator creates a nominator as a backing of framework.PodNominator. A podLister is passed in so as to check if the pod exists before adding its nominatedNode info.

func NominatedNodeName

func NominatedNodeName(pod *v1.Pod) string

NominatedNodeName returns nominated node name of a Pod.

Types

type Option added in v1.17.0

type Option func(*priorityQueueOptions)

Option configures a PriorityQueue

func WithClock added in v1.17.0

func WithClock(clock clock.Clock) Option

WithClock sets clock for PriorityQueue, the default clock is clock.RealClock.

func WithMetricsRecorder added in v1.27.0

func WithMetricsRecorder(recorder metrics.MetricAsyncRecorder) Option

WithMetricsRecorder sets metrics recorder.

func WithPluginMetricsSamplePercent added in v1.27.0

func WithPluginMetricsSamplePercent(percent int) Option

WithPluginMetricsSamplePercent sets the percentage of plugin metrics to be sampled.

func WithPodInitialBackoffDuration added in v1.17.0

func WithPodInitialBackoffDuration(duration time.Duration) Option

WithPodInitialBackoffDuration sets pod initial backoff duration for PriorityQueue.

func WithPodLister added in v1.24.12

func WithPodLister(pl listersv1.PodLister) Option

WithPodLister sets pod lister for PriorityQueue.

func WithPodMaxBackoffDuration added in v1.17.0

func WithPodMaxBackoffDuration(duration time.Duration) Option

WithPodMaxBackoffDuration sets pod max backoff duration for PriorityQueue.

func WithPodMaxInUnschedulablePodsDuration added in v1.24.0

func WithPodMaxInUnschedulablePodsDuration(duration time.Duration) Option

WithPodMaxInUnschedulablePodsDuration sets podMaxInUnschedulablePodsDuration for PriorityQueue.

func WithPreEnqueuePluginMap added in v1.26.0

func WithPreEnqueuePluginMap(m map[string][]framework.PreEnqueuePlugin) Option

WithPreEnqueuePluginMap sets preEnqueuePluginMap for PriorityQueue.

func WithQueueingHintMapPerProfile added in v1.28.0

func WithQueueingHintMapPerProfile(m QueueingHintMapPerProfile) Option

WithQueueingHintMapPerProfile sets queueingHintMap for PriorityQueue.

type PreEnqueueCheck added in v1.22.0

type PreEnqueueCheck func(pod *v1.Pod) bool

PreEnqueueCheck is a function type. It's used to build functions that run against a Pod and the caller can choose to enqueue or skip the Pod by the checking result.

type PriorityQueue

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

PriorityQueue implements a scheduling queue. The head of PriorityQueue is the highest priority pending pod. This structure has two sub queues and a additional data structure, namely: activeQ, backoffQ and unschedulablePods.

  • activeQ holds pods that are being considered for scheduling.
  • backoffQ holds pods that moved from unschedulablePods and will move to activeQ when their backoff periods complete.
  • unschedulablePods holds pods that were already attempted for scheduling and are currently determined to be unschedulable.

func NewPriorityQueue

func NewPriorityQueue(
	lessFn framework.LessFunc,
	informerFactory informers.SharedInformerFactory,
	opts ...Option,
) *PriorityQueue

NewPriorityQueue creates a PriorityQueue object.

func NewTestQueue added in v1.21.0

func NewTestQueue(ctx context.Context, lessFn framework.LessFunc, opts ...Option) *PriorityQueue

NewTestQueue creates a priority queue with an empty informer factory.

func NewTestQueueWithInformerFactory added in v1.24.0

func NewTestQueueWithInformerFactory(
	ctx context.Context,
	lessFn framework.LessFunc,
	informerFactory informers.SharedInformerFactory,
	opts ...Option,
) *PriorityQueue

func NewTestQueueWithObjects added in v1.21.0

func NewTestQueueWithObjects(
	ctx context.Context,
	lessFn framework.LessFunc,
	objs []runtime.Object,
	opts ...Option,
) *PriorityQueue

NewTestQueueWithObjects creates a priority queue with an informer factory populated with the provided objects.

func (*PriorityQueue) Activate added in v1.22.0

func (p *PriorityQueue) Activate(logger klog.Logger, pods map[string]*v1.Pod)

Activate moves the given pods to activeQ iff they're in unschedulablePods or backoffQ.

func (*PriorityQueue) Add

func (p *PriorityQueue) Add(logger klog.Logger, pod *v1.Pod) error

Add adds a pod to the active queue. It should be called only when a new pod is added so there is no chance the pod is already in active/unschedulable/backoff queues

func (PriorityQueue) AddNominatedPod added in v1.24.12

func (npm PriorityQueue) AddNominatedPod(logger klog.Logger, pi *framework.PodInfo, nominatingInfo *framework.NominatingInfo)

AddNominatedPod adds a pod to the nominated pods of the given node. This is called during the preemption process after a node is nominated to run the pod. We update the structure before sending a request to update the pod object to avoid races with the following scheduling cycles.

func (*PriorityQueue) AddUnschedulableIfNotPresent

func (p *PriorityQueue) AddUnschedulableIfNotPresent(logger klog.Logger, pInfo *framework.QueuedPodInfo, podSchedulingCycle int64) error

AddUnschedulableIfNotPresent inserts a pod that cannot be scheduled into the queue, unless it is already in the queue. Normally, PriorityQueue puts unschedulable pods in `unschedulablePods`. But if there has been a recent move request, then the pod is put in `podBackoffQ`.

func (*PriorityQueue) AssignedPodAdded

func (p *PriorityQueue) AssignedPodAdded(logger klog.Logger, pod *v1.Pod)

AssignedPodAdded is called when a bound pod is added. Creation of this pod may make pending pods with matching affinity terms schedulable.

func (*PriorityQueue) AssignedPodUpdated

func (p *PriorityQueue) AssignedPodUpdated(logger klog.Logger, oldPod, newPod *v1.Pod)

AssignedPodUpdated is called when a bound pod is updated. Change of labels may make pending pods with matching affinity terms schedulable.

func (*PriorityQueue) Close

func (p *PriorityQueue) Close()

Close closes the priority queue.

func (*PriorityQueue) Delete

func (p *PriorityQueue) Delete(pod *v1.Pod) error

Delete deletes the item from either of the two queues. It assumes the pod is only in one queue.

func (PriorityQueue) DeleteNominatedPodIfExists

func (npm PriorityQueue) DeleteNominatedPodIfExists(pod *v1.Pod)

DeleteNominatedPodIfExists deletes <pod> from nominatedPods.

func (*PriorityQueue) Done added in v1.28.0

func (p *PriorityQueue) Done(pod types.UID)

Done must be called for pod returned by Pop. This allows the queue to keep track of which pods are currently being processed.

func (*PriorityQueue) MoveAllToActiveOrBackoffQueue added in v1.17.0

func (p *PriorityQueue) MoveAllToActiveOrBackoffQueue(logger klog.Logger, event framework.ClusterEvent, oldObj, newObj interface{}, preCheck PreEnqueueCheck)

MoveAllToActiveOrBackoffQueue moves all pods from unschedulablePods to activeQ or backoffQ. This function adds all pods and then signals the condition variable to ensure that if Pop() is waiting for an item, it receives the signal after all the pods are in the queue and the head is the highest priority pod.

func (PriorityQueue) NominatedPodsForNode added in v1.13.2

func (npm PriorityQueue) NominatedPodsForNode(nodeName string) []*framework.PodInfo

NominatedPodsForNode returns a copy of pods that are nominated to run on the given node, but they are waiting for other pods to be removed from the node.

func (*PriorityQueue) PendingPods added in v1.14.0

func (p *PriorityQueue) PendingPods() ([]*v1.Pod, string)

PendingPods returns all the pending pods in the queue; accompanied by a debugging string recording showing the number of pods in each queue respectively. This function is used for debugging purposes in the scheduler cache dumper and comparer.

func (*PriorityQueue) PodsInActiveQ added in v1.30.0

func (p *PriorityQueue) PodsInActiveQ() []*v1.Pod

PodsInActiveQ returns all the Pods in the activeQ. This function is only used in tests.

func (*PriorityQueue) Pop

func (p *PriorityQueue) Pop(logger klog.Logger) (*framework.QueuedPodInfo, error)

Pop removes the head of the active queue and returns it. It blocks if the activeQ is empty and waits until a new item is added to the queue. It increments scheduling cycle when a pod is popped.

func (*PriorityQueue) Run added in v1.18.0

func (p *PriorityQueue) Run(logger klog.Logger)

Run starts the goroutine to pump from podBackoffQ to activeQ

func (*PriorityQueue) SchedulingCycle added in v1.13.4

func (p *PriorityQueue) SchedulingCycle() int64

SchedulingCycle returns current scheduling cycle.

func (*PriorityQueue) Update

func (p *PriorityQueue) Update(logger klog.Logger, oldPod, newPod *v1.Pod) error

Update updates a pod in the active or backoff queue if present. Otherwise, it removes the item from the unschedulable queue if pod is updated in a way that it may become schedulable and adds the updated one to the active queue. If pod is not present in any of the queues, it is added to the active queue.

func (PriorityQueue) UpdateNominatedPod added in v1.24.12

func (npm PriorityQueue) UpdateNominatedPod(logger klog.Logger, oldPod *v1.Pod, newPodInfo *framework.PodInfo)

UpdateNominatedPod updates the <oldPod> with <newPod>.

type QueueingHintFunction added in v1.28.0

type QueueingHintFunction struct {
	PluginName     string
	QueueingHintFn framework.QueueingHintFn
}

QueueingHintFunction is the wrapper of QueueingHintFn that has PluginName.

type QueueingHintMap added in v1.28.0

type QueueingHintMap map[framework.ClusterEvent][]*QueueingHintFunction

QueueingHintMap is keyed with ClusterEvent, valued with queueing hint functions registered for the event.

type QueueingHintMapPerProfile added in v1.28.0

type QueueingHintMapPerProfile map[string]QueueingHintMap

QueueingHintMapPerProfile is keyed with profile name, valued with queueing hint map registered for the profile.

type SchedulingQueue

type SchedulingQueue interface {
	framework.PodNominator
	Add(logger klog.Logger, pod *v1.Pod) error
	// Activate moves the given pods to activeQ iff they're in unschedulablePods or backoffQ.
	// The passed-in pods are originally compiled from plugins that want to activate Pods,
	// by injecting the pods through a reserved CycleState struct (PodsToActivate).
	Activate(logger klog.Logger, pods map[string]*v1.Pod)
	// AddUnschedulableIfNotPresent adds an unschedulable pod back to scheduling queue.
	// The podSchedulingCycle represents the current scheduling cycle number which can be
	// returned by calling SchedulingCycle().
	AddUnschedulableIfNotPresent(logger klog.Logger, pod *framework.QueuedPodInfo, podSchedulingCycle int64) error
	// SchedulingCycle returns the current number of scheduling cycle which is
	// cached by scheduling queue. Normally, incrementing this number whenever
	// a pod is popped (e.g. called Pop()) is enough.
	SchedulingCycle() int64
	// Pop removes the head of the queue and returns it. It blocks if the
	// queue is empty and waits until a new item is added to the queue.
	Pop(logger klog.Logger) (*framework.QueuedPodInfo, error)
	// Done must be called for pod returned by Pop. This allows the queue to
	// keep track of which pods are currently being processed.
	Done(types.UID)
	Update(logger klog.Logger, oldPod, newPod *v1.Pod) error
	Delete(pod *v1.Pod) error
	// TODO(sanposhiho): move all PreEnqueueCkeck to Requeue and delete it from this parameter eventually.
	// Some PreEnqueueCheck include event filtering logic based on some in-tree plugins
	// and it affect badly to other plugins.
	// See https://github.com/kubernetes/kubernetes/issues/110175
	MoveAllToActiveOrBackoffQueue(logger klog.Logger, event framework.ClusterEvent, oldObj, newObj interface{}, preCheck PreEnqueueCheck)
	AssignedPodAdded(logger klog.Logger, pod *v1.Pod)
	AssignedPodUpdated(logger klog.Logger, oldPod, newPod *v1.Pod)
	PendingPods() ([]*v1.Pod, string)
	PodsInActiveQ() []*v1.Pod
	// Close closes the SchedulingQueue so that the goroutine which is
	// waiting to pop items can exit gracefully.
	Close()
	// Run starts the goroutines managing the queue.
	Run(logger klog.Logger)
}

SchedulingQueue is an interface for a queue to store pods waiting to be scheduled. The interface follows a pattern similar to cache.FIFO and cache.Heap and makes it easy to use those data structures as a SchedulingQueue.

func NewSchedulingQueue

func NewSchedulingQueue(
	lessFn framework.LessFunc,
	informerFactory informers.SharedInformerFactory,
	opts ...Option) SchedulingQueue

NewSchedulingQueue initializes a priority queue as a new scheduling queue.

type UnschedulablePods added in v1.24.0

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

UnschedulablePods holds pods that cannot be scheduled. This data structure is used to implement unschedulablePods.

Jump to

Keyboard shortcuts

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