clustersnapshot

package
v0.0.0-...-30e57c9 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNodeNotFound = errors.New("node not found")

ErrNodeNotFound means that a node wasn't found in the snapshot.

Functions

func InitializeClusterSnapshotOrDie

func InitializeClusterSnapshotOrDie(
	t *testing.T,
	snapshot ClusterSnapshot,
	nodes []*apiv1.Node,
	pods []*apiv1.Pod)

InitializeClusterSnapshotOrDie clears cluster snapshot and then initializes it with given set of nodes and pods. Both Spec.NodeName and Status.NominatedNodeName are used when simulating scheduling pods.

func WithForkedSnapshot

func WithForkedSnapshot(snapshot ClusterSnapshot, f func() (bool, error)) (error, error)

WithForkedSnapshot is a helper function for snapshot that makes sure all Fork() calls are closed with Commit() or Revert() calls. The function return (error, error) pair. The first error comes from the passed function, the second error indicate the success of the function itself.

Types

type BasicClusterSnapshot

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

BasicClusterSnapshot is simple, reference implementation of ClusterSnapshot. It is inefficient. But hopefully bug-free and good for initial testing.

func NewBasicClusterSnapshot

func NewBasicClusterSnapshot() *BasicClusterSnapshot

NewBasicClusterSnapshot creates instances of BasicClusterSnapshot.

func (*BasicClusterSnapshot) AddNodeInfo

func (snapshot *BasicClusterSnapshot) AddNodeInfo(nodeInfo *framework.NodeInfo) error

AddNodeInfo adds a NodeInfo.

func (*BasicClusterSnapshot) Commit

func (snapshot *BasicClusterSnapshot) Commit() error

Commit commits changes done after forking.

func (*BasicClusterSnapshot) ForceAddPod

func (snapshot *BasicClusterSnapshot) ForceAddPod(pod *apiv1.Pod, nodeName string) error

ForceAddPod adds pod to the snapshot and schedules it to given node.

func (*BasicClusterSnapshot) ForceRemovePod

func (snapshot *BasicClusterSnapshot) ForceRemovePod(namespace, podName, nodeName string) error

ForceRemovePod removes pod from the snapshot.

func (*BasicClusterSnapshot) Fork

func (snapshot *BasicClusterSnapshot) Fork()

Fork creates a fork of snapshot state. All modifications can later be reverted to moment of forking via Revert()

func (*BasicClusterSnapshot) GetNodeInfo

func (snapshot *BasicClusterSnapshot) GetNodeInfo(nodeName string) (*framework.NodeInfo, error)

GetNodeInfo gets a NodeInfo.

func (*BasicClusterSnapshot) IsPVCUsedByPods

func (snapshot *BasicClusterSnapshot) IsPVCUsedByPods(key string) bool

IsPVCUsedByPods returns if the pvc is used by any pod

func (*BasicClusterSnapshot) ListNodeInfos

func (snapshot *BasicClusterSnapshot) ListNodeInfos() ([]*framework.NodeInfo, error)

ListNodeInfos lists NodeInfos.

func (*BasicClusterSnapshot) NodeInfos

NodeInfos exposes snapshot as NodeInfoLister.

func (*BasicClusterSnapshot) RemoveNodeInfo

func (snapshot *BasicClusterSnapshot) RemoveNodeInfo(nodeName string) error

RemoveNodeInfo removes nodes (and pods scheduled to it) from the snapshot.

func (*BasicClusterSnapshot) Revert

func (snapshot *BasicClusterSnapshot) Revert()

Revert reverts snapshot state to moment of forking.

func (*BasicClusterSnapshot) SetClusterState

func (snapshot *BasicClusterSnapshot) SetClusterState(nodes []*apiv1.Node, scheduledPods []*apiv1.Pod) error

SetClusterState sets the cluster state.

func (*BasicClusterSnapshot) StorageInfos

StorageInfos exposes snapshot as StorageInfoLister.

type ClusterSnapshot

type ClusterSnapshot interface {
	schedulerframework.SharedLister

	// SetClusterState resets the snapshot to an unforked state and replaces the contents of the snapshot
	// with the provided data. scheduledPods are correlated to their Nodes based on spec.NodeName.
	SetClusterState(nodes []*apiv1.Node, scheduledPods []*apiv1.Pod) error

	// ForceAddPod adds the given Pod to the Node with the given nodeName inside the snapshot.
	ForceAddPod(pod *apiv1.Pod, nodeName string) error
	// ForceRemovePod removes the given Pod (and all DRA objects it owns) from the snapshot.
	ForceRemovePod(namespace string, podName string, nodeName string) error

	// AddNodeInfo adds the given NodeInfo to the snapshot. The Node and the Pods are added, as well as
	// any DRA objects passed along them.
	AddNodeInfo(nodeInfo *framework.NodeInfo) error
	// RemoveNodeInfo removes the given NodeInfo from the snapshot The Node and the Pods are removed, as well as
	// any DRA objects owned by them.
	RemoveNodeInfo(nodeName string) error
	// GetNodeInfo returns an internal NodeInfo for a given Node - all information about the Node tracked in the snapshot.
	// This means the Node itself, its scheduled Pods, as well as all relevant DRA objects. The internal NodeInfos
	// obtained via this method should always be used in CA code instead of directly using *schedulerframework.NodeInfo.
	GetNodeInfo(nodeName string) (*framework.NodeInfo, error)
	// ListNodeInfos returns internal NodeInfos for all Nodes tracked in the snapshot. See the comment on GetNodeInfo.
	ListNodeInfos() ([]*framework.NodeInfo, error)

	// Fork creates a fork of snapshot state. All modifications can later be reverted to moment of forking via Revert().
	// Use WithForkedSnapshot() helper function instead if possible.
	Fork()
	// Revert reverts snapshot state to moment of forking.
	Revert()
	// Commit commits changes done after forking.
	Commit() error
}

ClusterSnapshot is abstraction of cluster state used for predicate simulations. It exposes mutation methods and can be viewed as scheduler's SharedLister.

type DeltaClusterSnapshot

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

DeltaClusterSnapshot is an implementation of ClusterSnapshot optimized for typical Cluster Autoscaler usage - (fork, add stuff, revert), repeated many times per loop.

Complexity of some notable operations:

fork - O(1)
revert - O(1)
commit - O(n)
list all pods (no filtering) - O(n), cached
list all pods (with filtering) - O(n)
list node infos - O(n), cached

Watch out for:

node deletions, pod additions & deletions - invalidates cache of current snapshot
	(when forked affects delta, but not base.)
pod affinity - causes scheduler framework to list pods with non-empty selector,
	so basic caching doesn't help.

func NewDeltaClusterSnapshot

func NewDeltaClusterSnapshot() *DeltaClusterSnapshot

NewDeltaClusterSnapshot creates instances of DeltaClusterSnapshot.

func (*DeltaClusterSnapshot) AddNodeInfo

func (snapshot *DeltaClusterSnapshot) AddNodeInfo(nodeInfo *framework.NodeInfo) error

AddNodeInfo adds a NodeInfo.

func (*DeltaClusterSnapshot) Commit

func (snapshot *DeltaClusterSnapshot) Commit() error

Commit commits changes done after forking. Time: O(n), where n = size of delta (number of nodes added, modified or deleted since forking)

func (*DeltaClusterSnapshot) ForceAddPod

func (snapshot *DeltaClusterSnapshot) ForceAddPod(pod *apiv1.Pod, nodeName string) error

ForceAddPod adds pod to the snapshot and schedules it to given node.

func (*DeltaClusterSnapshot) ForceRemovePod

func (snapshot *DeltaClusterSnapshot) ForceRemovePod(namespace, podName, nodeName string) error

ForceRemovePod removes pod from the snapshot.

func (*DeltaClusterSnapshot) Fork

func (snapshot *DeltaClusterSnapshot) Fork()

Fork creates a fork of snapshot state. All modifications can later be reverted to moment of forking via Revert() Time: O(1)

func (*DeltaClusterSnapshot) GetNodeInfo

func (snapshot *DeltaClusterSnapshot) GetNodeInfo(nodeName string) (*framework.NodeInfo, error)

GetNodeInfo gets a NodeInfo.

func (*DeltaClusterSnapshot) IsPVCUsedByPods

func (snapshot *DeltaClusterSnapshot) IsPVCUsedByPods(key string) bool

IsPVCUsedByPods returns if the pvc is used by any pod

func (*DeltaClusterSnapshot) ListNodeInfos

func (snapshot *DeltaClusterSnapshot) ListNodeInfos() ([]*framework.NodeInfo, error)

ListNodeInfos lists NodeInfos.

func (*DeltaClusterSnapshot) NodeInfos

NodeInfos returns node lister.

func (*DeltaClusterSnapshot) RemoveNodeInfo

func (snapshot *DeltaClusterSnapshot) RemoveNodeInfo(nodeName string) error

RemoveNodeInfo removes nodes (and pods scheduled to it) from the snapshot.

func (*DeltaClusterSnapshot) Revert

func (snapshot *DeltaClusterSnapshot) Revert()

Revert reverts snapshot state to moment of forking. Time: O(1)

func (*DeltaClusterSnapshot) SetClusterState

func (snapshot *DeltaClusterSnapshot) SetClusterState(nodes []*apiv1.Node, scheduledPods []*apiv1.Pod) error

SetClusterState sets the cluster state.

func (*DeltaClusterSnapshot) StorageInfos

StorageInfos returns storage lister

Jump to

Keyboard shortcuts

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