clustersnapshot

package
v0.0.0-...-3fd892a Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 7 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) AddNode

func (snapshot *BasicClusterSnapshot) AddNode(node *apiv1.Node) error

AddNode adds node to the snapshot.

func (*BasicClusterSnapshot) AddNodeWithPods

func (snapshot *BasicClusterSnapshot) AddNodeWithPods(node *apiv1.Node, pods []*apiv1.Pod) error

AddNodeWithPods adds a node and set of pods to be scheduled to this node to the snapshot.

func (*BasicClusterSnapshot) AddNodes

func (snapshot *BasicClusterSnapshot) AddNodes(nodes []*apiv1.Node) error

AddNodes adds nodes in batch to the snapshot.

func (*BasicClusterSnapshot) AddPod

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

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

func (*BasicClusterSnapshot) Clear

func (snapshot *BasicClusterSnapshot) Clear()

Clear reset cluster snapshot to empty, unforked state

func (*BasicClusterSnapshot) Commit

func (snapshot *BasicClusterSnapshot) Commit() error

Commit commits changes done after forking.

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) IsPVCUsedByPods

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

IsPVCUsedByPods returns if the pvc is used by any pod

func (*BasicClusterSnapshot) NodeInfos

NodeInfos exposes snapshot as NodeInfoLister.

func (*BasicClusterSnapshot) RemoveNode

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

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

func (*BasicClusterSnapshot) RemovePod

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

RemovePod removes pod from the snapshot.

func (*BasicClusterSnapshot) Revert

func (snapshot *BasicClusterSnapshot) Revert()

Revert reverts snapshot state to moment of forking.

func (*BasicClusterSnapshot) StorageInfos

StorageInfos exposes snapshot as StorageInfoLister.

type ClusterSnapshot

type ClusterSnapshot interface {
	schedulerframework.SharedLister
	// AddNode adds node to the snapshot.
	AddNode(node *apiv1.Node) error
	// AddNodes adds nodes to the snapshot.
	AddNodes(nodes []*apiv1.Node) error
	// RemoveNode removes nodes (and pods scheduled to it) from the snapshot.
	RemoveNode(nodeName string) error
	// AddPod adds pod to the snapshot and schedules it to given node.
	AddPod(pod *apiv1.Pod, nodeName string) error
	// RemovePod removes pod from the snapshot.
	RemovePod(namespace string, podName string, nodeName string) error
	// AddNodeWithPods adds a node and set of pods to be scheduled to this node to the snapshot.
	AddNodeWithPods(node *apiv1.Node, pods []*apiv1.Pod) error
	// IsPVCUsedByPods returns if the pvc is used by any pod, key = <namespace>/<pvc_name>
	IsPVCUsedByPods(key string) bool

	// 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
	// Clear reset cluster snapshot to empty, unforked state.
	Clear()
}

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) AddNode

func (snapshot *DeltaClusterSnapshot) AddNode(node *apiv1.Node) error

AddNode adds node to the snapshot.

func (*DeltaClusterSnapshot) AddNodeWithPods

func (snapshot *DeltaClusterSnapshot) AddNodeWithPods(node *apiv1.Node, pods []*apiv1.Pod) error

AddNodeWithPods adds a node and set of pods to be scheduled to this node to the snapshot.

func (*DeltaClusterSnapshot) AddNodes

func (snapshot *DeltaClusterSnapshot) AddNodes(nodes []*apiv1.Node) error

AddNodes adds nodes in batch to the snapshot.

func (*DeltaClusterSnapshot) AddPod

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

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

func (*DeltaClusterSnapshot) Clear

func (snapshot *DeltaClusterSnapshot) Clear()

Clear reset cluster snapshot to empty, unforked state Time: O(1)

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) 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) IsPVCUsedByPods

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

IsPVCUsedByPods returns if the pvc is used by any pod

func (*DeltaClusterSnapshot) NodeInfos

NodeInfos returns node lister.

func (*DeltaClusterSnapshot) RemoveNode

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

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

func (*DeltaClusterSnapshot) RemovePod

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

RemovePod removes pod from the snapshot.

func (*DeltaClusterSnapshot) Revert

func (snapshot *DeltaClusterSnapshot) Revert()

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

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