kernel

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package kernel manages guest kernels: their definitions, and their binaries on the host. A kernel is the default one this binary carries or one a client imports, checked against its SHA-256.

Index

Constants

View Source
const (
	ArchitectureX86_64  = "x86_64"
	ArchitectureAArch64 = "aarch64"
)

The CPU architectures a kernel may be built for, as uname -m names them.

View Source
const DefaultName = "default"

DefaultName is the name of the default kernel, which the daemon defines itself and an instance boots when it names no kernel.

View Source
const MaxImportBytes = 512 << 20

MaxImportBytes is the largest kernel a client can import.

Variables

This section is empty.

Functions

func Extract added in v0.4.0

func Extract(dstPath string, version Version) (string, error)

Extract writes the default kernel of version, decompressed, to dstPath, unless a file is already there, and returns dstPath. The kernel is written beside dstPath and renamed into place, so dstPath is never a partial kernel.

func MetricDescriptions added in v0.4.0

func MetricDescriptions() []metric.Description

MetricDescriptions returns the descriptions of every metric the kernel manager serves, for the reference.

Types

type Config

type Config struct {
	// DataDir holds the kernels, under kernels/<id>; it is required.
	DataDir string
	// Store keeps the kernel definitions. It is required.
	Store Store
	// Events records what happens to kernels. Nil records nothing.
	Events Recorder
	// Logger defaults to slog.Default.
	Logger *slog.Logger
}

Config configures a Manager.

type Kernel added in v0.4.0

type Kernel struct {
	ID           string    `yaml:"id"`
	Name         string    `yaml:"name"`
	Architecture string    `yaml:"arch"`
	SHA256       string    `yaml:"sha256"`
	CreatedAt    time.Time `yaml:"created_at"`
	UpdatedAt    time.Time `yaml:"updated_at"`
}

Kernel is a guest kernel image an instance can boot from, kept on the host.

func Default added in v0.4.0

func Default() Kernel

Default returns the definition of the default kernel this binary carries, without an ID or times.

func (Kernel) Validate added in v0.4.0

func (k Kernel) Validate() error

Validate returns an invalid argument error unless the kernel has a valid name and an architecture Dicer knows, and its checksum, if it has one, is a hex-encoded SHA-256 digest.

type Manager

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

Manager imports and deletes kernels: their definitions, kept in a Store, and their binaries on the host. It is safe for concurrent use.

func NewManager

func NewManager(cfg Config) (*Manager, error)

NewManager returns a Manager for the kernels under cfg.DataDir.

func (*Manager) Collect added in v0.4.0

func (m *Manager) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector: the kernels defined, and what they take on disk, as they are now.

func (*Manager) Delete

func (m *Manager) Delete(nameOrID string) error

Delete removes a kernel's definition and its binary, refusing the default kernel and one an instance or snapshot boots.

func (*Manager) Describe added in v0.4.0

func (m *Manager) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

func (*Manager) DiskBytes added in v0.4.0

func (m *Manager) DiskBytes(k Kernel) int64

DiskBytes returns the size of a kernel's binary on local disk, or 0 if it is not there.

func (*Manager) EnsureDefault added in v0.4.0

func (m *Manager) EnsureDefault() error

EnsureDefault puts the default kernel this binary carries on the host, and defines it once it is there. It extracts it again if its copy on the host is missing or damaged, and in place of the one an older version of Dicer carried.

func (*Manager) Import added in v0.4.0

func (m *Manager) Import(name, architecture, sha256 string, r io.Reader) (Kernel, error)

Import keeps the kernel a client sends, read from r, and defines it. It refuses an invalid kernel, the default kernel's name and a name already taken, and checks the kernel against sha256 if that is set. The SHA-256 is kept whether or not it is set, so that the kernel is checked each time an instance boots it. Nothing is kept if it fails.

func (*Manager) Kernel added in v0.4.0

func (m *Manager) Kernel(nameOrID string) (Kernel, error)

Kernel returns a kernel by name or ID.

func (*Manager) Kernels added in v0.4.0

func (m *Manager) Kernels() []Kernel

Kernels returns every kernel, sorted by name.

func (*Manager) Path

func (m *Manager) Path(k Kernel) (string, error)

Path returns the local path to a kernel's binary. It returns an errdefs.ErrInvalidState error if the binary is missing from the host, or does not match the kernel's checksum.

type Recorder added in v0.4.0

type Recorder interface {
	Record(e event.Event)
}

Recorder records what happens to kernels. It is declared here, and satisfied by internal/event, so that this package reports what it does without knowing who listens.

type Store added in v0.4.0

type Store interface {
	CreateKernel(k Kernel) error
	Kernel(nameOrID string) (Kernel, error)
	Kernels() []Kernel
	UpdateKernel(k Kernel) error
	// DeleteKernel refuses a kernel an instance or snapshot boots.
	DeleteKernel(nameOrID string) error
}

Store keeps the kernel definitions.

type Version added in v0.4.0

type Version string

Version identifies a release of Dicer's kernel, https://github.com/konradasb/dicer-kernel.

const DefaultVersion Version = "v6.18.53-1"

DefaultVersion is the release of Dicer's kernel this version of Dicer carries as the default kernel. A new release of Dicer may carry a newer one.

Jump to

Keyboard shortcuts

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