schedule

package
v1.76.6 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// FunctionalOrder is the Order value assigned to functional (non-critical) packages.
	// It is higher than any critical package order, ensuring functional packages are
	// scheduled only after all critical packages have been processed.
	FunctionalOrder = 999
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyOfGroup added in v1.76.1

type AnyOfGroup struct {
	Name    string                         `json:"name" yaml:"name"`
	Members map[string]*semver.Constraints `json:"members" yaml:"members"`
}

AnyOfGroup is a group of alternative dependencies: at least one member must be installed and satisfy its constraint for the group to pass. A nil constraint on a member means "any installed version is acceptable". Name is the stable identifier used by the scheduler in failure diagnostics.

type Constraints added in v1.76.0

type Constraints struct {
	Order        Order                 // Scheduling priority; lower values run first.
	Kubernetes   *semver.Constraints   // Kubernetes version constraint (e.g., ">=1.21")
	Deckhouse    *semver.Constraints   // Deckhouse version constraint (e.g., ">=1.60")
	Dependencies map[string]Dependency // Inter-package dependencies; keyed by package name. Source of topological ordering and checker inputs.
	AnyOf        []AnyOfGroup          // Groups of alternative dependencies. Checker-only: never contributes edges to the topological graph, so fallback chains across packages do not produce cycles.
	NoneOf       []NoneOfGroup         // Groups of forbidden dependencies. Checker-only: "must not be installed" is an admission predicate, not an ordering relation.
}

Constraints defines the scheduling requirements for a Package: ordering priority, version bounds, and inter-package dependencies.

type CycleError added in v1.76.1

type CycleError struct {
	Members []string
}

CycleError reports a topological cycle in the dependency graph. Members are the participating node names, sorted alphabetically for deterministic output.

func (*CycleError) Error added in v1.76.1

func (e *CycleError) Error() string

Error renders the cycle members in a single line suitable for K8s admission rejections and operator-facing logs.

type Dependency added in v1.76.0

type Dependency struct {
	Constraint *semver.Constraints `json:"constraint" yaml:"constraint"` // Semver constraint the dependency must satisfy
	Optional   bool                `json:"optional" yaml:"optional"`     // If true, the check is skipped when the dependency is absent
}

Dependency describes a requirement on another package, with an optional semver constraint and a flag to skip the check when the target is absent.

type Event added in v1.76.0

type Event struct {
	Kind    EventKind
	Name    string
	Reason  string
	Message string
	Enabled []string
}

Event represents a single lifecycle transition in the scheduling graph. Name identifies the affected node; Enabled is populated only for EventGlobalDone.

type EventKind added in v1.76.0

type EventKind int

EventKind identifies the type of lifecycle event emitted by the Scheduler.

const (
	// EventSchedule is emitted when a node transitions from idle to scheduled.
	EventSchedule EventKind = iota
	// EventDisable is emitted when a node loses eligibility during a scheduling pass.
	EventDisable
	// EventGlobalDone is emitted when the global sentinel node completes,
	// carrying the list of currently enabled package names.
	EventGlobalDone
)

type NoneOfGroup added in v1.76.1

type NoneOfGroup struct {
	Name    string                         `json:"name" yaml:"name"`
	Members map[string]*semver.Constraints `json:"members" yaml:"members"`
}

NoneOfGroup is a group of forbidden dependencies: no member may be installed in a way that matches its constraint. A nil constraint on a member forbids the module at any installed version; a non-nil constraint narrows the forbidden range. Name is the stable identifier used by the scheduler in failure diagnostics.

type Option

type Option func(*Scheduler)

Option configures a Scheduler during construction.

func WithBootstrapCondition

func WithBootstrapCondition(cond condition.Condition) Option

WithBootstrapCondition sets the predicate that gates scheduling until bootstrap is ready.

func WithDeckhouseVersionGetter

func WithDeckhouseVersionGetter(deckhouseVersionGetter version.Getter) Option

WithDeckhouseVersionGetter sets the provider for the current Deckhouse version.

func WithDependencyGetter

func WithDependencyGetter(getter dependency.Getter) Option

WithDependencyGetter sets the provider for the current dependency version.

func WithKubeVersionGetter

func WithKubeVersionGetter(kubeVersionGetter version.Getter) Option

WithKubeVersionGetter sets the provider for the current Kubernetes version.

type Order added in v1.76.0

type Order uint

Order is a numeric priority for scheduling: lower values are processed first.

type Package

type Package interface {
	GetName() string
	GetVersion() *semver.Version
	GetConstraints() Constraints
}

Package is the interface that graph participants must implement to be managed by the Scheduler.

type Scheduler

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

Scheduler manages a dependency graph of packages and their lifecycle. Each scheduling pass recomputes eligibility, cascade-disables nodes that lost it, and advances newly-eligible nodes — all in topological order. All exported methods are safe for concurrent use.

func NewScheduler

func NewScheduler(opts ...Option) *Scheduler

NewScheduler creates a Scheduler with an empty dependency graph and a buffered event channel. Use functional options to configure version providers and conditions. Call Scheduler.Ch to consume lifecycle events.

func (*Scheduler) AddNode added in v1.76.0

func (s *Scheduler) AddNode(pkg Package) error

AddNode registers a single package, wires it into the existing graph, and triggers a full scheduling pass. Newly-eligible dependents are advanced automatically.

Returns a *CycleError (without mutating any state) if adding the package would close a dependency cycle. Callers are expected to handle the error — typically by surfacing a status condition on the corresponding CR — and to retry once the manifest is fixed.

func (*Scheduler) Ch added in v1.76.0

func (s *Scheduler) Ch() <-chan Event

Ch returns a read-only channel that emits Event values as the graph evolves. The caller must drain this channel to avoid blocking the scheduler.

func (*Scheduler) CheckConstraints added in v1.76.0

func (s *Scheduler) CheckConstraints(name string, constraints Constraints) error

CheckConstraints evaluates the given constraints against the current cluster state and the current dependency graph. Returns an error describing the first unsatisfied constraint (version, dependency) or a *CycleError if adding a node named `name` with these dependencies would create a topological cycle. Returns nil only when every check passes and the proposed addition would leave the dep graph acyclic.

`name` is the scheduler-side identifier of the package that would be added. It is used by the cycle-simulation step to identify the proposed graph vertex.

func (*Scheduler) Complete added in v1.76.0

func (s *Scheduler) Complete(completed string)

Complete marks the named package as active (processing finished) and runs a scheduling pass to advance any newly-eligible dependents.

func (*Scheduler) Dump added in v1.76.0

func (s *Scheduler) Dump() []byte

Dump returns a YAML snapshot of all nodes and their current state.

func (*Scheduler) DumpByName added in v1.76.0

func (s *Scheduler) DumpByName(name string) []byte

DumpByName returns a YAML snapshot of a single scheduler node by name. Returns empty bytes if the node is not found. It is used by the debug endpoint to inspect the scheduling state of an individual package without dumping the entire graph.

func (*Scheduler) Pause

func (s *Scheduler) Pause()

Pause prevents any state changes from being processed.

func (*Scheduler) RemoveNode added in v1.76.0

func (s *Scheduler) RemoveNode(name string)

RemoveNode removes a package from the graph and triggers a full reschedule.

func (*Scheduler) Reschedule added in v1.76.0

func (s *Scheduler) Reschedule(name string)

Reschedule reverts the named package to idle and runs a full scheduling pass, causing it (and potentially its dependents) to be rescheduled. It is a no-op if the package does not exist.

func (*Scheduler) Resume

func (s *Scheduler) Resume()

Resume enables state change processing and re-evaluates all packages. For each package whose state changed, the appropriate callback is invoked.

func (*Scheduler) Schedule added in v1.76.0

func (s *Scheduler) Schedule()

Schedule forces a full scheduling pass without changing any node state. Use when external conditions (e.g. Kubernetes version) have changed and the graph needs re-evaluation.

func (*Scheduler) Stop added in v1.76.0

func (s *Scheduler) Stop()

Stop closes the event channel, preventing further events from being sent. It is safe to call Stop concurrently and multiple times.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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