schedulercache

package
v1.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNodeNameToInfoMap

func CreateNodeNameToInfoMap(pods []*api.Pod) map[string]*NodeInfo

CreateNodeNameToInfoMap obtains a list of pods and pivots that list into a map where the keys are node names and the values are the aggregated information for that node.

Types

type Cache added in v1.1.5

type Cache interface {
	// AssumePodIfBindSucceed assumes a pod to be scheduled if binding the pod succeeded.
	// If binding return true, the pod's information is aggregated into designated node.
	// Note that both binding and assuming are done as one atomic operation from cache's view.
	// No other events like Add would happen in between binding and assuming.
	// We are passing the binding function and let implementation take care of concurrency control details.
	// The implementation also decides the policy to expire pod before being confirmed (receiving Add event).
	// After expiration, its information would be subtracted.
	AssumePodIfBindSucceed(pod *api.Pod, bind func() bool) error

	// AddPod either confirms a pod if it's assumed, or adds it back if it's expired.
	// If added back, the pod's information would be added again.
	AddPod(pod *api.Pod) error

	// UpdatePod removes oldPod's information and adds newPod's information.
	UpdatePod(oldPod, newPod *api.Pod) error

	// RemovePod removes a pod. The pod's information would be subtracted from assigned node.
	RemovePod(pod *api.Pod) error

	// GetNodeNameToInfoMap returns a map of node names to node info. The node info contains
	// aggregated information of pods scheduled (including assumed to be) on this node.
	GetNodeNameToInfoMap() (map[string]*NodeInfo, error)

	// List lists all cached pods (including assumed ones).
	List(labels.Selector) ([]*api.Pod, error)
}

Cache collects pods' information and provides node-level aggregated information. It's intended for generic scheduler to do efficient lookup. Cache's operations are pod centric. It does incremental updates based on pod events. Pod events are sent via network. We don't have guaranteed delivery of all events: We use Reflector to list and watch from remote. Reflector might be slow and do a relist, which would lead to missing events.

State Machine of a pod's events in scheduler's cache:

+-------------------------------------------+  +----+
|                            Add            |  |    |
|                                           |  |    | Update
+      Assume                Add            v  v    |

Initial +--------> Assumed +------------+---> Added <--+

  • | + | | | | Add | | Remove | | | | + | +-------------> Expired +----> Deleted Expire

Note that an assumed pod can expire, because if we haven't received Add event notifying us for a while, there might be some problems and we shouldn't keep the pod in cache anymore.

Note that "Initial", "Expired", and "Deleted" pods do not actually exist in cache. Based on existing use cases, we are making the following assumptions:

  • No pod would be assumed twice
  • A pod could be added without going through scheduler. In this case, we will see Add but not Assume event.
  • If a pod wasn't added, it wouldn't be removed or updated.
  • Both "Expired" and "Deleted" are valid end states. In case of some problems, e.g. network issue, a pod might have changed its state (e.g. added and deleted) without delivering notification to the cache.

func New added in v1.1.5

func New(ttl time.Duration, stop chan struct{}) Cache

New returns a Cache implementation. It automatically starts a go routine that manages expiration of assumed pods. "ttl" is how long the assumed pod will get expired. "stop" is the channel that would close the background goroutine.

type NodeInfo

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

NodeInfo is node level aggregated information.

func NewNodeInfo

func NewNodeInfo(pods ...*api.Pod) *NodeInfo

NewNodeInfo returns a ready to use empty NodeInfo object. If any pods are given in arguments, their information will be aggregated in the returned object.

func (*NodeInfo) Clone added in v1.1.5

func (n *NodeInfo) Clone() *NodeInfo

func (*NodeInfo) NonZeroRequest added in v1.1.5

func (n *NodeInfo) NonZeroRequest() Resource

NonZeroRequest returns aggregated nonzero resource request of pods on this node.

func (*NodeInfo) Pods

func (n *NodeInfo) Pods() []*api.Pod

Pods return all pods scheduled (including assumed to be) on this node.

func (*NodeInfo) RequestedResource

func (n *NodeInfo) RequestedResource() Resource

RequestedResource returns aggregated resource request of pods on this node.

func (*NodeInfo) String

func (n *NodeInfo) String() string

String returns representation of human readable format of this NodeInfo.

type Resource

type Resource struct {
	MilliCPU int64
	Memory   int64
}

Resource is a collection of compute resource.

Jump to

Keyboard shortcuts

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