runtime

package
v1.76.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 60 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConditionReasonLoadFailed status.ConditionReason = "LoadFailed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Name       string
	Namespace  string
	Definition apps.Definition
	Settings   addonutils.Values
}

App represents an application instance as received from the Application controller. It carries the user-specified package identity, version constraints, and settings.

type Module

type Module struct {
	Name       string
	Definition modules.Definition
	Settings   addonutils.Values
}

Module represents a module instance as received from the module controller. Unlike App, modules always run in the d8-system namespace.

type Runtime

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

Runtime orchestrates the full lifecycle of application packages: discovery, installation, hook execution, Helm release management, and removal.

State is split across three structures, all protected by r.mu:

  • packages (lifecycle.Store): contexts and pending settings — the cancellation and change-detection layer, type-agnostic
  • apps: loaded Application instances, keyed by name
  • modules: loaded Module instances, keyed by name

Task execution is delegated to queue.Service (one queue per package), and cluster coordination to the scheduler, NELM, and hook event systems.

func New

func New(cli kclient.Client, moduleManager moduleManagerI, dc dependency.Container, logger *log.Logger) (*Runtime, error)

New creates and initializes a Runtime with all subsystems wired together. Blocks until the NELM cache completes its initial sync.

func (*Runtime) BuildKubeTasks

func (r *Runtime) BuildKubeTasks(ctx context.Context, kubeEvent shkubetypes.KubeEvent) map[string][]queue.Task

BuildKubeTasks converts a Kubernetes event into executable tasks for all matching hooks.

For each package:

  1. Find hooks that are bound to Kubernetes events
  2. Check if the hook can handle this specific event (filtering)
  3. Generate tasks for matching hooks using the provided builder

Returns a map of queue names to tasks, allowing different hooks to be routed to different queues (e.g., priority queues, sequential queues).

func (*Runtime) BuildScheduleTasks

func (r *Runtime) BuildScheduleTasks(ctx context.Context, crontab string) map[string][]queue.Task

BuildScheduleTasks converts a schedule (cron) event into executable tasks for all matching hooks.

For each package:

  1. Find hooks that are bound to schedule events
  2. Check if the hook's schedule matches the triggered crontab
  3. Generate tasks for matching hooks using the provided builder

Returns a map of queue names to tasks, allowing hooks to specify their execution queue.

func (*Runtime) CheckConstraints added in v1.76.0

func (r *Runtime) CheckConstraints(constraints schedule.Constraints) error

CheckConstraints checks constraints in scheduler

func (*Runtime) Dump

func (r *Runtime) Dump() []byte

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

Includes for each package:

  • Status: Current phase (Pending/Loaded/Running)
  • State: Scheduler state (enabled/disabled with reason)
  • Info: Instance name and namespace, current package configuration values and hooks

Used for debugging and introspection of operator internal state. Skips packages that have been removed from the manager.

func (*Runtime) DumpByName added in v1.76.0

func (r *Runtime) DumpByName(name string) []byte

DumpByName returns a YAML snapshot of a single package by name. Checks apps first, then modules. Returns an empty dump if not found.

func (*Runtime) RemoveApp

func (r *Runtime) RemoveApp(namespace, instance string)

RemoveApp removes an application and cancels all its running operations.

After the uninstall task succeeds, a cleanup goroutine removes the Store entry and stops the queue. The goroutine is necessary because queueService.Remove stops the queue — calling it synchronously from within the queue's own processing loop would deadlock on WaitGroup.

Store.Delete has a state guard: if UpdateApp re-created the package between uninstall and cleanup, Delete is a no-op (version != "").

func (*Runtime) RemoveModule

func (r *Runtime) RemoveModule(name string)

RemoveModule removes a module and cancels all its running operations. After uninstall, a cleanup goroutine removes the Store entry and stops the queue. See RemoveApp for detailed rationale on the async cleanup pattern.

func (*Runtime) Run added in v1.76.0

func (r *Runtime) Run()

Run starts the scheduler event loop in a background goroutine. It listens for schedule and disable events from the scheduler and dispatches them to the appropriate handler, driving the enable/disable lifecycle for all packages.

func (*Runtime) Scheduler

func (r *Runtime) Scheduler() *schedule.Scheduler

Scheduler returns package scheduler for external access

func (*Runtime) Status

func (r *Runtime) Status() *status.Service

Status returns package status service for external access

func (*Runtime) Stop

func (r *Runtime) Stop()

Stop performs graceful shutdown of all operator subsystems.

Shutdown order ensures safe termination:

  1. Stop NELM monitors (cleanup resource monitoring)
  2. Pause Kubernetes event handling (no new resource events)
  3. Stop schedule manager (no new cron triggers)
  4. Stop event handler (no new task generation)
  5. Stop queue service (no new task processing)

This order prevents new work from entering the system while allowing in-flight operations to complete gracefully where possible.

func (*Runtime) UpdateApp

func (r *Runtime) UpdateApp(repo registry.Remote, app App)

UpdateApp handles application creation and version changes from the Application controller.

Flow:

  1. NeedUpdate fast-path: skip if version and settings checksum are unchanged
  2. Store.Update: if version changed → new root context, enqueue full pipeline (Disable → Download → Install → Load); if only settings changed → nil context, trigger Reschedule so the scheduler re-runs Configure → Startup → Run
  3. CheckConstraints: validate Kubernetes/Deckhouse version requirements before enqueuing

Settings are applied lazily: the scheduler's schedulePackage reads pending settings from the Store via GetPendingSettings when the package is scheduled for startup.

func (*Runtime) UpdateModule

func (r *Runtime) UpdateModule(repo registry.Remote, module Module)

UpdateModule handles module creation and version changes from the module controller.

Flow mirrors UpdateApp: version changes enqueue the full pipeline (Disable → Download → Install → Load), settings-only changes trigger Reschedule to re-apply settings through the scheduler's schedule pipeline. See UpdateApp for detailed flow documentation.

func (*Runtime) ValidateSettings

func (r *Runtime) ValidateSettings(ctx context.Context, name string, settings addonutils.Values) (settingscheck.Result, error)

ValidateSettings checks settings against the package's OpenAPI schema. Returns valid if the package is not loaded yet (settings validated on load).

Directories

Path Synopsis
Package debug provides a Unix socket-based HTTP server and client for runtime debugging and inspection.
Package debug provides a Unix socket-based HTTP server and client for runtime debugging and inspection.
Package hookevent provides event handling for Kubernetes and schedule events.
Package hookevent provides event handling for Kubernetes and schedule events.
tasks
run

Jump to

Keyboard shortcuts

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