cache

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// NodeCount returns the number of nodes in the cache.
	// DO NOT use outside of tests.
	NodeCount() int

	// PodCount returns the number of pods in the cache (including those from deleted nodes).
	// DO NOT use outside of tests.
	PodCount() (int, error)

	// AssumePod assumes a pod scheduled and aggregates the pod's information into its node.
	// The implementation also decides the policy to expire pod before being confirmed (receiving Add event).
	// After expiration, its information would be subtracted.
	AssumePod(pod *corev1.Pod) error

	// FinishBinding signals that cache for assumed pod can be expired
	FinishBinding(pod *corev1.Pod) error

	// ForgetPod removes an assumed pod from cache.
	ForgetPod(pod *corev1.Pod) 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 *corev1.Pod) error

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

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

	// GetPod returns the pod from the cache with the same namespace and the
	// same name of the specified pod.
	GetPod(pod *corev1.Pod) (*corev1.Pod, error)

	// IsAssumedPod returns true if the pod is assumed and not expired.
	IsAssumedPod(pod *corev1.Pod) (bool, error)

	// AddNode adds overall information about node.
	// It returns a clone of added NodeInfo object.
	AddNode(node *corev1.Node) *framework.NodeInfo

	// UpdateNode updates overall information about node.
	// It returns a clone of updated NodeInfo object.
	UpdateNode(oldNode, newNode *corev1.Node) *framework.NodeInfo

	// RemoveNode removes overall information about node.
	RemoveNode(node *corev1.Node) error

	// UpdateSnapshot updates the passed infoSnapshot to the current contents of Cache.
	// The node info contains aggregated information of pods scheduled (including assumed to be)
	// on this node.
	// The snapshot only includes Nodes that are not deleted at the time this function is called.
	// nodeinfo.Node() is guaranteed to be not nil for all the nodes in the snapshot.
	UpdateSnapshot(nodeSnapshot *Snapshot) error

	// Dump produces a dump of the current cache.
	Dump() *Dump
}

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
      Forget             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

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, "0" means pod will never expire. "stop" is the channel that would close the background goroutine.

type Dump

type Dump struct {
	//nolint:staticcheck
	// disable `deprecation` check for lifted code.
	AssumedPods sets.String
	Nodes       map[string]*framework.NodeInfo
}

Dump is a dump of the cache state.

type Snapshot

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

Snapshot is a snapshot of cache NodeInfo and NodeTree order. The scheduler takes a snapshot at the beginning of each scheduling cycle and uses it for its operations in that cycle.

func NewEmptySnapshot

func NewEmptySnapshot() *Snapshot

NewEmptySnapshot initializes a Snapshot struct and returns it.

func NewSnapshot

func NewSnapshot(pods []*corev1.Pod, nodes []*corev1.Node) *Snapshot

NewSnapshot initializes a Snapshot struct and returns it.

func (*Snapshot) Get

func (s *Snapshot) Get(nodeName string) (*framework.NodeInfo, error)

Get returns the NodeInfo of the given node name.

func (*Snapshot) HavePodsWithAffinityList

func (s *Snapshot) HavePodsWithAffinityList() ([]*framework.NodeInfo, error)

HavePodsWithAffinityList returns the list of nodes with at least one pod with inter-pod affinity

func (*Snapshot) HavePodsWithRequiredAntiAffinityList

func (s *Snapshot) HavePodsWithRequiredAntiAffinityList() ([]*framework.NodeInfo, error)

HavePodsWithRequiredAntiAffinityList returns the list of nodes with at least one pod with required inter-pod anti-affinity

func (*Snapshot) IsPVCUsedByPods

func (s *Snapshot) IsPVCUsedByPods(key string) bool

IsPVCUsedByPods returns true/false on whether the PVC is used by one or more scheduled pods, keyed in the format "namespace/name".

func (*Snapshot) List

func (s *Snapshot) List() ([]*framework.NodeInfo, error)

List returns the list of nodes in the snapshot.

func (*Snapshot) NodeInfos

func (s *Snapshot) NodeInfos() framework.NodeInfoLister

NodeInfos returns a NodeInfoLister.

func (*Snapshot) NumNodes

func (s *Snapshot) NumNodes() int

NumNodes returns the number of nodes in the snapshot.

func (*Snapshot) StorageInfos

func (s *Snapshot) StorageInfos() framework.StorageInfoLister

StorageInfos returns a StorageInfoLister.

Jump to

Keyboard shortcuts

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