kubernetesk8s.io/kubernetes/pkg/scheduler Index | Files | Directories

package scheduler

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

Index

Constants

const (
	// DefaultExtenderTimeout defines the default extender timeout in second.
	DefaultExtenderTimeout = 5 * time.Second
)

Variables

var ErrNoNodesAvailable = fmt.Errorf("no nodes available to schedule pods")

ErrNoNodesAvailable is used to describe the error that no nodes available to schedule pods.

Functions

func NewHTTPExtender

func NewHTTPExtender(config *schedulerapi.Extender) (framework.Extender, error)

NewHTTPExtender creates an HTTPExtender object.

func NewInformerFactory

func NewInformerFactory(cs clientset.Interface, resyncPeriod time.Duration) informers.SharedInformerFactory

NewInformerFactory creates a SharedInformerFactory and initializes a scheduler specific in-place podInformer.

Types

type AdmissionResult

type AdmissionResult struct {
	Name                 string
	Reason               string
	InsufficientResource *noderesources.InsufficientResource
}

AdmissionResult describes the reason why Scheduler can't admit the pod. If the reason is a resource fit one, then AdmissionResult.InsufficientResource includes the details.

func AdmissionCheck

func AdmissionCheck(pod *v1.Pod, nodeInfo *framework.NodeInfo, includeAllFailures bool) []AdmissionResult

AdmissionCheck calls the filtering logic of noderesources/nodeport/nodeAffinity/nodename and returns the failure reasons. It's used in kubelet(pkg/kubelet/lifecycle/predicate.go) and scheduler. It returns the first failure if `includeAllFailures` is set to false; otherwise returns all failures.

type FailureHandlerFn

type FailureHandlerFn func(ctx context.Context, fwk framework.Framework, podInfo *framework.QueuedPodInfo, status *framework.Status, nominatingInfo *framework.NominatingInfo, start time.Time)

type FrameworkCapturer

type FrameworkCapturer func(schedulerapi.KubeSchedulerProfile)

FrameworkCapturer is used for registering a notify function in building framework.

type HTTPExtender

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

HTTPExtender implements the Extender interface.

func (*HTTPExtender) Bind

func (h *HTTPExtender) Bind(binding *v1.Binding) error

Bind delegates the action of binding a pod to a node to the extender.

func (*HTTPExtender) Filter

func (h *HTTPExtender) Filter(
	pod *v1.Pod,
	nodes []*framework.NodeInfo,
) (filteredList []*framework.NodeInfo, failedNodes, failedAndUnresolvableNodes extenderv1.FailedNodesMap, err error)

Filter based on extender implemented predicate functions. The filtered list is expected to be a subset of the supplied list; otherwise the function returns an error. The failedNodes and failedAndUnresolvableNodes optionally contains the list of failed nodes and failure reasons, except nodes in the latter are unresolvable.

func (*HTTPExtender) IsBinder

func (h *HTTPExtender) IsBinder() bool

IsBinder returns whether this extender is configured for the Bind method.

func (*HTTPExtender) IsFilter

func (h *HTTPExtender) IsFilter() bool

IsFilter returns whether this extender is configured for the Filter method.

func (*HTTPExtender) IsIgnorable

func (h *HTTPExtender) IsIgnorable() bool

IsIgnorable returns true indicates scheduling should not fail when this extender is unavailable

func (*HTTPExtender) IsInterested

func (h *HTTPExtender) IsInterested(pod *v1.Pod) bool

IsInterested returns true if at least one extended resource requested by this pod is managed by this extender.

func (*HTTPExtender) IsPrioritizer

func (h *HTTPExtender) IsPrioritizer() bool

IsPrioritizer returns whether this extender is configured for the Prioritize method.

func (*HTTPExtender) Name

func (h *HTTPExtender) Name() string

Name returns extenderURL to identify the extender.

func (*HTTPExtender) Prioritize

func (h *HTTPExtender) Prioritize(pod *v1.Pod, nodes []*framework.NodeInfo) (*extenderv1.HostPriorityList, int64, error)

Prioritize based on extender implemented priority functions. Weight*priority is added up for each such priority function. The returned score is added to the score computed by Kubernetes scheduler. The total score is used to do the host selection.

func (*HTTPExtender) ProcessPreemption

func (h *HTTPExtender) ProcessPreemption(
	pod *v1.Pod,
	nodeNameToVictims map[string]*extenderv1.Victims,
	nodeInfos framework.NodeInfoLister,
) (map[string]*extenderv1.Victims, error)

ProcessPreemption returns filtered candidate nodes and victims after running preemption logic in extender.

func (*HTTPExtender) SupportsPreemption

func (h *HTTPExtender) SupportsPreemption() bool

SupportsPreemption returns true if an extender supports preemption. An extender should have preempt verb defined and enabled its own node cache.

type Option

type Option func(*schedulerOptions)

Option configures a Scheduler

func WithBuildFrameworkCapturer

func WithBuildFrameworkCapturer(fc FrameworkCapturer) Option

WithBuildFrameworkCapturer sets a notify function for getting buildFramework details.

func WithClock

func WithClock(clock clock.WithTicker) Option

WithClock sets clock for PriorityQueue, the default clock is clock.RealClock.

func WithComponentConfigVersion

func WithComponentConfigVersion(apiVersion string) Option

WithComponentConfigVersion sets the component config version to the KubeSchedulerConfiguration version used. The string should be the full scheme group/version of the external type we converted from (for example "kubescheduler.config.k8s.io/v1")

func WithExtenders

func WithExtenders(e ...schedulerapi.Extender) Option

WithExtenders sets extenders for the Scheduler

func WithFrameworkOutOfTreeRegistry

func WithFrameworkOutOfTreeRegistry(registry frameworkruntime.Registry) Option

WithFrameworkOutOfTreeRegistry sets the registry for out-of-tree plugins. Those plugins will be appended to the default registry.

func WithKubeConfig

func WithKubeConfig(cfg *restclient.Config) Option

WithKubeConfig sets the kube config for Scheduler.

func WithParallelism

func WithParallelism(threads int32) Option

WithParallelism sets the parallelism for all scheduler algorithms. Default is 16.

func WithPercentageOfNodesToScore

func WithPercentageOfNodesToScore(percentageOfNodesToScore *int32) Option

WithPercentageOfNodesToScore sets percentageOfNodesToScore for Scheduler. The default value of 0 will use an adaptive percentage: 50 - (num of nodes)/125.

func WithPodInitialBackoffSeconds

func WithPodInitialBackoffSeconds(podInitialBackoffSeconds int64) Option

WithPodInitialBackoffSeconds sets podInitialBackoffSeconds for Scheduler, the default value is 1

func WithPodMaxBackoffSeconds

func WithPodMaxBackoffSeconds(podMaxBackoffSeconds int64) Option

WithPodMaxBackoffSeconds sets podMaxBackoffSeconds for Scheduler, the default value is 10

func WithPodMaxInUnschedulablePodsDuration

func WithPodMaxInUnschedulablePodsDuration(duration time.Duration) Option

WithPodMaxInUnschedulablePodsDuration sets podMaxInUnschedulablePodsDuration for PriorityQueue.

func WithProfiles

func WithProfiles(p ...schedulerapi.KubeSchedulerProfile) Option

WithProfiles sets profiles for Scheduler. By default, there is one profile with the name "default-scheduler".

type ScheduleResult

type ScheduleResult struct {
	// Name of the selected node.
	SuggestedHost string
	// The number of nodes the scheduler evaluated the pod against in the filtering
	// phase and beyond.
	EvaluatedNodes int
	// The number of nodes out of the evaluated ones that fit the pod.
	FeasibleNodes int
	// contains filtered or unexported fields
}

ScheduleResult represents the result of scheduling a pod.

type Scheduler

type Scheduler struct {
	// It is expected that changes made via Cache will be observed
	// by NodeLister and Algorithm.
	Cache internalcache.Cache

	Extenders []framework.Extender

	// NextPod should be a function that blocks until the next pod
	// is available. We don't use a channel for this, because scheduling
	// a pod may take some amount of time and we don't want pods to get
	// stale while they sit in a channel.
	NextPod func(logger klog.Logger) (*framework.QueuedPodInfo, error)

	// FailureHandler is called upon a scheduling failure.
	FailureHandler FailureHandlerFn

	// SchedulePod tries to schedule the given pod to one of the nodes in the node list.
	// Return a struct of ScheduleResult with the name of suggested host on success,
	// otherwise will return a FitError with reasons.
	SchedulePod func(ctx context.Context, fwk framework.Framework, state *framework.CycleState, pod *v1.Pod) (ScheduleResult, error)

	// Close this to shut down the scheduler.
	StopEverything <-chan struct{}

	// SchedulingQueue holds pods to be scheduled
	SchedulingQueue internalqueue.SchedulingQueue

	// Profiles are the scheduling profiles.
	Profiles profile.Map
	// contains filtered or unexported fields
}

Scheduler watches for new unscheduled pods. It attempts to find nodes that they fit on and writes bindings back to the api server.

func New

func New(ctx context.Context,
	client clientset.Interface,
	informerFactory informers.SharedInformerFactory,
	dynInformerFactory dynamicinformer.DynamicSharedInformerFactory,
	recorderFactory profile.RecorderFactory,
	opts ...Option) (*Scheduler, error)

New returns a Scheduler

func (*Scheduler) Run

func (sched *Scheduler) Run(ctx context.Context)

Run begins watching and scheduling. It starts scheduling and blocked until the context is done.

func (*Scheduler) ScheduleOne

func (sched *Scheduler) ScheduleOne(ctx context.Context)

ScheduleOne does the entire scheduling workflow for a single pod. It is serialized on the scheduling algorithm's host fitting.

func (*Scheduler) WaitForHandlersSync

func (sched *Scheduler) WaitForHandlersSync(ctx context.Context) error

WaitForHandlersSync waits for EventHandlers to sync. It returns true if it was successful, false if the controller should shut down

Source Files

eventhandlers.go extender.go schedule_one.go scheduler.go

Directories

PathSynopsis
pkg/scheduler/apis
pkg/scheduler/apis/config
pkg/scheduler/apis/config/latest
pkg/scheduler/apis/config/scheme
pkg/scheduler/apis/config/testing
pkg/scheduler/apis/config/testing/defaults
pkg/scheduler/apis/config/v1
pkg/scheduler/apis/config/validation
pkg/scheduler/backend
pkg/scheduler/backend/cache
pkg/scheduler/backend/cache/debugger
pkg/scheduler/backend/cache/fake
pkg/scheduler/backend/heap
pkg/scheduler/backend/queue
pkg/scheduler/framework
pkg/scheduler/framework/autoscaler_contract
pkg/scheduler/framework/parallelize
pkg/scheduler/framework/plugins
pkg/scheduler/framework/plugins/defaultbinder
pkg/scheduler/framework/plugins/defaultpreemption
pkg/scheduler/framework/plugins/dynamicresources
pkg/scheduler/framework/plugins/examples
pkg/scheduler/framework/plugins/examples/multipoint
pkg/scheduler/framework/plugins/examples/prebind
pkg/scheduler/framework/plugins/examples/stateful
pkg/scheduler/framework/plugins/feature
pkg/scheduler/framework/plugins/helper
pkg/scheduler/framework/plugins/imagelocality
pkg/scheduler/framework/plugins/interpodaffinity
pkg/scheduler/framework/plugins/names
pkg/scheduler/framework/plugins/nodeaffinity
pkg/scheduler/framework/plugins/nodename
pkg/scheduler/framework/plugins/nodeports
pkg/scheduler/framework/plugins/noderesources
pkg/scheduler/framework/plugins/nodeunschedulable
pkg/scheduler/framework/plugins/nodevolumelimits
pkg/scheduler/framework/plugins/podtopologyspread
pkg/scheduler/framework/plugins/queuesort
pkg/scheduler/framework/plugins/schedulinggates
pkg/scheduler/framework/plugins/tainttoleration
pkg/scheduler/framework/plugins/testing
pkg/scheduler/framework/plugins/volumebinding
pkg/scheduler/framework/plugins/volumebinding/metrics
pkg/scheduler/framework/plugins/volumerestrictions
pkg/scheduler/framework/plugins/volumezone
pkg/scheduler/framework/preemption
pkg/scheduler/framework/runtime
pkg/scheduler/metrics
pkg/scheduler/metrics/resourcesPackage resources provides a metrics collector that reports the resource consumption (requests and limits) of the pods in the cluster as the scheduler and kubelet would interpret it.
pkg/scheduler/profilePackage profile holds the definition of a scheduling Profile.
pkg/scheduler/testing
pkg/scheduler/testing/framework
pkg/scheduler/util
pkg/scheduler/util/assumecache
pkg/scheduler/util/queue
Version
v1.33.0 (latest)
Published
Apr 23, 2025
Platform
linux/amd64
Imports
58 packages
Last checked
3 hours ago

Tools for package owners.