schedule

package
v1.78.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package schedule is the scheduler: one graph of every package node (modules, applications and Global) and one computation that answers, for every node at once, "may it run now?".

Facts in, levels out (protocol.go): a Current or Global publishes only facts about its own node (Publish); the scheduler computes, atomically under one mutex, every node's state and delivers it as one latest Event per node, signalled by Wake and read in batches by Take. A lost or repeated message changes nothing: the next one carries the whole state. Per computation:

decision     the node's rule chain folded by rule.Resolve. The position is the precedence:
             the floor, then the requirement gates, which can only forbid, then the intent
             rules (Module.spec.enabled, the global hooks' signal, the enabled script).
inputs       a hash of the decision, the node's own inputs and the Output of the nodes it
             subscribes to; Global's also name every enabled module's revision.
convergence  disabled, or the node applied exactly these inputs.
gate         enabled, and Global, every lower tier, every dependency and every kept AnyOf
             member are converged.

The scheduler starts paused and computes nothing before the boot gate (Resume): an unknown input reads as Forbid, so an earlier computation would disable modules and delete their releases. Recheck recomputes for inputs no fact carries (addon-operator's state, a global hook's signal).

protocol.go   Facts, Event and the errors the admission checks return.
scheduler.go  the Scheduler: its inputs, the computation, the gate.
node.go       Node, Constraints and the rule chain of a node (addNode).
event.go      delivery: the latest-value slots, Wake and Take.
topo.go       the dependency order and cycle detection.
dump.go       the debug dump.
rule/         the rule families a chain is built from.

Rules and getters run inside the computation under the mutex: they must not call back into the scheduler, and a slow one holds every package. The package never imports the engine.

Index

Constants

View Source
const (
	// FunctionalOrder is the Order of functional (non-critical) packages: above every critical
	// order, so they are gated until all critical packages converged, and bootstrap-gated.
	FunctionalOrder = 999
)
View Source
const GlobalNode = "global"

GlobalNode is the name of the global node. Its inputs carry the identity of every enabled module, and every other node waits for it to be converged (the global barrier, see gateOf).

View Source
const ReasonDependencyCycle = "DependencyCycle"

ReasonDependencyCycle is the reason of a rejection by AddNode or CheckConstraints: the node would close a dependency cycle.

View Source
const ReasonDependentRequirementsUnmet = "DependentRequirementsUnmet"

ReasonDependentRequirementsUnmet is the reason of a rejection by CheckDependents: an enabled package that depends on the node does not accept its new version.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyOfGroup

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

AnyOfGroup passes when at least one member is enabled and satisfies its constraint (nil: any version). Name appears in failure messages.

type ConstraintError

type ConstraintError struct {
	Reason  string // Reason is a Kubernetes condition reason.
	Message string
	// contains filtered or unexported fields
}

ConstraintError is why a node would not be admitted (CheckConstraints, AddNode).

func (*ConstraintError) Error

func (e *ConstraintError) Error() string

func (*ConstraintError) Unwrap

func (e *ConstraintError) Unwrap() error

Unwrap returns the typed cause (*CycleError for a cycle), or nil.

type Constraints

type Constraints struct {
	Order        Order                 // Order: 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 // Dependencies are hard ordering edges and gate inputs.
	AnyOf        []AnyOfGroup          // AnyOf members are soft edges, dropped where they close a cycle.
	NoneOf       []NoneOfGroup         // NoneOf is gate-only: no ordering edge.

	// Subscriptions name the nodes whose Output is part of this node's inputs. The engine
	// subscribes every package to global.
	Subscriptions map[string]struct{}
	// Licensing is the per-edition availability and bundle membership the bundle rule resolves
	// against the active edition.
	Licensing edition.Licensing

	// Floor is the lowest-precedence rule, the default when no intent rule has an opinion:
	// Static(Enable) for applications and Global, Static(Disable) for modules. A Disable floor also
	// gives the node the intent rules (addNode). Admission ignores it. A nil Floor leaves only the
	// gates, so the node resolves to Undefined and stays off.
	Floor rule.Rule
}

Constraints are the scheduling requirements of a package.

type CycleError

type CycleError struct {
	Members []string
}

CycleError is a dependency cycle; Members are the participants, sorted.

func (*CycleError) Error

func (e *CycleError) Error() string

Error renders the cycle in one line, for admission rejections and logs.

type Dependency

type Dependency struct {
	Constraint *semver.Constraints `json:"constraint" yaml:"constraint"`
	Optional   bool                `json:"optional" yaml:"optional"`
}

Dependency is a requirement on another package; Optional skips the check when it is absent.

type EnabledModule

type EnabledModule struct {
	// ID is name@revision; Global's inputs hash it.
	ID string
	// Attachment is the node's Node.Attachment, passed through untouched.
	Attachment any
}

EnabledModule is one enabled module in Global's event. It is built from the node in the same computation as the list, so the list and the attachments always describe the same revisions.

type Event

type Event struct {
	Name string
	// Version is the node's revision; a receiver ignores an event of another revision.
	Version string
	Enabled bool
	// Reason and Message explain a negative decision; empty when enabled.
	Reason  string
	Message string
	// OwnInputs echoes the Facts.OwnInputs the event was computed from.
	OwnInputs string
	// Inputs is the hash of everything a run of the node depends on (inputsOf).
	Inputs string
	Gate   bool // Gate: enabled, and everything the node waits for is converged (gateOf).
	// EnabledModules is set only for the global node: every enabled module, sorted by ID.
	// Applications are not listed: their CRDs are not Global's.
	EnabledModules []EnabledModule
}

Event is the computed state of one node, produced for every node on every computation; the engine takes the latest per node in batches (Wake, Take).

type Facts

type Facts struct {
	Version string // Version must equal the node's Revision.
	// OwnInputs is the hash of the node's own inputs. The scheduler mixes it into the inputs and
	// echoes it in the event, so the Current can tell which of its inputs an event reflects.
	OwnInputs string
	// Applied is the Inputs of the last successful run or disable; empty when unknown.
	Applied string
	// Output is the checksum of what the node publishes for its subscribers, whose inputs hash it:
	// Global's is its values after the publish step, a module Current's its image digests.
	Output string
}

Facts is what a Current publishes about its own node; facts of another revision are ignored, and a replaced node drops its facts.

type Node

type Node struct {
	Name    string
	Version *semver.Version // Version is what dependents' rules compare against.
	// Revision is the identity in the protocol (Facts.Version, Event.Version) and in Global's
	// inputs: the image version. Not Version.String(): the image version may be spelled differently
	// (a leading v).
	Revision string
	// Module marks a module node: only enabled modules make up Global's enabled set and an enabled
	// script's global.enabledModules.
	Module      bool
	Constraints Constraints
	// EnabledScript returns the module's enabled script, nil when it ships none. Called on every
	// computation, so it reads the object's live settings.
	EnabledScript func() *script.Descriptor
	// Attachment is opaque to the scheduler: it rides on Global's event with an enabled module
	// (EnabledModule), so Global reads the revision the event names and no other.
	Attachment any
	// Output is the revision's Output, known when it is added: the node starts with it, so a
	// subscriber sees the new revision's Output at once, never an empty one until its Current
	// publishes the same value.
	Output string
}

Node is one revision of a package as AddNode registers it; a new revision is a new Node.

type NoneOfGroup

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

NoneOfGroup passes when no member is enabled at a version matching its constraint (nil: any version). Name appears in failure messages.

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 functional packages until bootstrap.

func WithBundleChecker

func WithBundleChecker(getter bundle.BundleChecker) Option

WithBundleChecker sets the active edition's bundle check.

func WithConvergenceHook

func WithConvergenceHook(hook func(converged bool)) Option

WithConvergenceHook sets the function told when the graph's convergence changes (Converged): false at Resume and whenever a computation leaves the graph unconverged, true when one converges it. Called under the scheduler's lock: it must not block.

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 replaces the graph as the source of dependency versions.

func WithDynamicGetter

func WithDynamicGetter(getter dynamic.Getter) Option

WithDynamicGetter sets the provider of a module's enable signal from global hooks (the deprecated "<module>Enabled" values patch), consulted only without an intent from SetIntent: Module.spec.enabled first, then the hook signal. It is called under the scheduler's mutex and must not call back. Its change reaches no fact, so its owner calls Recheck after it.

func WithKubeVersionGetter

func WithKubeVersionGetter(kubeVersionGetter version.Getter) Option

WithKubeVersionGetter sets the provider for the current Kubernetes version.

type Order

type Order uint

Order is a scheduling priority: lower values run first.

type Scheduler

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

Scheduler is the graph of packages: their rule chains, the facts their Currents publish, the enable intents, and one computation that derives every node's decision, inputs, convergence and gate (protocol.go). Every exported method is safe for concurrent use and never blocks on a consumer; every method that may change the result computes before it returns, so the last computation is always the current state.

func NewScheduler

func NewScheduler(logger *log.Logger, opts ...Option) *Scheduler

NewScheduler creates a paused Scheduler with an empty graph. Nothing is computed until Resume: before the boot the gate inputs and the intents are unknown, and an unknown input reads as Forbid.

func (*Scheduler) AddNode

func (s *Scheduler) AddNode(nd Node) error

AddNode adds nd or replaces the node of the same name, dropping its facts: they describe the stopped Current. A node that would close a cycle is rejected (ReasonDependencyCycle) and the graph is not changed. It computes either way.

func (*Scheduler) CheckConstraints

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

CheckConstraints checks constraints against the cluster and the graph and simulates adding a node named name with them. It returns a *ConstraintError for the first unmet requirement, or with ReasonDependencyCycle (wrapping a *CycleError) for a cycle. Read-only; while paused the dependency answers from the graph are not meaningful yet.

func (*Scheduler) CheckDependents

func (s *Scheduler) CheckDependents(name string, version *semver.Version) error

CheckDependents reports whether replacing the node named name by a revision at version would forbid an enabled package that depends on it: one whose dependency on name has a constraint the version does not meet. It returns a *ConstraintError with ReasonDependentRequirementsUnmet naming every such dependent, sorted; nil when there is none or version is nil. Read-only.

Why: the dependent's own rule would forbid it at the next computation, which disables it and deletes its release, a consequence of another package's update nobody asked for. The old module dependency extender refused such a release the same way. Only Dependencies count, as there: an optional one too, because an optional dependency that is present must still match. AnyOf and NoneOf groups are not checked.

func (*Scheduler) Converged

func (s *Scheduler) Converged() bool

Converged reports whether the scheduler is running and the global node and every module node are converged. Applications do not count: a broken user application must not keep Deckhouse unready.

func (*Scheduler) Dump

func (s *Scheduler) Dump() any

Dump returns a snapshot of all nodes.

func (*Scheduler) DumpByName

func (s *Scheduler) DumpByName(name string) any

DumpByName returns a snapshot of one node; nil when it is unknown.

func (*Scheduler) Publish

func (s *Scheduler) Publish(name string, f Facts)

Publish stores the facts of the named node and computes. Facts of another revision are ignored, so a stopped Current cannot change its replacement's; equal facts skip the computation. They are compared under the read lock first: every Current publishes on every wake, mostly equal facts, which must not queue on the write lock behind a computation.

func (*Scheduler) Recheck

func (s *Scheduler) Recheck()

Recheck computes once (when and why: core.Engine.Recheck). A no-op while paused or stopped.

func (*Scheduler) RemoveNode

func (s *Scheduler) RemoveNode(name string)

RemoveNode drops the node and its unread event and computes; unknown names are ignored. The intent is kept: it belongs to the configuration.

func (*Scheduler) Resume

func (s *Scheduler) Resume()

Resume resumes computations and computes once. A Resume while running does nothing.

func (*Scheduler) SetIntent

func (s *Scheduler) SetIntent(name string, enabled *bool)

SetIntent sets the Module.spec.enabled intent of name (nil removes it) and computes. It is kept by name, across the node's replacement and removal. The module's dynamic rule reads it (see addNode for its precedence); applications and global have no such rule.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop ends the scheduler: no more computations, and Wake is closed. Idempotent.

func (*Scheduler) Take

func (s *Scheduler) Take() []Event

Take returns the latest unread event of every node, sorted by name, and empties the slots.

func (*Scheduler) Unconverged

func (s *Scheduler) Unconverged() Unconverged

Unconverged returns the global and module nodes Converged waits for; applications never hold it.

func (*Scheduler) Wake

func (s *Scheduler) Wake() <-chan struct{}

Wake signals that events are pending; any number of computations leaves one signal. Stop closes it, which ends the consumer's loop.

type Unconverged

type Unconverged struct {
	Paused bool                       // Paused: paused or stopped, nothing is computed.
	Nodes  map[string]UnconvergedNode // Nodes are the unconverged global and module nodes; empty while Paused.
}

Unconverged is what Converged waits for in the scheduler.

type UnconvergedNode

type UnconvergedNode struct {
	Revision string // Revision is the node's revision, the one its Current runs.
	// WaitsFor is global, the nodes of the nearest unconverged tier below, or a dependency or AnyOf member.
	WaitsFor string
}

UnconvergedNode is one unconverged node; WaitsFor is empty while its gate is open.

Directories

Path Synopsis
Package rule is the enable/disable signal the scheduler folds to decide whether a package runs.
Package rule is the enable/disable signal the scheduler folds to decide whether a package runs.
bundle
Package bundle is a module intent rule: Enable when the active bundle of the active edition enables the module, a soft Disable otherwise.
Package bundle is a module intent rule: Enable when the active bundle of the active edition enables the module, a soft Disable otherwise.
dynamic
Package dynamic is a module's enable intent rule.
Package dynamic is a module's enable intent rule.
script
Package script is a module's enabled script as a scheduler rule.
Package script is 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