schedule

package
v1.77.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 19 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 gate-rule inputs.
	AnyOf        []AnyOfGroup          // Groups of alternative dependencies. Gate-only: never contributes edges to the topological graph, so fallback chains across packages do not produce cycles.
	NoneOf       []NoneOfGroup         // Groups of forbidden dependencies. Gate-only: "must not be installed" is an admission predicate, not an ordering relation.

	Subscriptions map[string]struct{} // Subscriptions to other nodes: this node will be notified when the subscribed node changes state.
	// Licensing carries the package's per-edition availability and bundle
	// membership. It is the data the edition gate and bundle floor consume,
	// resolved live against the active edition. The package supplies only the
	// data — resolution logic lives in the edition package.
	Licensing edition.Licensing

	// Floor is the package's lowest-precedence rule: its default decision when no
	// higher-precedence intent rule (bundle, user, script) has an opinion. Apps and Global
	// set rule.Static(rule.Enable) (on whenever loaded); modules set
	// rule.Static(rule.Disable). It is the only behavior-carrying field here — admission
	// (CheckConstraints) ignores it, since the floor is intent, not a
	// requirement. A nil Floor means no floor: with gates-only the package
	// resolves to Undefined and stays off, so every package must set one.
	Floor rule.Rule
}

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 carries the current enabled module set on an EventSchedule for [GlobalName].

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
)

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 WithBundleChecker added in v1.77.0

func WithBundleChecker(getter bundle.BundleChecker) Option

WithBundleChecker sets the bundle checker function for the scheduler.

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 WithDynamicGetter added in v1.77.0

func WithDynamicGetter(getter dynamic.Getter) Option

WithDynamicGetter sets the provider for a module's resolved enablement intent (ModuleConfig plus dynamic hook state), answered by the global module.

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
	GetEnabledScriptDescriptor() *script.Descriptor
}

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(logger *log.Logger, 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. Its direct subscribers are reverted to idle in the same pass so they are rescheduled too; the cascade is one level deep — a subscriber's own subscribers are not touched. 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
Package rule models the single enable/disable signal type the scheduler folds to decide whether a package may run.
Package rule models the single enable/disable signal type the scheduler folds to decide whether a package may run.
bundle
Package bundle provides a module floor rule: it enables a module when the cluster's active bundle is one that enables it in the active edition, and soft-disables it otherwise.
Package bundle provides a module floor rule: it enables a module when the cluster's active bundle is one that enables it in the active edition, and soft-disables it otherwise.
dynamic
Package dynamic provides the module enablement intent rule: the highest- precedence enablement signal a module carries, folding the external enable/disable signals (explicit ModuleConfig intent and the deprecated global-hook dynamic enable).
Package dynamic provides the module enablement intent rule: the highest- precedence enablement signal a module carries, folding the external enable/disable signals (explicit ModuleConfig intent and the deprecated global-hook dynamic enable).
script
Package script models a module's enabled script as a scheduler rule.
Package script models a module's enabled script as a scheduler rule.

Jump to

Keyboard shortcuts

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