runtime

package
v1.75.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 55 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConditionReasonValidationFailed status.ConditionReason = "ValidationFailed"
	ConditionReasonApplySettings    status.ConditionReason = "ApplySettings"
	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.

It delegates package state to lifecycle.Store (the single source of truth), task execution to queue.Service (one queue per package), and cluster coordination to the scheduler, NELM, and hook event systems.

All package mutations flow through lifecycle.Store callbacks, ensuring atomicity between state changes and task enqueueing.

func New

func New(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) 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) 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) 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 updates (version changes and settings changes). Version changes and settings changes are handled independently with separate contexts.

func (*Runtime) UpdateModule

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

UpdateModule handles module updates (version changes and settings changes). On version change: validates requirements, then queues download → install → load. On settings change: queues apply-settings → run.

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