Documentation
¶
Overview ¶
Package edgelet implements the ContainerEngine interface using the embedded containerd runtime. It communicates directly with the in-process containerd via the containerd Go client (not the Docker SDK), connecting to the private socket at /run/edgelet/containerd.sock.
Index ¶
- type Engine
- func (e *Engine) AreMicroserviceAndContainerEqual(containerID string, ms *models.Microservice, registry *models.Registry) bool
- func (e *Engine) Close() error
- func (e *Engine) CreateContainer(ms *models.Microservice, hostname string) (string, error)
- func (e *Engine) CreateExecSession(containerID string, runtimeExecID string, cmd []string) (string, error)
- func (e *Engine) DeleteImage(_ context.Context, nameOrID string) error
- func (e *Engine) EnsureNetwork(_ string) error
- func (e *Engine) ExecWithExitCode(containerID string, cmd []string, timeout time.Duration) (int, string, error)
- func (e *Engine) FindLocalImage(imageRef, registryURL string, fromCache bool) (bool, error)
- func (e *Engine) GetAllContainers() ([]engine.Container, error)
- func (e *Engine) GetContainer(microserviceUUID string) (*engine.Container, error)
- func (e *Engine) GetContainerByID(containerID string) (*engine.Container, error)
- func (e *Engine) GetContainerIPAddress(containerID string) (string, error)
- func (e *Engine) GetContainerMicroserviceUUID(cont engine.Container) string
- func (e *Engine) GetContainerName(cont engine.Container) string
- func (e *Engine) GetContainerSandboxID(containerID string) (string, error)
- func (e *Engine) GetContainerStartedAt(containerID string) (int64, error)
- func (e *Engine) GetContainerStats(containerID string) (*engine.ContainerStats, error)
- func (e *Engine) GetContainerStatus(containerID, _ string) (*models.MicroserviceStatus, error)
- func (e *Engine) GetExecSessionExitCode(execID string) (int, error)
- func (e *Engine) GetExecSessionStatus(execID string) (bool, error)
- func (e *Engine) GetRunningContainers() ([]engine.Container, error)
- func (e *Engine) Init(cfg engine.EngineConfig) error
- func (e *Engine) InspectContainerRaw(containerID string) (map[string]any, error)
- func (e *Engine) KillContainer(containerID string) error
- func (e *Engine) ListImages(_ context.Context) ([]engine.ImageInfo, error)
- func (e *Engine) LoadImageFromPath(_ context.Context, archivePath string) ([]engine.LoadedImage, error)
- func (e *Engine) PruneContainers(_ context.Context) (*engine.ContainerPruneReport, error)
- func (e *Engine) PruneDangling(_ context.Context) (*engine.ImagePruneReport, error)
- func (e *Engine) PruneImages() error
- func (e *Engine) PruneVolumes(_ context.Context) (*engine.VolumePruneReport, error)
- func (e *Engine) PullImage(imageRef string, registry *models.Registry, opts *engine.PullImageOptions) error
- func (e *Engine) RemoveContainer(containerID string, _ bool) error
- func (e *Engine) RemoveImage(imageRef string) error
- func (e *Engine) RemoveNamedVolume(_ context.Context, name string) error
- func (e *Engine) ResizeExecSession(execID string, cols, rows uint32) error
- func (e *Engine) SetContainerSpecCompare(allow bool)
- func (e *Engine) StartContainer(containerID string) error
- func (e *Engine) StartExecSession(execID string, stdin io.Reader, stdout, stderr io.Writer) error
- func (e *Engine) StopContainer(containerID string) error
- func (e *Engine) StopExecSession(execID string) error
- func (e *Engine) SweepOrphanExecSessions(containerID string, keepRuntimeExecIDs map[string]struct{}) error
- func (e *Engine) TailContainerLogs(containerID, sessionID, microserviceUUID string, handler engine.LogTailHandler, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine implements engine.ContainerEngine using the embedded containerd.
func New ¶
New returns an uninitialised iofog engine. logDir is the directory to write per-container log files to.
func (*Engine) AreMicroserviceAndContainerEqual ¶
func (e *Engine) AreMicroserviceAndContainerEqual(containerID string, ms *models.Microservice, registry *models.Registry) bool
AreMicroserviceAndContainerEqual returns true if the running container's configuration matches the desired microservice spec. It compares:
- Image name
- Environment (label digest when present; OCI spec only on the slow sweep)
- Port mappings (from persisted label vs desired) — skipped for host-network mode
- Network mode (host vs bridge)
func (*Engine) CreateContainer ¶
CreateContainer creates the container via CRI: RunPodSandbox (CNI managed by containerd) then CreateContainer. It does NOT start the container — that is deferred to StartContainer.
func (*Engine) CreateExecSession ¶
func (e *Engine) CreateExecSession(containerID string, runtimeExecID string, cmd []string) (string, error)
CreateExecSession validates the container, builds the exec process spec, and stores it as a pending exec. runtimeExecID must be unique per container (e.g. {cid[:12]}-exec-{session[:8]}). The process is NOT started yet — call StartExecSession to attach I/O and launch.
func (*Engine) DeleteImage ¶
DeleteImage removes an image from the iofog containerd namespace by name or digest.
func (*Engine) EnsureNetwork ¶
func (*Engine) ExecWithExitCode ¶
func (e *Engine) ExecWithExitCode(containerID string, cmd []string, timeout time.Duration) (int, string, error)
ExecWithExitCode runs a command in the container and returns its exit code and combined stdout/stderr. Stdin is closed and no terminal is allocated, matching a Docker healthcheck exec. The process runs as the container user. On timeout, kills the process and returns (-1, output so far, context.DeadlineExceeded).
func (*Engine) FindLocalImage ¶
func (*Engine) GetContainer ¶
func (*Engine) GetContainerByID ¶
func (*Engine) GetContainerIPAddress ¶
GetContainerIPAddress returns the container's IP from the in-memory state map, falling back to the persisted label for recovery after an agent restart.
func (*Engine) GetContainerMicroserviceUUID ¶
func (*Engine) GetContainerSandboxID ¶
func (*Engine) GetContainerStartedAt ¶
GetContainerStartedAt returns the Unix-millisecond timestamp when the container was last started, from the in-memory state or the persisted label.
func (*Engine) GetContainerStats ¶
func (e *Engine) GetContainerStats(containerID string) (*engine.ContainerStats, error)
GetContainerStats returns live CPU and memory usage for the container. It uses a two-sample approach for CPU percentage: the first call returns 0% CPU while storing the baseline; subsequent calls compute the delta.
func (*Engine) GetContainerStatus ¶
func (e *Engine) GetContainerStatus(containerID, _ string) (*models.MicroserviceStatus, error)
func (*Engine) GetExecSessionExitCode ¶
GetExecSessionExitCode reports the exit code for a completed exec process.
func (*Engine) GetExecSessionStatus ¶
GetExecSessionStatus reports whether the exec process for execID is still running.
func (*Engine) GetRunningContainers ¶
func (*Engine) Init ¶
func (e *Engine) Init(cfg engine.EngineConfig) error
Init connects to the embedded containerd socket, initializes CNI, and recovers per-container state from existing container labels.
func (*Engine) InspectContainerRaw ¶
func (*Engine) KillContainer ¶
KillContainer forcefully terminates the container task.
func (*Engine) ListImages ¶
ListImages returns all images available in the iofog containerd namespace.
func (*Engine) LoadImageFromPath ¶
func (*Engine) PruneContainers ¶
func (*Engine) PruneDangling ¶
PruneDangling removes images with no active containers referencing them and no tags, docker system prune --filter dangling=true semantics.
func (*Engine) PruneImages ¶
PruneImages deletes images that are not referenced by any existing container.
func (*Engine) PruneVolumes ¶
PruneVolumes removes rebuildable staging under volumes/microservices. Persistent VOLUME data under volumes/data and volumes/shared is not deleted.
func (*Engine) RemoveContainer ¶
RemoveContainer stops and removes the container via CRI, then tears down the pod sandbox. CRI handles CNI teardown in the correct order (StopPodSandbox triggers CNI DEL).
func (*Engine) RemoveImage ¶
func (*Engine) RemoveNamedVolume ¶
func (*Engine) ResizeExecSession ¶
ResizeExecSession resizes a running tty exec process.
func (*Engine) SetContainerSpecCompare ¶ added in v1.1.0
SetContainerSpecCompare allows an OCI spec read on the next env compare when the apply label has no environment digest.
func (*Engine) StartContainer ¶
StartContainer starts the container via CRI. CRI manages logs; we only record start time.
func (*Engine) StartExecSession ¶
StartExecSession looks up the pending exec registered by CreateExecSession, wires stdin/stdout/stderr pipes to the container, and starts the process. Blocks until the process exits so the caller only fires OnComplete() when the shell actually ends.
func (*Engine) StopContainer ¶
StopContainer stops the container via CRI (SIGTERM, then SIGKILL after timeout).
func (*Engine) StopExecSession ¶
StopExecSession kills the running exec process, waits for exit, and deregisters it from containerd.
func (*Engine) SweepOrphanExecSessions ¶
func (e *Engine) SweepOrphanExecSessions(containerID string, keepRuntimeExecIDs map[string]struct{}) error
SweepOrphanExecSessions stops interactive exec processes tracked for containerID that are not in keepRuntimeExecIDs.
func (*Engine) TailContainerLogs ¶
func (e *Engine) TailContainerLogs(containerID, sessionID, microserviceUUID string, handler engine.LogTailHandler, cfg *engine.TailConfig) error
TailContainerLogs streams log lines from the CRI container log file. Containerd CRI writes both stdout and stderr to a single file (0.log) with CRI format: "timestamp stream flag message". We parse and dispatch by stream. Falls back to stdout.log/stderr.log if 0.log is absent.