kubernetesk8s.io/kubernetes/pkg/scheduler/framework/preemption Index | Files

package preemption

import "k8s.io/kubernetes/pkg/scheduler/framework/preemption"

Index

Types

type Candidate

type Candidate interface {
	// Victims wraps a list of to-be-preempted Pods and the number of PDB violation.
	Victims() *extenderv1.Victims
	// Name returns the target node name where the preemptor gets nominated to run.
	Name() string
}

Candidate represents a nominated node on which the preemptor can be scheduled, along with the list of victims that should be evicted for the preemptor to fit the node.

type Evaluator

type Evaluator struct {
	PluginName string
	Handler    framework.Handle
	PodLister  corelisters.PodLister
	PdbLister  policylisters.PodDisruptionBudgetLister

	// PreemptPod is a function that actually makes API calls to preempt a specific Pod.
	// This is exposed to be replaced during tests.
	PreemptPod func(ctx context.Context, c Candidate, preemptor, victim *v1.Pod, pluginName string) error

	Interface
	// contains filtered or unexported fields
}

func NewEvaluator

func NewEvaluator(pluginName string, fh framework.Handle, i Interface, enableAsyncPreemption bool) *Evaluator

func (*Evaluator) DryRunPreemption

func (ev *Evaluator) DryRunPreemption(ctx context.Context, state *framework.CycleState, pod *v1.Pod, potentialNodes []*framework.NodeInfo,
	pdbs []*policy.PodDisruptionBudget, offset int32, candidatesNum int32) ([]Candidate, *framework.NodeToStatus, error)

DryRunPreemption simulates Preemption logic on <potentialNodes> in parallel, returns preemption candidates and a map indicating filtered nodes statuses. The number of candidates depends on the constraints defined in the plugin's args. In the returned list of candidates, ones that do not violate PDB are preferred over ones that do. NOTE: This method is exported for easier testing in default preemption.

func (*Evaluator) IsPodRunningPreemption

func (ev *Evaluator) IsPodRunningPreemption(podUID types.UID) bool

IsPodRunningPreemption returns true if the pod is currently triggering preemption asynchronously.

func (*Evaluator) Preempt

Preempt returns a PostFilterResult carrying suggested nominatedNodeName, along with a Status. The semantics of returned <PostFilterResult, Status> varies on different scenarios:

func (*Evaluator) SelectCandidate

func (ev *Evaluator) SelectCandidate(ctx context.Context, candidates []Candidate) Candidate

SelectCandidate chooses the best-fit candidate from given <candidates> and return it. NOTE: This method is exported for easier testing in default preemption.

type Interface

type Interface interface {
	// GetOffsetAndNumCandidates chooses a random offset and calculates the number of candidates that should be
	// shortlisted for dry running preemption.
	GetOffsetAndNumCandidates(nodes int32) (int32, int32)
	// CandidatesToVictimsMap builds a map from the target node to a list of to-be-preempted Pods and the number of PDB violation.
	CandidatesToVictimsMap(candidates []Candidate) map[string]*extenderv1.Victims
	// PodEligibleToPreemptOthers returns one bool and one string. The bool indicates whether this pod should be considered for
	// preempting other pods or not. The string includes the reason if this pod isn't eligible.
	PodEligibleToPreemptOthers(ctx context.Context, pod *v1.Pod, nominatedNodeStatus *framework.Status) (bool, string)
	// SelectVictimsOnNode finds minimum set of pods on the given node that should be preempted in order to make enough room
	// for "pod" to be scheduled.
	// Note that both `state` and `nodeInfo` are deep copied.
	SelectVictimsOnNode(ctx context.Context, state *framework.CycleState,
		pod *v1.Pod, nodeInfo *framework.NodeInfo, pdbs []*policy.PodDisruptionBudget) ([]*v1.Pod, int, *framework.Status)
	// OrderedScoreFuncs returns a list of ordered score functions to select preferable node where victims will be preempted.
	// The ordered score functions will be processed one by one iff we find more than one node with the highest score.
	// Default score functions will be processed if nil returned here for backwards-compatibility.
	OrderedScoreFuncs(ctx context.Context, nodesToVictims map[string]*extenderv1.Victims) []func(node string) int64
}

Interface is expected to be implemented by different preemption plugins as all those member methods might have different behavior compared with the default preemption.

Source Files

preemption.go

Version
v1.33.0 (latest)
Published
Apr 23, 2025
Platform
linux/amd64
Imports
24 packages
Last checked
3 hours ago

Tools for package owners.