queue

package
v1.13.1-k3s1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NominatedNodeName

func NominatedNodeName(pod *v1.Pod) string

NominatedNodeName returns nominated node name of a Pod.

Types

type FIFO

type FIFO struct {
	*cache.FIFO
}

FIFO is basically a simple wrapper around cache.FIFO to make it compatible with the SchedulingQueue interface.

func NewFIFO

func NewFIFO() *FIFO

NewFIFO creates a FIFO object.

func (*FIFO) Add

func (f *FIFO) Add(pod *v1.Pod) error

Add adds a pod to the FIFO.

func (*FIFO) AddIfNotPresent

func (f *FIFO) AddIfNotPresent(pod *v1.Pod) error

AddIfNotPresent adds a pod to the FIFO if it is absent in the FIFO.

func (*FIFO) AddUnschedulableIfNotPresent

func (f *FIFO) AddUnschedulableIfNotPresent(pod *v1.Pod) error

AddUnschedulableIfNotPresent adds an unschedulable pod back to the queue. In FIFO it is added to the end of the queue.

func (*FIFO) AssignedPodAdded

func (f *FIFO) AssignedPodAdded(pod *v1.Pod)

AssignedPodAdded does nothing here.

func (*FIFO) AssignedPodUpdated

func (f *FIFO) AssignedPodUpdated(pod *v1.Pod)

AssignedPodUpdated does nothing here.

func (*FIFO) Close

func (f *FIFO) Close()

Close closes the FIFO queue.

func (*FIFO) Delete

func (f *FIFO) Delete(pod *v1.Pod) error

Delete deletes a pod in the FIFO.

func (*FIFO) DeleteNominatedPodIfExists

func (f *FIFO) DeleteNominatedPodIfExists(pod *v1.Pod)

DeleteNominatedPodIfExists does nothing in FIFO.

func (*FIFO) MoveAllToActiveQueue

func (f *FIFO) MoveAllToActiveQueue()

MoveAllToActiveQueue does nothing in FIFO as all pods are always in the active queue.

func (*FIFO) NumUnschedulablePods

func (f *FIFO) NumUnschedulablePods() int

NumUnschedulablePods returns the number of unschedulable pods exist in the SchedulingQueue.

func (*FIFO) Pop

func (f *FIFO) Pop() (*v1.Pod, error)

Pop removes the head of FIFO and returns it. This is just a copy/paste of cache.Pop(queue Queue) from fifo.go that scheduler has always been using. There is a comment in that file saying that this method shouldn't be used in production code, but scheduler has always been using it. This function does minimal error checking.

func (*FIFO) Update

func (f *FIFO) Update(oldPod, newPod *v1.Pod) error

Update updates a pod in the FIFO.

func (*FIFO) WaitingPods

func (f *FIFO) WaitingPods() []*v1.Pod

WaitingPods returns all the waiting pods in the queue.

func (*FIFO) WaitingPodsForNode

func (f *FIFO) WaitingPodsForNode(nodeName string) []*v1.Pod

WaitingPodsForNode returns pods that are nominated to run on the given node, but FIFO does not support it.

type Heap

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

Heap is a producer/consumer queue that implements a heap data structure. It can be used to implement priority queues and similar data structures.

func (*Heap) Add

func (h *Heap) Add(obj interface{}) error

Add inserts an item, and puts it in the queue. The item is updated if it already exists.

func (*Heap) AddIfNotPresent

func (h *Heap) AddIfNotPresent(obj interface{}) error

AddIfNotPresent inserts an item, and puts it in the queue. If an item with the key is present in the map, no changes is made to the item.

func (*Heap) Delete

func (h *Heap) Delete(obj interface{}) error

Delete removes an item.

func (*Heap) Get

func (h *Heap) Get(obj interface{}) (interface{}, bool, error)

Get returns the requested item, or sets exists=false.

func (*Heap) GetByKey

func (h *Heap) GetByKey(key string) (interface{}, bool, error)

GetByKey returns the requested item, or sets exists=false.

func (*Heap) List

func (h *Heap) List() []interface{}

List returns a list of all the items.

func (*Heap) Pop

func (h *Heap) Pop() (interface{}, error)

Pop returns the head of the heap.

func (*Heap) Update

func (h *Heap) Update(obj interface{}) error

Update is the same as Add in this implementation. When the item does not exist, it is added.

type KeyFunc

type KeyFunc func(obj interface{}) (string, error)

KeyFunc is a function type to get the key from an object.

type LessFunc

type LessFunc func(interface{}, interface{}) bool

LessFunc is a function type to compare two objects.

type PriorityQueue

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

PriorityQueue implements a scheduling queue. It is an alternative to FIFO. The head of PriorityQueue is the highest priority pending pod. This structure has two sub queues. One sub-queue holds pods that are being considered for scheduling. This is called activeQ and is a Heap. Another queue holds pods that are already tried and are determined to be unschedulable. The latter is called unschedulableQ.

func NewPriorityQueue

func NewPriorityQueue() *PriorityQueue

NewPriorityQueue creates a PriorityQueue object.

func (*PriorityQueue) Add

func (p *PriorityQueue) Add(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 either queue.

func (*PriorityQueue) AddIfNotPresent

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

AddIfNotPresent adds a pod to the active queue if it is not present in any of the two queues. If it is present in any, it doesn't do any thing.

func (*PriorityQueue) AddUnschedulableIfNotPresent

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

AddUnschedulableIfNotPresent does nothing if the pod is present in either queue. Otherwise it adds the pod to the unschedulable queue if p.receivedMoveRequest is false, and to the activeQ if p.receivedMoveRequest is true.

func (*PriorityQueue) AssignedPodAdded

func (p *PriorityQueue) AssignedPodAdded(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(pod *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 (p *PriorityQueue) DeleteNominatedPodIfExists(pod *v1.Pod)

DeleteNominatedPodIfExists deletes pod from internal cache if it's a nominatedPod

func (*PriorityQueue) MoveAllToActiveQueue

func (p *PriorityQueue) MoveAllToActiveQueue()

MoveAllToActiveQueue moves all pods from unschedulableQ to activeQ. This function adds all pods and then signals the condition variable to ensure that if Pop() is waiting for an item, it receives it after all the pods are in the queue and the head is the highest priority pod. TODO(bsalamat): We should add a back-off mechanism here so that a high priority pod which is unschedulable does not go to the head of the queue frequently. For example in a cluster where a lot of pods being deleted, such a high priority pod can deprive other pods from getting scheduled.

func (*PriorityQueue) NumUnschedulablePods

func (p *PriorityQueue) NumUnschedulablePods() int

NumUnschedulablePods returns the number of unschedulable pods exist in the SchedulingQueue.

func (*PriorityQueue) Pop

func (p *PriorityQueue) Pop() (*v1.Pod, 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 also clears receivedMoveRequest to mark the beginning of a new scheduling cycle.

func (*PriorityQueue) Update

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

Update updates a pod in the active queue if present. Otherwise, it removes the item from the unschedulable queue and adds the updated one to the active queue.

func (*PriorityQueue) WaitingPods

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

WaitingPods returns all the waiting pods in the queue.

func (*PriorityQueue) WaitingPodsForNode

func (p *PriorityQueue) WaitingPodsForNode(nodeName string) []*v1.Pod

WaitingPodsForNode returns pods that are nominated to run on the given node, but they are waiting for other pods to be removed from the node before they can be actually scheduled.

type SchedulingQueue

type SchedulingQueue interface {
	Add(pod *v1.Pod) error
	AddIfNotPresent(pod *v1.Pod) error
	AddUnschedulableIfNotPresent(pod *v1.Pod) error
	// 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() (*v1.Pod, error)
	Update(oldPod, newPod *v1.Pod) error
	Delete(pod *v1.Pod) error
	MoveAllToActiveQueue()
	AssignedPodAdded(pod *v1.Pod)
	AssignedPodUpdated(pod *v1.Pod)
	WaitingPodsForNode(nodeName string) []*v1.Pod
	WaitingPods() []*v1.Pod
	// Close closes the SchedulingQueue so that the goroutine which is
	// waiting to pop items can exit gracefully.
	Close()
	// DeleteNominatedPodIfExists deletes nominatedPod from internal cache
	DeleteNominatedPodIfExists(pod *v1.Pod)
	// NumUnschedulablePods returns the number of unschedulable pods exist in the SchedulingQueue.
	NumUnschedulablePods() int
}

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() SchedulingQueue

NewSchedulingQueue initializes a new scheduling queue. If pod priority is enabled a priority queue is returned. If it is disabled, a FIFO is returned.

type UnschedulablePodsMap

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

UnschedulablePodsMap holds pods that cannot be scheduled. This data structure is used to implement unschedulableQ.

Jump to

Keyboard shortcuts

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