engine

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: 59 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 engine is the package engine of deckhouse-controller: it installs, updates, configures, disables and removes applications and, with EnableModuleV2, modules and Global; without it it runs applications only, beside addon-operator.

engine/            the composition root and the facade. build.go wires the services and the
                   core and orders their start and stop (read it first); services.go and
                   load.go build the services, the scheduler and the loader; facade.go is the
                   API the controllers call; sink.go routes notifications to the status
                   queues and the settings channels; admission.go serves the validation
                   webhooks; debug.go the dumps of the debug API; orphans.go and webhooks.go
                   adapt services to the core's interfaces.
engine/core/       the registry, the dispatcher, readiness and the boot.
engine/lifecycle/  the package Reconciler, one per package name: it owns Current and the
                   Candidate and decides the version (start with reconciler.go and loop.go,
                   then prepare.go, activate.go and remove.go). Its sub-packages:
  current/         Current, one per working revision: accept, run, disable, uninstall
                   (start with next.go, then loop.go).
  global/          Global: the global module and the barrier (EnableModuleV2 only).
  hooklane/        the hook lanes of Current and Global and their Router (lanes.go).
  gate/            gate.Decide, the package Reconciler's pure update decision.
  model/           the values the components hand each other: Desired, Revision, Report.
  configstate/     the configuration state Current and Global share.
  inbox/, operation/, report/, retry/
                   the loops' primitives: latest-value inputs, the operation worker, the
                   Report store, the backoff and the clock.
engine/schedule/   the scheduler: the convergence protocol and the graph (protocol.go,
                   then scheduler.go); rule/ holds the rules a node's decision folds.
engine/objectpatcher/
                   the patcher of the hooks' patches; under Module v2 a readiness hook's patch
                   of the Module status becomes the probe's verdict.
engine/enginetest/ the scenario kit over fakes; tests only.

core, lifecycle and schedule make up the core and, by convention, import no Kubernetes client: every cluster effect goes through an interface its consumer declares, implemented by a service this package builds. One cluster read happens inside a scheduler computation: in the default tree the dependency getter (services.go, addonDependencyGetter) reads the Module of an application's dependency from the manager's cached client.

A package's status has two halves, joined by name in the status projection: Engine.Report, the lifecycle half (decisions and the results of operations), and Engine.Observed, the observed half (internal/packages/observed: what the release service, the health service and the hook lanes observe). The hook lanes, which run inside the lifecycle, write a hook failure there; the rest of the core does not touch it. The facade forgets a package's observations when it reports its removal done.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application struct {
	Namespace string
	Name      string
	// PackageName is spec.packageName: the package in the repository.
	PackageName string
	// Version is spec.packageVersion: the version that should become Current.
	Version    string
	Repository registry.Remote
	// Settings and SettingsVersion are spec.settings and the settings-schema version they are
	// written for (spec.version).
	Settings        addonutils.Values
	SettingsVersion int
	Maintenance     string
	// ResourceRequests are spec.resourceRequests.
	ResourceRequests []resourcesize.Request
	// UpdateSettings are the update settings the application follows, already merged by the
	// controller (spec.update, global.applications.update, the deckhouse ModuleConfig).
	UpdateSettings releaseupdater.Settings
	// ApplyNow skips the update windows (model.Policy.Force): the Application controller sets it
	// while the apply-now annotation names spec.packageVersion. It never skips the requirements,
	// the dependents or the settings check.
	ApplyNow bool
	// Requirements of the ApplicationPackageVersion of Version (application.requirementsOf).
	Requirements schedule.Constraints
}

Application is an Application resource as the controller hands it to the engine.

type BootApplication

type BootApplication struct {
	Namespace      string
	Name           string
	PackageName    string
	Repository     registry.Remote // Repository is the one in spec.
	CurrentVersion string          // CurrentVersion is status.currentVersion; empty restores nothing.
	// LastApplied is the raw status.lastAppliedConfiguration (checkpointSettings).
	LastApplied      []byte
	Maintenance      string
	ResourceRequests []resourcesize.Request
	// Removing: the Application is being deleted and has a CurrentVersion; Boot restores it to
	// uninstall it (model.BootPackage.Removing).
	Removing bool
	// Notified is status.update.notified (model.BootPackage.Notified).
	Notified model.Notified
}

BootApplication is what Boot needs of an installed Application (see model.BootPackage).

type BootModule

type BootModule struct {
	Name       string
	Repository registry.Remote
	Embedded   bool
	// CurrentVersion is status.currentVersion; for an embedded module only whether it is set
	// matters (it is restored with the version the image ships).
	CurrentVersion string
	LastApplied    []byte // LastApplied is the raw status.lastAppliedConfiguration.
	Maintenance    string
	// Enabled must be passed: an unknown intent falls to the module floor (Disable).
	Enabled *bool
	// Removing: the Module is being deleted and has a CurrentVersion (BootApplication.Removing).
	Removing bool
}

BootModule is what Boot needs of an installed Module; global is not passed.

type Config

type Config struct {
	// EnableModuleV2 runs modules and Global in the engine (app.ModuleV2Enabled). Off: modules stay
	// in addon-operator, the engine runs applications only, reads the gate inputs from
	// addon-operator's global values and waits for Resume after addon-operator's converge.
	EnableModuleV2 bool
}

Config is the option the callers decide on.

type ConvergeDump

type ConvergeDump struct {
	Converged bool                           `json:"converged" yaml:"converged"`
	Paused    bool                           `json:"paused,omitempty" yaml:"paused,omitempty"` // Paused: before the boot gate or stopped.
	Packages  map[string]ConvergePackageDump `json:"packages,omitempty" yaml:"packages,omitempty"`
}

ConvergeDump is what the convergence waits for; Packages is empty once Converged.

type ConvergePackageDump

type ConvergePackageDump struct {
	Version  string `json:"version,omitempty" yaml:"version,omitempty"` // Version is the revision being converged.
	WaitsFor string `json:"waitsFor,omitempty" yaml:"waitsFor,omitempty"`
	Error    string `json:"error,omitempty" yaml:"error,omitempty"`
}

ConvergePackageDump is one unconverged node: what it waits for and the failure its report holds.

type Engine

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

Engine is the package engine as deckhouse-controller uses it: the core with every service it runs on. The facade (facade.go) translates controller terms into the core's inputs and keeps no lifecycle state.

func Build

func Build(cli kclient.Client, moduleManager moduleManager, metricStorage metricsstorage.Storage, logger *log.Logger, cfg Config) (*Engine, error)

Build creates the engine with every service it needs. It starts nothing but the core's dispatcher; the scheduler is paused until Boot or Resume. moduleManager is required without EnableModuleV2 and must be nil with it.

func (*Engine) ApplyApplication

func (e *Engine) ApplyApplication(a Application)

ApplyApplication passes the desired state of an application. Call it on every reconcile of an Application that is not being deleted. Non-blocking.

func (*Engine) ApplyGlobal

func (e *Engine) ApplyGlobal(settings addonutils.Values, settingsVersion int)

ApplyGlobal passes the global settings to Global; dropped without EnableModuleV2. Non-blocking.

func (*Engine) ApplyModule

func (e *Engine) ApplyModule(m Module)

ApplyModule passes the desired state of a module, its enable intent included. Ignored without EnableModuleV2. Non-blocking.

func (*Engine) Boot

func (e *Engine) Boot(ctx context.Context, global []byte, bootApps []BootApplication, bootModules []BootModule) error

Boot is core.Engine.Boot over the controllers' view of the installed packages. global is the raw lastAppliedConfiguration of the global Module; without EnableModuleV2 it is ignored and modules must be empty.

func (*Engine) CheckConstraints

func (e *Engine) CheckConstraints(name string, constraints schedule.Constraints) error

CheckConstraints reports whether a node with constraints would be admitted now (schedule.Scheduler.CheckConstraints); name is the node name (apps.BuildName for an application).

func (*Engine) Converge

func (e *Engine) Converge() any

Converge returns the global and module nodes core.Engine.Converged waits for, each with its failure; the scheduler and the reports are read apart, so it is not one snapshot.

func (*Engine) DiskCleanup

func (e *Engine) DiskCleanup(ctx context.Context, apps, modules []disk.PreservePackage) error

DiskCleanup brings the disks to a consistent state before Boot: each removes the images and mounts its list does not name. It is the only place files are purged. The lists name every version the cluster claims, packages being deleted included unless their release is deleted by name: Boot restores them to uninstall them. Releases are left alone: a package's release goes with its uninstall. An entry without a version is dropped. Without EnableModuleV2 the module disk is addon-operator's and modules is ignored; with it the module list is acted on whatever it holds, so the caller must not pass one it failed to read. Every failure is returned; none stops the other parts.

func (*Engine) Dump

func (e *Engine) Dump() any

Dump returns every package the core knows, applications and modules apart.

func (*Engine) DumpByName

func (e *Engine) DumpByName(name string) any

DumpByName returns one package; nil for an unknown name.

func (*Engine) DumpGlobal

func (e *Engine) DumpGlobal() any

DumpGlobal returns Global's report, observation and info; nil without EnableModuleV2.

func (*Engine) DumpQueues

func (e *Engine) DumpQueues(name string) any

DumpQueues returns the hook lanes of every package and Global, or name's when it is set (hooklane.Router.Dump).

func (*Engine) DumpScheduler

func (e *Engine) DumpScheduler() any

DumpScheduler is schedule.Scheduler.Dump.

func (*Engine) DumpSchedulerByName

func (e *Engine) DumpSchedulerByName(name string) any

DumpSchedulerByName is schedule.Scheduler.DumpByName.

func (*Engine) GetAppStatusQueue

func (e *Engine) GetAppStatusQueue() workqueue.TypedRateLimitingInterface[string]

GetAppStatusQueue returns the queue of application names whose status may have changed.

func (*Engine) GetDeckhouseSettingsCh

func (e *Engine) GetDeckhouseSettingsCh() <-chan addonutils.Values

GetDeckhouseSettingsCh carries the latest effective settings of the deckhouse module (statusSink.publishSettings). Only with EnableModuleV2.

func (*Engine) GetEnabledModuleNames

func (e *Engine) GetEnabledModuleNames() []string

GetEnabledModuleNames returns the modules the scheduler enabled, sorted; empty without EnableModuleV2.

func (*Engine) GetGlobalSettingsCh

func (e *Engine) GetGlobalSettingsCh() <-chan addonutils.Values

GetGlobalSettingsCh carries the latest effective global settings.

func (*Engine) GetModuleStatusQueue

func (e *Engine) GetModuleStatusQueue() workqueue.TypedRateLimitingInterface[string]

GetModuleStatusQueue is GetAppStatusQueue for modules and global.

func (*Engine) IsPackageEnabled

func (e *Engine) IsPackageEnabled(name string) bool

IsPackageEnabled reports the scheduler's latest decision about name; false before one arrived. Global is always enabled when the engine runs it.

func (*Engine) Observed

func (e *Engine) Observed(name string) observed.Observation

Observed returns the observed half of name's status; the projection builds the status from Report and Observed.

func (*Engine) Ready

func (e *Engine) Ready() bool

Ready is core.Engine.Ready.

func (*Engine) Recheck

func (e *Engine) Recheck()

Recheck is core.Engine.Recheck.

func (*Engine) RemoveApplication

func (e *Engine) RemoveApplication(namespace, name string) bool

RemoveApplication uninstalls an application and reports whether the removal has finished, so the controller can release the finalizer; the status queue is notified when it does. Non-blocking and idempotent.

func (*Engine) RemoveModule

func (e *Engine) RemoveModule(name string) bool

RemoveModule is RemoveApplication for a module. It reports true at once for global and without EnableModuleV2.

func (*Engine) Render

func (e *Engine) Render(ctx context.Context, name string) (string, error)

Render renders the chart of name's activated object in its release namespace.

func (*Engine) Report

func (e *Engine) Report(name string) (model.Report, bool)

Report is core.Engine.Report: the lifecycle half of name's status.

func (*Engine) Resume

func (e *Engine) Resume()

Resume is core.Engine.Resume.

func (*Engine) Snapshots

func (e *Engine) Snapshots(name string) (any, bool)

Snapshots returns the hook snapshots of name's activated object (or Global's); false when there is none.

func (*Engine) Start

func (e *Engine) Start()

Start starts the services that run independently of the lifecycle. Called once, before DiskCleanup and Boot. Non-blocking. The hook event loop starts before Boot, during which Global's hooks start (the restored Currents' follow in their first runs), and before the cron manager, whose channel only the loop drains. The hook lanes start with their package's hooks.

func (*Engine) Stop

func (e *Engine) Stop()

Stop stops the engine and every service. Blocking; safe to call more than once and before Start (a lost election), but only after Boot returned. Order:

  1. the core: stopping Currents and Global stop their hook lanes while the event loop still runs;
  2. the drift monitors: only a running Current adds one;
  3. the health service;
  4. the event sources;
  5. the goroutines Start runs — the hook event loop (the hook lanes stopped with the core, so no run is left to send an event) and the sink —, then the status queues, which nothing feeds any more.

func (*Engine) ValidateModuleExclusiveGroup

func (e *Engine) ValidateModuleExclusiveGroup(group string) error

ValidateModuleExclusiveGroup returns an error when an enabled module belongs to group.

func (*Engine) ValidatePackageSettings

func (e *Engine) ValidatePackageSettings(ctx context.Context, name string, settingsVersion int, settings addonutils.Values) (settingscheck.Result, error)

ValidatePackageSettings converts and validates settings with the object of name's activated version, or with Global for global. Valid while the package has no activated object: the engine checks the settings itself before it activates one.

type Module

type Module struct {
	Name string
	// Version is spec.packageVersion; ignored for an embedded module, whose version is the one the
	// deckhouse image ships.
	Version    string
	Repository registry.Remote
	// Embedded is set for a module the deckhouse image ships.
	Embedded        bool
	Settings        addonutils.Values
	SettingsVersion int
	Maintenance     string
	// Enabled is Module.spec.enabled, the module's enable intent; nil means none.
	Enabled *bool
	// UpdateSettings and ApplyNow are Application's for a module. No controller sets them yet, so
	// a module follows no update window: modules get them with the module update work.
	UpdateSettings releaseupdater.Settings
	ApplyNow       bool
	// Requirements of the ModulePackageVersion of Version.
	Requirements schedule.Constraints
}

Module is a Module resource as the controller hands it to the engine.

Directories

Path Synopsis
Package core is the engine core: the registry of package Reconcilers, Global, the boot, the dispatcher of scheduler events and readiness.
Package core is the engine core: the registry of package Reconcilers, Global, the boot, the dispatcher of scheduler events and readiness.
Package enginetest is the scenario kit of the package engine: a real core, scheduler, package Reconcilers, Currents and Global over fakes of the disk, the loader, nelm, the hook bindings, the orphan purge and Global's CRD and webhook services.
Package enginetest is the scenario kit of the package engine: a real core, scheduler, package Reconcilers, Currents and Global over fakes of the disk, the loader, nelm, the hook bindings, the orphan purge and Global's CRD and webhook services.
Package lifecycle is the package Reconciler, one per package name: it decides which revision of the package runs and owns the two things that run it, Current (the running revision, lifecycle/current) and the Candidate (the preparation of the desired one).
Package lifecycle is the package Reconciler, one per package name: it decides which revision of the package runs and owns the two things that run it, Current (the running revision, lifecycle/current) and the Candidate (the preparation of the desired one).
configstate
Package configstate holds the configuration state Current and Global share: what was pushed, what is in force, and the checksum every configuration is identified by.
Package configstate holds the configuration state Current and Global share: what was pushed, what is in force, and the checksum every configuration is identified by.
current
Package current runs the working revision of one package: its configuration, hooks and release.
Package current runs the working revision of one package: its configuration, hooks and release.
gate
Package gate is the update decision of one package: Decide answers whether the desired revision is Current, must be prepared, is blocked, or may be activated.
Package gate is the update decision of one package: Decide answers whether the desired revision is Current, must be prepared, is blocked, or may be activated.
global
Package global runs Global: the global hooks, the global settings and the global run, which ensures the CRDs and conversion webhooks of the enabled modules and publishes the enabled set into the global values.
Package global runs Global: the global hooks, the global settings and the global run, which ensures the CRDs and conversion webhooks of the enabled modules and publishes the enabled set into the global values.
hooklane
Package hooklane runs a package's runtime and synchronization hooks in lanes: one lane per hook queue of the package, a FIFO with one goroutine, so the hooks of one queue run one at a time in event order and the queues run in parallel, beside the package's operations.
Package hooklane runs a package's runtime and synchronization hooks in lanes: one lane per hook queue of the package, a FIFO with one goroutine, so the hooks of one queue run one at a time in event order and the queues run in parallel, beside the package's operations.
inbox
Package inbox holds the latest value of every input of a loop plus a wake signal: inputs are states passed whole, so a loop that wakes late loses nothing by reading only the last one.
Package inbox holds the latest value of every input of a loop plus a wake signal: inputs are states passed whole, so a loop that wakes late loses nothing by reading only the last one.
model
Package model is the vocabulary of the package lifecycle: the data that flows between Engine, the package Reconciler, Current and Global, and the Report.
Package model is the vocabulary of the package lifecycle: the data that flows between Engine, the package Reconciler, Current and Global, and the Report.
operation
Package operation runs one operation of Current, Global or the package Reconciler (the preparation of a candidate): its steps, in order, in a worker goroutine that the owner's loop starts and cancels.
Package operation runs one operation of Current, Global or the package Reconciler (the preparation of a candidate): its steps, in order, in a worker goroutine that the owner's loop starts and cancels.
report
Package report stores the Report of one package or of Global.
Package report stores the Report of one package or of Global.
retry
Package retry is the backoff of every execution failure in the lifecycle and the Clock its deadlines are read with.
Package retry is the backoff of every execution failure in the lifecycle and the Clock its deadlines are read with.
Package notify sends the update notifications of packages to the webhook of the notification settings (applications.update.notification); the package Reconciler decides when.
Package notify sends the update notifications of packages to the webhook of the notification settings (applications.update.notification); the package Reconciler decides when.
Package objectpatcher is the patcher of the hooks' patches.
Package objectpatcher is the patcher of the hooks' patches.
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?".
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?".
rule
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.
rule/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.
rule/dynamic
Package dynamic is a module's enable intent rule.
Package dynamic is a module's enable intent rule.
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