kern

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package kern provides the Krewire Kernel — the imperative control plane that boots, supervises, and executes workloads. It is stdlib plus libs/core only; framework and krewire provide Module implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor interface {
	Execute(ctx context.Context, workload core.Workload) core.ExitCode
}

Executor dispatches a workload.

type Kernel

type Kernel struct {
	Project    core.Project
	Registry   *Registry
	Supervisor *Supervisor
	Executor   Executor
	// contains filtered or unexported fields
}

Kernel is the central executor for the Krewire ecosystem.

func New

func New(project core.Project) (*Kernel, error)

New creates a Kernel for the given project, validating it.

func (*Kernel) Boot

func (k *Kernel) Boot(ctx context.Context) error

Boot initializes all registered modules in dependency order.

func (*Kernel) Execute

func (k *Kernel) Execute(ctx context.Context, workload core.Workload) core.ExitCode

Execute dispatches the workload via the registered handler.

func (*Kernel) RegisterHandler

func (k *Kernel) RegisterHandler(kind core.Kind, fn func(context.Context, core.Workload) core.ExitCode)

RegisterHandler registers a workload handler for the given kind.

func (*Kernel) Shutdown

func (k *Kernel) Shutdown(ctx context.Context) error

Shutdown gracefully stops supervised modules.

func (*Kernel) Use

func (k *Kernel) Use(modules ...Module) *Kernel

Use registers modules and returns the receiver for chaining.

type Module

type Module interface {
	Name() string
	Init(*Kernel) error
}

Module is a kernel module. Modules are registered by name and initialized against the kernel. Optionally, a module may implement DependsOn() []string to declare ordering.

type Registry

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

Registry holds modules by name.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty Registry.

func (*Registry) Ordered

func (r *Registry) Ordered() []Module

Ordered returns modules topologically sorted by DependsOn() if implemented, otherwise in registration order (sorted by name for determinism).

func (*Registry) Register

func (r *Registry) Register(m Module) error

Register adds a module. Duplicate names return UsageError.

func (*Registry) Resolve

func (r *Registry) Resolve(name string) (Module, bool)

Resolve returns the module with the given name.

type Startable

type Startable interface {
	Start(context.Context) error
	Stop(context.Context) error
}

Startable is implemented by long-running modules.

type Supervisor

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

Supervisor manages long-running modules.

func NewSupervisor

func NewSupervisor() *Supervisor

NewSupervisor creates a Supervisor with a 10s shutdown timeout.

func (*Supervisor) Add

func (s *Supervisor) Add(m Startable)

Add registers a startable module for supervision.

func (*Supervisor) Health

func (s *Supervisor) Health() map[string]error

Health returns a snapshot of module health.

func (*Supervisor) OnReload

func (s *Supervisor) OnReload(fn func())

OnReload sets the hot-reload hook.

func (*Supervisor) Reload

func (s *Supervisor) Reload()

Reload triggers the hot-reload hook if set.

func (*Supervisor) Start

func (s *Supervisor) Start(ctx context.Context) error

Start starts all registered modules.

func (*Supervisor) Stop

func (s *Supervisor) Stop(ctx context.Context) error

Stop stops all modules with the configured timeout.

func (*Supervisor) WithShutdownTimeout

func (s *Supervisor) WithShutdownTimeout(d time.Duration) *Supervisor

WithShutdownTimeout sets the timeout used by Stop.

Jump to

Keyboard shortcuts

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