clustersnapshot

package
v0.0.0-...-7df4f84 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 13 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 AssignTestPodsToNodes

func AssignTestPodsToNodes(pods []*apiv1.Pod, nodes []*apiv1.Node)

AssignTestPodsToNodes distributes test pods evenly across test nodes.

func CreateTestNodes

func CreateTestNodes(n int) []*apiv1.Node

CreateTestNodes creates n test Nodes.

func CreateTestNodesWithPrefix

func CreateTestNodesWithPrefix(prefix string, n int) []*apiv1.Node

CreateTestNodesWithPrefix creates n test Nodes with the given name prefix.

func CreateTestPods

func CreateTestPods(n int) []*apiv1.Pod

CreateTestPods creates n test Pods.

func CreateTestPodsWithPrefix

func CreateTestPodsWithPrefix(prefix string, n int) []*apiv1.Pod

CreateTestPodsWithPrefix creates n test Pods with the given name prefix.

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 ClusterSnapshot

type ClusterSnapshot interface {
	ClusterSnapshotStore

	// AddNodeInfo adds the given NodeInfo to the snapshot without checking scheduler predicates. 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)

	// SchedulePod tries to schedule the given Pod on the Node with the given name inside the snapshot,
	// checking scheduling predicates. The pod is only scheduled if the predicates pass. If the pod is scheduled,
	// all relevant DRA objects are modified to reflect that. Returns nil if the pod got scheduled, and a non-nil
	// error explaining why not otherwise. The error Type() can be checked against SchedulingInternalError to distinguish
	// failing predicates from unexpected errors.
	SchedulePod(pod *apiv1.Pod, nodeName string) SchedulingError
	// SchedulePodOnAnyNodeMatching tries to schedule the given Pod on any Node for which nodeMatches returns
	// true. Scheduling predicates are checked, and the pod is scheduled only if there is a matching Node with passing
	// predicates. If the pod is scheduled, all relevant DRA objects are modified to reflect that, and the name of the
	// Node its scheduled on and nil are returned. If the pod can't be scheduled on any Node, an empty string and a non-nil
	// error explaining why are returned. The error Type() can be checked against SchedulingInternalError to distinguish
	// failing predicates from unexpected errors.
	SchedulePodOnAnyNodeMatching(pod *apiv1.Pod, nodeMatches func(*framework.NodeInfo) bool) (matchingNode string, err SchedulingError)
	// UnschedulePod removes the given Pod from the given Node inside the snapshot, and modifies all relevant DRA objects
	// to reflect the removal. The pod can then be scheduled on another Node in the snapshot using the Schedule methods.
	UnschedulePod(namespace string, podName string, nodeName string) error

	// CheckPredicates runs scheduler predicates to check if the given Pod would be able to schedule on the Node with the given
	// name. Returns nil if predicates pass, or a non-nil error specifying why they didn't otherwise. The error Type() can be
	// checked against SchedulingInternalError to distinguish failing predicates from unexpected errors. Doesn't mutate the snapshot.
	CheckPredicates(pod *apiv1.Pod, nodeName string) SchedulingError
}

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

type ClusterSnapshotStore

type ClusterSnapshotStore interface {
	framework.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, draSnapshot drasnapshot.Snapshot) error

	// ForceAddPod adds the given Pod to the Node with the given nodeName inside the snapshot without checking scheduler predicates.
	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

	// AddSchedulerNodeInfo adds the given schedulerframework.NodeInfo to the snapshot without checking scheduler predicates, and
	// without taking DRA objects into account. This shouldn't be used outside the clustersnapshot pkg, use ClusterSnapshot.AddNodeInfo()
	// instead.
	AddSchedulerNodeInfo(nodeInfo *schedulerframework.NodeInfo) error
	// RemoveSchedulerNodeInfo removes the given schedulerframework.NodeInfo from the snapshot without taking DRA objects into account. This shouldn't
	// be used outside the clustersnapshot pkg, use ClusterSnapshot.RemoveNodeInfo() instead.
	RemoveSchedulerNodeInfo(nodeName string) error

	// DraSnapshot returns an interface that allows accessing and modifying the DRA objects in the snapshot.
	DraSnapshot() drasnapshot.Snapshot

	// 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
}

ClusterSnapshotStore is the "low-level" part of ClusterSnapshot, responsible for storing the snapshot state and mutating it directly, without going through scheduler predicates. ClusterSnapshotStore shouldn't be directly used outside the clustersnapshot pkg, its methods should be accessed via ClusterSnapshot.

type SchedulingError

type SchedulingError interface {
	error

	// Type can be used to distinguish between different SchedulingError types.
	Type() SchedulingErrorType
	// Reasons provides a list of human-readable reasons explaining the error.
	Reasons() []string

	// FailingPredicateName returns the name of the predicate that failed. Only applicable to the FailingPredicateError type.
	FailingPredicateName() string
	// FailingPredicateReasons returns a list of human-readable reasons explaining why the predicate failed. Only applicable to the FailingPredicateError type.
	FailingPredicateReasons() []string
}

SchedulingError represents an error encountered while trying to schedule a Pod inside ClusterSnapshot. An interface is exported instead of the concrete type to avoid the dreaded https://go.dev/doc/faq#nil_error.

func NewFailingPredicateError

func NewFailingPredicateError(pod *apiv1.Pod, predicateName string, predicateReasons []string, unexpectedErrMsg string, debugInfo string) SchedulingError

NewFailingPredicateError creates a new schedulingError with FailingPredicateError type.

func NewNoNodesPassingPredicatesFoundError

func NewNoNodesPassingPredicatesFoundError(pod *apiv1.Pod) SchedulingError

NewNoNodesPassingPredicatesFoundError creates a new schedulingError with NoNodesPassingPredicatesFoundError type.

func NewSchedulingInternalError

func NewSchedulingInternalError(pod *apiv1.Pod, errMsg string) SchedulingError

NewSchedulingInternalError creates a new schedulingError with SchedulingInternalError type.

type SchedulingErrorType

type SchedulingErrorType int

SchedulingErrorType represents different possible schedulingError types.

const (
	// SchedulingInternalError denotes internal unexpected error while trying to schedule a pod
	SchedulingInternalError SchedulingErrorType = iota
	// FailingPredicateError means that a pod couldn't be scheduled on a particular node because of a failing scheduler predicate
	FailingPredicateError
	// NoNodesPassingPredicatesFoundError means that a pod couldn't be scheduled on any Node because of failing scheduler predicates
	NoNodesPassingPredicatesFoundError
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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