scheduler

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AffinityOperator

type AffinityOperator string

AffinityOperator represents an operator for affinity rules

const (
	// AffinityOperatorIn represents the "in" operator
	AffinityOperatorIn AffinityOperator = "In"
	// AffinityOperatorNotIn represents the "not in" operator
	AffinityOperatorNotIn AffinityOperator = "NotIn"
	// AffinityOperatorExists represents the "exists" operator
	AffinityOperatorExists AffinityOperator = "Exists"
	// AffinityOperatorDoesNotExist represents the "does not exist" operator
	AffinityOperatorDoesNotExist AffinityOperator = "DoesNotExist"
)

type AffinityRule

type AffinityRule struct {
	Key      string
	Operator AffinityOperator
	Values   []string
}

AffinityRule represents a rule for node affinity

type BinPackingStrategy

type BinPackingStrategy string

BinPackingStrategy represents different strategies for bin packing

const (
	// BinPackingBestFit packs tasks onto as few nodes as possible
	BinPackingBestFit BinPackingStrategy = "BestFit"
	// BinPackingWorstFit spreads tasks across nodes evenly
	BinPackingWorstFit BinPackingStrategy = "WorstFit"
	// BinPackingFirstFit uses the first node that fits
	BinPackingFirstFit BinPackingStrategy = "FirstFit"
	// BinPackingRandom randomly selects a node that fits
	BinPackingRandom BinPackingStrategy = "Random"
)

type Constraint

type Constraint interface {
	Satisfied(node *Node) bool
}

Constraint represents a scheduling constraint

type EnhancedConstraint

type EnhancedConstraint interface {
	Satisfied(node *EnhancedNode) bool
}

EnhancedConstraint represents a scheduling constraint

type EnhancedNode

type EnhancedNode struct {
	ID        string
	Name      string
	Address   string
	Available EnhancedResourceRequirements
	Used      EnhancedResourceRequirements
	Labels    map[string]string
	Taints    []Taint
	Zone      string
	Region    string
}

EnhancedNode represents a node in the cluster

type EnhancedResourceLimit

type EnhancedResourceLimit struct {
	CPU    float64
	Memory int64
	Disk   int64
}

EnhancedResourceLimit specifies the resource limits for a task

type EnhancedResourceRequest

type EnhancedResourceRequest struct {
	CPU    float64
	Memory int64
	Disk   int64
}

EnhancedResourceRequest specifies the resources requested by a task

type EnhancedResourceRequirements

type EnhancedResourceRequirements struct {
	Requests EnhancedResourceRequest
	Limits   EnhancedResourceLimit
}

EnhancedResourceRequirements specifies the resources required by a task

type EnhancedScheduler

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

EnhancedScheduler is responsible for scheduling tasks to nodes

func NewEnhancedScheduler

func NewEnhancedScheduler(logger *logrus.Logger) (*EnhancedScheduler, error)

NewEnhancedScheduler creates a new enhanced scheduler

func (*EnhancedScheduler) Close

func (s *EnhancedScheduler) Close() error

Close closes the scheduler and releases resources

func (*EnhancedScheduler) RegisterNode

func (s *EnhancedScheduler) RegisterNode(node *EnhancedNode)

RegisterNode registers a node with the scheduler

func (*EnhancedScheduler) Schedule

func (s *EnhancedScheduler) Schedule(ctx context.Context, task *Task) (string, error)

Schedule schedules a specific task to a node

func (*EnhancedScheduler) ScheduleAll

func (s *EnhancedScheduler) ScheduleAll(ctx context.Context) error

ScheduleAll attempts to schedule all pending tasks to available nodes

func (*EnhancedScheduler) ScheduleTask

func (s *EnhancedScheduler) ScheduleTask(ctx context.Context, task *Task) (string, error)

ScheduleTask schedules a specific task to an available node

func (*EnhancedScheduler) SubmitTask

func (s *EnhancedScheduler) SubmitTask(task *EnhancedTask)

SubmitTask submits a task to be scheduled

func (*EnhancedScheduler) UnregisterNode

func (s *EnhancedScheduler) UnregisterNode(nodeID string)

UnregisterNode removes a node from the scheduler

func (*EnhancedScheduler) WithBinPackingStrategy

func (s *EnhancedScheduler) WithBinPackingStrategy(strategy BinPackingStrategy) *EnhancedScheduler

WithBinPackingStrategy sets the bin packing strategy

func (*EnhancedScheduler) WithNodeManager

func (s *EnhancedScheduler) WithNodeManager(nodeManager interface{}) *EnhancedScheduler

WithNodeManager sets the node manager

func (*EnhancedScheduler) WithOvercommitRatios

func (s *EnhancedScheduler) WithOvercommitRatios(cpuRatio, memoryRatio float64) *EnhancedScheduler

WithOvercommitRatios sets the resource overcommit ratios

func (*EnhancedScheduler) WithRebalanceThreshold

func (s *EnhancedScheduler) WithRebalanceThreshold(threshold float64) *EnhancedScheduler

WithRebalanceThreshold sets the load difference threshold for rebalancing

func (*EnhancedScheduler) WithSchedulingInterval

func (s *EnhancedScheduler) WithSchedulingInterval(interval int64) *EnhancedScheduler

WithSchedulingInterval sets the scheduling interval in seconds

type EnhancedTask

type EnhancedTask struct {
	ID          string
	Name        string
	Image       string
	Command     []string
	Resources   EnhancedResourceRequirements
	State       EnhancedTaskState
	AssignedTo  string
	Constraints []EnhancedConstraint
	Priority    int32
	TenantID    string
	Tolerations []Toleration
}

EnhancedTask represents a unit of work to be scheduled

type EnhancedTaskState

type EnhancedTaskState string

EnhancedTaskState represents the state of a scheduled task

const (
	// EnhancedTaskPending indicates the task is waiting to be scheduled
	EnhancedTaskPending EnhancedTaskState = "pending"
	// EnhancedTaskScheduled indicates the task has been scheduled to a node
	EnhancedTaskScheduled EnhancedTaskState = "scheduled"
	// EnhancedTaskRunning indicates the task is running on a node
	EnhancedTaskRunning EnhancedTaskState = "running"
	// EnhancedTaskCompleted indicates the task has completed successfully
	EnhancedTaskCompleted EnhancedTaskState = "completed"
	// EnhancedTaskFailed indicates the task has failed
	EnhancedTaskFailed EnhancedTaskState = "failed"
)

type LabelConstraint

type LabelConstraint struct {
	Key   string
	Value string
}

LabelConstraint is a constraint that requires a specific label value

func (*LabelConstraint) Satisfied

func (c *LabelConstraint) Satisfied(node *EnhancedNode) bool

Satisfied checks if the node satisfies the label constraint

type Node

type Node struct {
	ID        string
	Name      string
	Address   string
	Available ResourceRequirements
	Used      ResourceRequirements
	Labels    map[string]string
}

Node represents a node in the cluster

type NodeLoad

type NodeLoad struct {
	NodeID         string
	LoadScore      float64
	ContainerCount int
	ReservedCPU    float64
	ReservedMemory int64
	Taints         []Taint
}

NodeLoad represents the current load on a node

type RegionConstraint

type RegionConstraint struct {
	Region string
}

RegionConstraint is a constraint that requires a specific region

func (*RegionConstraint) Satisfied

func (c *RegionConstraint) Satisfied(node *EnhancedNode) bool

Satisfied checks if the node satisfies the region constraint

type ResourceRequirements

type ResourceRequirements struct {
	CPU    float64
	Memory int64
	Disk   int64
}

ResourceRequirements specifies the resources required by a task

type Scheduler

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

Scheduler is responsible for scheduling tasks to nodes

func NewScheduler

func NewScheduler(logger *logrus.Logger) *Scheduler

NewScheduler creates a new scheduler

func (*Scheduler) GetNode

func (s *Scheduler) GetNode(nodeID string) (*Node, bool)

GetNode returns a node by ID

func (*Scheduler) GetTask

func (s *Scheduler) GetTask(taskID string) (*Task, bool)

GetTask returns a task by ID

func (*Scheduler) RegisterNode

func (s *Scheduler) RegisterNode(node *Node)

RegisterNode registers a node with the scheduler

func (*Scheduler) Schedule

func (s *Scheduler) Schedule(ctx context.Context) error

Schedule attempts to schedule pending tasks to available nodes

func (*Scheduler) SubmitTask

func (s *Scheduler) SubmitTask(task *Task)

SubmitTask submits a task to be scheduled

func (*Scheduler) UnregisterNode

func (s *Scheduler) UnregisterNode(nodeID string)

UnregisterNode removes a node from the scheduler

type Taint

type Taint struct {
	Key    string
	Value  string
	Effect TaintEffect
}

Taint represents a taint on a node

type TaintEffect

type TaintEffect string

TaintEffect represents the effect of a taint

const (
	// TaintEffectNoSchedule prevents scheduling of new tasks
	TaintEffectNoSchedule TaintEffect = "NoSchedule"
	// TaintEffectPreferNoSchedule tries to avoid scheduling but not guaranteed
	TaintEffectPreferNoSchedule TaintEffect = "PreferNoSchedule"
	// TaintEffectNoExecute evicts tasks that don't tolerate the taint
	TaintEffectNoExecute TaintEffect = "NoExecute"
)

type Task

type Task struct {
	ID          string
	Name        string
	Image       string
	Command     []string
	Resources   ResourceRequirements
	State       TaskState
	AssignedTo  string
	Constraints []Constraint
	Affinity    []AffinityRule
}

Task represents a unit of work to be scheduled

type TaskState

type TaskState string

TaskState represents the state of a scheduled task

const (
	// TaskPending indicates the task is waiting to be scheduled
	TaskPending TaskState = "pending"
	// TaskScheduled indicates the task has been scheduled to a node
	TaskScheduled TaskState = "scheduled"
	// TaskRunning indicates the task is running on a node
	TaskRunning TaskState = "running"
	// TaskCompleted indicates the task has completed successfully
	TaskCompleted TaskState = "completed"
	// TaskFailed indicates the task has failed
	TaskFailed TaskState = "failed"
)

type Toleration

type Toleration struct {
	Key    string
	Value  string
	Effect TaintEffect
}

Toleration represents a toleration for a taint

type ZoneConstraint

type ZoneConstraint struct {
	Zone string
}

ZoneConstraint is a constraint that requires a specific zone

func (*ZoneConstraint) Satisfied

func (c *ZoneConstraint) Satisfied(node *EnhancedNode) bool

Satisfied checks if the node satisfies the zone constraint

Jump to

Keyboard shortcuts

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