runner

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const ContainerIDMinimumParts = 2

ContainerIDMinimumParts is the minimum number of parts needed in a container ID to extract the network name. Container ID format: realm-space-cell-container We need at least realm and space to form the network name: realm-space.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exec

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

func (*Exec) BootstrapCNI

func (r *Exec) BootstrapCNI(cfgDir, cacheDir, binDir string) (cni.BootstrapReport, error)

func (*Exec) Close

func (r *Exec) Close() error

func (*Exec) CreateCell

func (r *Exec) CreateCell(cell intmodel.Cell) (intmodel.Cell, error)

func (*Exec) CreateContainer

func (r *Exec) CreateContainer(cell intmodel.Cell, container intmodel.ContainerSpec) (intmodel.Cell, error)

CreateContainer creates a container in an existing cell by merging the container spec into the cell's containers list. The cell must already exist.

Inheritance of spec.defaults.container from the parent Space happens in ensureCellContainers, which is the single choke point every creation and update path traverses — so the post-merge (effective) configuration is what gets persisted and what `kuke get container -o yaml` displays.

func (*Exec) CreateRealm

func (r *Exec) CreateRealm(realm intmodel.Realm) (intmodel.Realm, error)

func (*Exec) CreateSpace

func (r *Exec) CreateSpace(space intmodel.Space) (intmodel.Space, error)

func (*Exec) CreateStack

func (r *Exec) CreateStack(stack intmodel.Stack) (intmodel.Stack, error)

func (*Exec) DeleteCell

func (r *Exec) DeleteCell(cell intmodel.Cell) error

func (*Exec) DeleteContainer

func (r *Exec) DeleteContainer(cell intmodel.Cell, containerID string) error

DeleteContainer stops and deletes a specific container in a cell from containerd.

func (*Exec) DeleteRealm

func (r *Exec) DeleteRealm(realm intmodel.Realm) error

func (*Exec) DeleteSpace

func (r *Exec) DeleteSpace(space intmodel.Space) error

func (*Exec) DeleteStack

func (r *Exec) DeleteStack(stack intmodel.Stack) error

func (*Exec) EnsureCell

func (r *Exec) EnsureCell(cell intmodel.Cell) (intmodel.Cell, error)

EnsureCell ensures that all required resources for a cell exist. It ensures the cgroup exists, ensures cell containers exist, and updates metadata.

func (*Exec) EnsureContainer

func (r *Exec) EnsureContainer(cell intmodel.Cell, container intmodel.ContainerSpec) (intmodel.Cell, error)

EnsureContainer ensures that a container spec is merged into an existing cell. It merges the container into the cell's Spec.Containers list (avoiding duplicates by ID), ensures containers exist, and updates metadata.

func (*Exec) EnsureKukeonRootCgroup

func (r *Exec) EnsureKukeonRootCgroup() (bool, bool, error)

EnsureKukeonRootCgroup ensures the kukeon root cgroup (/kukeon) exists at the cgroup hierarchy root. This is the base under which all realms are created. It bypasses buildCgroupPath (which would otherwise nest /kukeon under itself) and creates the cgroup directly at the discovered mountpoint. Returns (existsPre, created, err).

func (*Exec) EnsureRealm

func (r *Exec) EnsureRealm(realm intmodel.Realm) (intmodel.Realm, error)

EnsureRealm ensures that all required resources for a realm exist and reconciles its state. It ensures the containerd namespace and cgroup exist, and transitions the realm from "Creating" to "Ready" state if all resources are present.

func (*Exec) EnsureSpace

func (r *Exec) EnsureSpace(space intmodel.Space) (intmodel.Space, error)

EnsureSpace ensures that all required resources for a space exist. It ensures the CNI config and cgroup exist.

func (*Exec) EnsureStack

func (r *Exec) EnsureStack(stack intmodel.Stack) (intmodel.Stack, error)

EnsureStack ensures that all required resources for a stack exist. It ensures the cgroup exists.

func (*Exec) ExistsCellRootContainer

func (r *Exec) ExistsCellRootContainer(cell intmodel.Cell) (bool, error)

func (*Exec) ExistsCgroup

func (r *Exec) ExistsCgroup(doc any) (bool, error)

func (*Exec) ExistsContainer

func (r *Exec) ExistsContainer(containerdID string) (bool, error)

ExistsContainer checks if a container exists in containerd by its containerd ID. It ensures the client is connected before making the call.

func (*Exec) ExistsRealmContainerdNamespace

func (r *Exec) ExistsRealmContainerdNamespace(namespace string) (bool, error)

func (*Exec) ExistsSpaceCNIConfig

func (r *Exec) ExistsSpaceCNIConfig(space intmodel.Space) (bool, error)

ExistsSpaceCNIConfig checks if the CNI config for a space exists. It returns a bool and an error. The bool is true if the CNI config exists, false otherwise. The error is returned if the space name is required, the realm name is required, the CNI config does not exist, or the CNI config creation fails.

func (*Exec) ExtractContainersFromCells

func (r *Exec) ExtractContainersFromCells(cells []intmodel.Cell) []intmodel.ContainerSpec

ExtractContainersFromCells extracts all containers from a list of cells. It returns both root containers and regular containers as internal ContainerSpec types.

func (*Exec) GetCell

func (r *Exec) GetCell(cell intmodel.Cell) (intmodel.Cell, error)

func (*Exec) GetContainerState

func (r *Exec) GetContainerState(cell intmodel.Cell, containerID string) (intmodel.ContainerState, error)

GetContainerState queries containerd for the actual task status of a container and converts it to the internal ContainerState.

func (*Exec) GetRealm

func (r *Exec) GetRealm(realm intmodel.Realm) (intmodel.Realm, error)

func (*Exec) GetSpace

func (r *Exec) GetSpace(space intmodel.Space) (intmodel.Space, error)

func (*Exec) GetStack

func (r *Exec) GetStack(stack intmodel.Stack) (intmodel.Stack, error)

func (*Exec) KillCell

func (r *Exec) KillCell(cell intmodel.Cell) (intmodel.Cell, error)

KillCell immediately force-kills all containers in a cell (workload containers first, then root container). It detaches the root container from the CNI network before killing it.

func (*Exec) KillContainer

func (r *Exec) KillContainer(cell intmodel.Cell, containerID string) error

KillContainer immediately force-kills a specific container in a cell.

func (*Exec) ListCells

func (r *Exec) ListCells(realmName, spaceName, stackName string) ([]intmodel.Cell, error)

func (*Exec) ListContainers

func (r *Exec) ListContainers(realmName, spaceName, stackName, cellName string) ([]intmodel.ContainerSpec, error)

func (*Exec) ListRealms

func (r *Exec) ListRealms() ([]intmodel.Realm, error)

func (*Exec) ListSpaces

func (r *Exec) ListSpaces(realmName string) ([]intmodel.Space, error)

func (*Exec) ListStacks

func (r *Exec) ListStacks(realmName, spaceName string) ([]intmodel.Stack, error)

func (*Exec) PopulateAndPersistCellContainerStatuses

func (r *Exec) PopulateAndPersistCellContainerStatuses(cell *intmodel.Cell) error

PopulateAndPersistCellContainerStatuses populates container statuses from containerd and persists them by updating cell metadata. This should be used when the cell status changes need to be persisted to disk.

func (*Exec) PurgeCell

func (r *Exec) PurgeCell(cell intmodel.Cell) error

PurgeCell performs comprehensive cleanup of a cell, including CNI resources and orphaned containers.

func (*Exec) PurgeContainer

func (r *Exec) PurgeContainer(realm intmodel.Realm, containerID string) error

PurgeContainer performs comprehensive cleanup of a container, including CNI resources.

func (*Exec) PurgeRealm

func (r *Exec) PurgeRealm(realm intmodel.Realm) error

PurgeRealm performs comprehensive cleanup of a realm, including all child resources, CNI resources, and orphaned containers.

func (*Exec) PurgeSpace

func (r *Exec) PurgeSpace(space intmodel.Space) error

PurgeSpace performs comprehensive cleanup of a space, including CNI resources and orphaned containers.

func (*Exec) PurgeStack

func (r *Exec) PurgeStack(stack intmodel.Stack) error

PurgeStack performs comprehensive cleanup of a stack, including CNI resources and orphaned containers.

func (*Exec) RecreateCell

func (r *Exec) RecreateCell(desired intmodel.Cell) (intmodel.Cell, error)

RecreateCell stops all containers in the cell, deletes them, and recreates the cell with the new root container spec. This is used when the root container spec changes (image, command, or args).

func (*Exec) RefreshCell

func (r *Exec) RefreshCell(cell intmodel.Cell) (intmodel.Cell, int, error)

RefreshCell refreshes the status of a cell and its containers. Returns the updated cell, number of containers updated, and any error.

func (*Exec) RefreshRealm

func (r *Exec) RefreshRealm(realm intmodel.Realm) (intmodel.Realm, bool, error)

RefreshRealm refreshes the status of a realm by checking cgroup and containerd namespace. Returns the updated realm, whether it was updated, and any error.

func (*Exec) RefreshSpace

func (r *Exec) RefreshSpace(space intmodel.Space) (intmodel.Space, bool, error)

RefreshSpace refreshes the status of a space by checking CNI config. Returns the updated space, whether it was updated, and any error.

func (*Exec) RefreshStack

func (r *Exec) RefreshStack(stack intmodel.Stack) (intmodel.Stack, bool, error)

RefreshStack refreshes the status of a stack by checking cgroup. Returns the updated stack, whether it was updated, and any error.

func (*Exec) StartCell

func (r *Exec) StartCell(cell intmodel.Cell) (intmodel.Cell, error)

StartCell starts the root container and all containers defined in the CellDoc. The root container is started first, then all containers in doc.Spec.Containers are started.

func (*Exec) StartContainer

func (r *Exec) StartContainer(cell intmodel.Cell, containerID string) (intmodel.Cell, error)

StartContainer starts a specific container in a cell.

func (*Exec) StopCell

func (r *Exec) StopCell(cell intmodel.Cell) (intmodel.Cell, error)

StopCell stops all containers in the cell (workload containers first, then root container). It detaches the root container from the CNI network before stopping it, ensuring the network namespace is still valid. If detachment fails or the container is already stopped, fallback cleanup removes IPAM allocations directly.

func (*Exec) StopContainer

func (r *Exec) StopContainer(cell intmodel.Cell, containerID string) error

StopContainer stops a specific container in a cell.

func (*Exec) UpdateCell

func (r *Exec) UpdateCell(desired intmodel.Cell) (intmodel.Cell, error)

UpdateCell updates an existing cell with new metadata and container changes. It handles: - Metadata updates (labels) - Container additions (containers in desired but not in actual) - Container updates (containers in both, with spec changes) - Container removals (orphans: containers in actual but not in desired)

Breaking changes (root container spec changes, parent associations) should be rejected before calling this method.

func (*Exec) UpdateCellMetadata

func (r *Exec) UpdateCellMetadata(cell intmodel.Cell) error

func (*Exec) UpdateContainer

func (r *Exec) UpdateContainer(cell intmodel.Cell, desiredContainer intmodel.ContainerSpec) (intmodel.Cell, error)

UpdateContainer updates an existing container within a cell. If the container spec has breaking changes (image, command, args), it will stop, delete, and recreate the container. Otherwise, it updates the container spec in metadata.

func (*Exec) UpdateRealm

func (r *Exec) UpdateRealm(desired intmodel.Realm) (intmodel.Realm, error)

UpdateRealm updates an existing realm with new metadata and compatible spec fields. It only updates fields that are backward-compatible (labels, registry credentials). Breaking changes (name, namespace) should be rejected before calling this method.

func (*Exec) UpdateRealmMetadata

func (r *Exec) UpdateRealmMetadata(realm intmodel.Realm) error

func (*Exec) UpdateSpace

func (r *Exec) UpdateSpace(desired intmodel.Space) (intmodel.Space, error)

UpdateSpace updates an existing space with new metadata and compatible spec fields. It only updates fields that are backward-compatible (labels). Breaking changes (name, realm association, CNI config path) should be rejected before calling this method.

func (*Exec) UpdateSpaceMetadata

func (r *Exec) UpdateSpaceMetadata(space intmodel.Space) error

func (*Exec) UpdateStack

func (r *Exec) UpdateStack(desired intmodel.Stack) (intmodel.Stack, error)

UpdateStack updates an existing stack with new metadata and compatible spec fields. It only updates fields that are backward-compatible (labels, ID). Breaking changes (name, realm/space association) should be rejected before calling this method.

func (*Exec) UpdateStackMetadata

func (r *Exec) UpdateStackMetadata(stack intmodel.Stack) error

type Options

type Options struct {
	ContainerdSocket string
	RunPath          string
	CniConf          cni.Conf
	// ForceRegenerateCNI forces ensureSpaceCNIConfig to rewrite an existing conflist
	// even when one is present and its bridge name matches SafeBridgeName. Set by
	// `kuke init --force-regenerate-cni` as an operator escape hatch.
	ForceRegenerateCNI bool
}

type Runner

type Runner interface {
	BootstrapCNI(cfgDir, cacheDir, binDir string) (cni.BootstrapReport, error)
	EnsureKukeonRootCgroup() (existsPre bool, created bool, err error)

	GetRealm(realm intmodel.Realm) (intmodel.Realm, error)
	ListRealms() ([]intmodel.Realm, error)
	CreateRealm(realm intmodel.Realm) (intmodel.Realm, error)
	EnsureRealm(realm intmodel.Realm) (intmodel.Realm, error)
	UpdateRealm(realm intmodel.Realm) (intmodel.Realm, error)
	ExistsRealmContainerdNamespace(namespace string) (bool, error)
	DeleteRealm(realm intmodel.Realm) error

	GetSpace(space intmodel.Space) (intmodel.Space, error)
	ListSpaces(realmName string) ([]intmodel.Space, error)
	CreateSpace(space intmodel.Space) (intmodel.Space, error)
	EnsureSpace(space intmodel.Space) (intmodel.Space, error)
	UpdateSpace(space intmodel.Space) (intmodel.Space, error)
	ExistsSpaceCNIConfig(space intmodel.Space) (bool, error)
	DeleteSpace(space intmodel.Space) error

	GetCell(cell intmodel.Cell) (intmodel.Cell, error)
	ListCells(realmName, spaceName, stackName string) ([]intmodel.Cell, error)
	ListContainers(realmName, spaceName, stackName, cellName string) ([]intmodel.ContainerSpec, error)
	CreateCell(cell intmodel.Cell) (intmodel.Cell, error)
	EnsureCell(cell intmodel.Cell) (intmodel.Cell, error)
	StartCell(cell intmodel.Cell) (intmodel.Cell, error)
	StopCell(cell intmodel.Cell) (intmodel.Cell, error)
	StartContainer(cell intmodel.Cell, containerID string) (intmodel.Cell, error)
	StopContainer(cell intmodel.Cell, containerID string) error
	KillCell(cell intmodel.Cell) (intmodel.Cell, error)
	KillContainer(cell intmodel.Cell, containerID string) error
	DeleteContainer(cell intmodel.Cell, containerID string) error
	CreateContainer(cell intmodel.Cell, container intmodel.ContainerSpec) (intmodel.Cell, error)
	EnsureContainer(cell intmodel.Cell, container intmodel.ContainerSpec) (intmodel.Cell, error)
	UpdateCell(cell intmodel.Cell) (intmodel.Cell, error)
	RecreateCell(cell intmodel.Cell) (intmodel.Cell, error)
	UpdateContainer(cell intmodel.Cell, container intmodel.ContainerSpec) (intmodel.Cell, error)
	UpdateCellMetadata(cell intmodel.Cell) error
	ExistsCellRootContainer(cell intmodel.Cell) (bool, error)
	DeleteCell(cell intmodel.Cell) error

	GetStack(stack intmodel.Stack) (intmodel.Stack, error)
	ListStacks(realmName, spaceName string) ([]intmodel.Stack, error)
	CreateStack(stack intmodel.Stack) (intmodel.Stack, error)
	EnsureStack(stack intmodel.Stack) (intmodel.Stack, error)
	UpdateStack(stack intmodel.Stack) (intmodel.Stack, error)
	DeleteStack(stack intmodel.Stack) error

	ExistsCgroup(doc any) (bool, error)

	PurgeRealm(realm intmodel.Realm) error
	PurgeSpace(space intmodel.Space) error
	PurgeStack(stack intmodel.Stack) error
	PurgeCell(cell intmodel.Cell) error
	PurgeContainer(realm intmodel.Realm, containerID string) error

	RefreshRealm(realm intmodel.Realm) (intmodel.Realm, bool, error)
	RefreshSpace(space intmodel.Space) (intmodel.Space, bool, error)
	RefreshStack(stack intmodel.Stack) (intmodel.Stack, bool, error)
	RefreshCell(cell intmodel.Cell) (intmodel.Cell, int, error)

	GetContainerState(cell intmodel.Cell, containerID string) (intmodel.ContainerState, error)

	Close() error
}

func NewRunner

func NewRunner(ctx context.Context, logger *slog.Logger, opts Options) Runner

Jump to

Keyboard shortcuts

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