engine

package
v1.0.1-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: EPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CRIReasonContainerExited is reported by CRI when a dead container object
	// cannot be started and must be recreated.
	CRIReasonContainerExited = "CONTAINER_EXITED"
)
View Source
const SizeUnknown = int64(-1)

SizeUnknown marks a size or count field that could not be determined.

Variables

This section is empty.

Functions

func CountImageInUse

func CountImageInUse(names []string, digest string, counts map[string]int64) int64

CountImageInUse counts containers referencing an image by any of its known names or digest.

func ImageInUseFromSummary

func ImageInUseFromSummary(s imagetypes.Summary) int64

ImageInUseFromSummary returns the container usage count from a Docker/Moby summary.

func ImageSizesFromSummary

func ImageSizesFromSummary(s imagetypes.Summary) (contentSize, diskUsage int64, contentKnown bool)

ImageSizesFromSummary extracts content and disk usage from a Docker/Moby image summary. Content size requires manifest details (ImageList with Manifests=true, API >= 1.47).

func IsDigestOnlyImageRef

func IsDigestOnlyImageRef(ref string) bool

IsDigestOnlyImageRef reports whether a containerd/Docker image name is a digest alias.

func IsNonRestartableCRIReason

func IsNonRestartableCRIReason(reason string) bool

IsNonRestartableCRIReason reports whether the CRI reason indicates terminal non-restartable state.

func LookupImageInUseByID

func LookupImageInUseByID(imageID string, counts map[string]int64) int64

LookupImageInUseByID returns the container count for an image ID key.

func PickPrimaryRepoTag

func PickPrimaryRepoTag(repoTags []string) (repository, tag string)

PickPrimaryRepoTag chooses the best human-readable repository and tag from references.

func SplitRepoTag

func SplitRepoTag(ref string) (repository, tag string)

SplitRepoTag splits a reference into repository and tag at the last colon.

func SupportsInPlaceRestart

func SupportsInPlaceRestart(engineName string) bool

SupportsInPlaceRestart reports whether StopContainer leaves a container object that StartContainer can bring back without Remove+Create.

Types

type Container

type Container struct {
	ID     string
	Names  []string
	Image  string
	Status string
	State  string
	Labels map[string]string
}

Container is the engine-agnostic representation of a running or stopped container. It mirrors the fields ProcessManager actually uses, so docker.Container and any future engine-specific types can all be mapped to this common struct.

type ContainerEngine

type ContainerEngine interface {
	// Init initializes the engine. For docker/podman this dials the daemon socket;
	// for iofog it extracts embedded binaries and starts containerd in-process.
	Init(cfg EngineConfig) error

	// Container lifecycle
	GetContainer(microserviceUUID string) (*Container, error)
	// GetContainerByID returns a container by its engine-assigned ID. Used when the caller
	// already has the ID (e.g. from runtime_container_refs). Returns nil if not found.
	GetContainerByID(containerID string) (*Container, error)
	// GetContainerSandboxID returns the sandbox (pause) container ID for the given workload
	// container. Only meaningful for iofog/CRI; Docker/Podman return "".
	GetContainerSandboxID(containerID string) (string, error)
	GetRunningContainers() ([]Container, error)
	GetAllContainers() ([]Container, error)
	CreateContainer(ms *models.Microservice, hostname string) (string, error)
	StartContainer(containerID string) error
	StopContainer(containerID string) error
	KillContainer(containerID string) error
	RemoveContainer(containerID string, removeVolumes bool) error

	// Image management
	PullImage(imageRef string, registry *models.Registry, opts *PullImageOptions) error
	FindLocalImage(imageRef, registryURL string, fromCache bool) (bool, error)
	RemoveImage(imageRef string) error
	// PruneImages prunes images not referenced by running containers.
	// Deprecated: prefer the unified ListImages/DeleteImage path via the pruning manager.
	PruneImages() error
	// ListImages returns all locally available images.
	ListImages(ctx context.Context) ([]ImageInfo, error)
	// LoadImageFromPath imports an image archive from daemon-local filesystem path.
	LoadImageFromPath(ctx context.Context, archivePath string) ([]LoadedImage, error)
	// DeleteImage removes an image by its ID or name:tag reference.
	DeleteImage(ctx context.Context, nameOrID string) error
	// PruneDangling removes only untagged images not referenced by any container.
	PruneDangling(ctx context.Context) (*ImagePruneReport, error)
	// PruneContainers removes stopped/orphaned containers that are safe to delete.
	PruneContainers(ctx context.Context) (*ContainerPruneReport, error)
	// PruneVolumes removes unused/orphaned volume artifacts.
	PruneVolumes(ctx context.Context) (*VolumePruneReport, error)
	// RemoveNamedVolume deletes a named volume when it exists.
	RemoveNamedVolume(ctx context.Context, name string) error

	// Inspection / stats
	GetContainerStatus(containerID, microserviceUUID string) (*models.MicroserviceStatus, error)
	GetContainerStats(containerID string) (*ContainerStats, error)
	GetContainerIPAddress(containerID string) (string, error)
	GetContainerStartedAt(containerID string) (int64, error)
	InspectContainerRaw(containerID string) (map[string]any, error)

	// Log streaming
	TailContainerLogs(containerID, sessionID, microserviceUUID string, handler LogTailHandler, cfg *TailConfig) error

	// Configuration drift detection
	AreMicroserviceAndContainerEqual(containerID string, ms *models.Microservice, registry *models.Registry) bool

	// Network
	EnsureNetwork(name string) error

	// Exec session
	// CreateExecSession registers an exec spec for the given container using runtimeExecID
	// (edgelet engine) or returns a daemon-assigned id (docker/podman). The process is NOT
	// started yet; call StartExecSession to attach I/O and launch it.
	CreateExecSession(containerID string, runtimeExecID string, cmd []string) (string, error)
	// StartExecSession attaches the given stdin/stdout/stderr pipes to the exec process
	// identified by execID and starts it. Must be called after CreateExecSession.
	StartExecSession(execID string, stdin io.Reader, stdout, stderr io.Writer) error
	// GetExecSessionStatus reports whether the exec process identified by execID is still running.
	GetExecSessionStatus(execID string) (running bool, err error)
	// GetExecSessionExitCode returns exit status when the exec process has completed.
	GetExecSessionExitCode(execID string) (exitCode int, err error)
	// ResizeExecSession resizes an interactive TTY exec session.
	ResizeExecSession(execID string, cols, rows uint32) error
	// StopExecSession kills and deregisters the exec process. For iofog engine this is required
	// when the controller closes the WebSocket so the exec ID can be reused; Docker/Podman no-op.
	StopExecSession(execID string) error

	// Helpers used by ProcessManager
	GetContainerMicroserviceUUID(cont Container) string
	GetContainerName(cont Container) string

	// Close releases any resources held by the engine.
	Close() error
}

ContainerEngine is the abstraction over Docker, Podman, and the embedded iofog containerd engine. ProcessManager uses only this interface so that the underlying runtime is fully interchangeable via the containerEngine config field.

func NewLoggingEngine

func NewLoggingEngine(inner ContainerEngine, engineName string) ContainerEngine

NewLoggingEngine returns a ContainerEngine decorator that emits structured runtimeops events.

type ContainerPruneReport

type ContainerPruneReport struct {
	Deleted      []string
	DeletedCount int
}

ContainerPruneReport captures normalized container-prune results.

type ContainerStats

type ContainerStats struct {
	CPUUsage    float32
	MemoryUsage int64
}

ContainerStats holds per-container CPU and memory statistics.

type EngineConfig

type EngineConfig struct {
	SocketURL  string // e.g. "unix:///var/run/docker.sock"
	APIVersion string // Docker API version negotiation (empty = auto)
	LogDir     string // directory for container log files (iofog engine only)
}

EngineConfig holds the configuration passed to ContainerEngine.Init().

type ExecOrphanSweeper

type ExecOrphanSweeper interface {
	// SweepOrphanExecSessions stops and deletes tracked interactive exec processes for
	// containerID that are not listed in keepRuntimeExecIDs.
	SweepOrphanExecSessions(containerID string, keepRuntimeExecIDs map[string]struct{}) error
}

ExecOrphanSweeper is optionally implemented by engines that assign stable containerd exec ids.

type ImageInfo

type ImageInfo struct {
	ID               string    // content-addressable digest or engine-specific ID
	RepoTags         []string  // list of "name:tag" references; may be empty for dangling images
	ShortID          string    // short display id when available
	Repository       string    // repository part of primary tag
	Tag              string    // tag part of primary tag
	Digest           string    // primary digest when available
	CreatedAt        time.Time // image creation timestamp when available
	ContentSizeBytes int64     // distributable content size; SizeUnknown when unavailable
	DiskUsageBytes   int64     // content plus unpacked snapshot size on disk
	InUse            int64     // containers referencing this image; SizeUnknown when unavailable
	Engine           string    // engine that emitted this record (docker|podman|edgelet)
}

ImageInfo is the engine-agnostic representation of a local container image.

type ImagePruneReport

type ImagePruneReport struct {
	Deleted             []string
	DeletedCount        int
	SpaceReclaimedBytes int64
}

ImagePruneReport captures normalized dangling-prune results.

type LoadedImage

type LoadedImage struct {
	Name string
	ID   string
}

LoadedImage is a normalized result entry returned by load/import operations.

type LogTailHandler

type LogTailHandler interface {
	OnLogLine(sessionID, microserviceUUID string, line []byte, st StreamType)
	OnComplete(sessionID string)
	OnError(sessionID string, err error)
}

LogTailHandler is the callback interface used by TailContainerLogs.

type NonRestartableContainerError

type NonRestartableContainerError struct {
	ContainerID string
	Reason      string
	ExitCode    int32
	Message     string
}

NonRestartableContainerError signals that a runtime container object is in a terminal non-restartable state and must be removed/recreated.

func IsNonRestartableContainerError

func IsNonRestartableContainerError(err error) (*NonRestartableContainerError, bool)

IsNonRestartableContainerError returns the typed error if err wraps one.

func (*NonRestartableContainerError) Error

type PullImageOptions

type PullImageOptions struct {
	Out              io.Writer
	ProgressCallback func(float32)
	// Platform is an optional OCI platform selector (e.g. linux/amd64).
	// When set, engines should map it to their native pull option.
	Platform string
}

PullImageOptions allows optional progress reporting. If nil, no progress is reported.

type StreamType

type StreamType int

StreamType distinguishes stdout from stderr in log lines.

const (
	Stdout StreamType = iota
	Stderr
)

type TailConfig

type TailConfig struct {
	Follow bool
	Lines  int
	Since  string
	Until  string
	// Ctx, when set, cancels log tailing when done or when the session ends.
	Ctx context.Context
}

TailConfig configures how container logs are tailed.

type VolumePruneReport

type VolumePruneReport struct {
	Deleted             []string
	DeletedCount        int
	SpaceReclaimedBytes int64
}

VolumePruneReport captures normalized volume-prune results.

Directories

Path Synopsis
Package docker implements the ContainerEngine interface backed by the Docker daemon.
Package docker implements the ContainerEngine interface backed by the Docker daemon.
Package edgelet implements the ContainerEngine interface using the embedded containerd runtime.
Package edgelet implements the ContainerEngine interface using the embedded containerd runtime.
cri
Package cri provides a CRI client wrapper for the iofog engine.
Package cri provides a CRI client wrapper for the iofog engine.
Package podman implements the ContainerEngine interface backed by the Podman daemon.
Package podman implements the ContainerEngine interface backed by the Podman daemon.

Jump to

Keyboard shortcuts

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