cri

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: EPL-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package cri provides a CRI client wrapper for the iofog engine. It connects to containerd's CRI plugin (same socket as main API) and exposes RunPodSandbox, CreateContainer, StartContainer, StopContainer, RemoveContainer, StopPodSandbox, RemovePodSandbox for proper CNI lifecycle management.

Index

Constants

View Source
const (
	AnnotationIofogNetwork = "iofog.network"
)
View Source
const (
	RuntimeHandlerCrun = "crun"
)

Runtime handler names — must match containerd config.

Variables

View Source
var ErrUnknownRuntimeClass = errors.New("unknown runtime class")

Functions

func ApplyOCIRlimits added in v1.1.0

func ApplyOCIRlimits(spec *specs.Spec, ms *models.Microservice)

ApplyOCIRlimits writes POSIX rlimits onto the OCI process spec.

func ContainerConfigFromMicroservice

func ContainerConfigFromMicroservice(ms *models.Microservice, hostname string, envVars []string, logPath string, hostsFilePath string, resolvFilePath string, sandboxID string, nodeUID string) (*runtimeapi.ContainerConfig, error)

ContainerConfigFromMicroservice builds a CRI ContainerConfig from a microservice. Includes image, env, args, mounts, and security context. sandboxID is stored in labels for teardown and recovery.

func GRPCStatusCode

func GRPCStatusCode(err error) int

GRPCStatusCode returns the gRPC status code when present.

func GetRuntimeHandler

func GetRuntimeHandler(ms *models.Microservice) (string, error)

GetRuntimeHandler returns the CRI runtime handler for the microservice.

func IsFailedPrecondition

func IsFailedPrecondition(err error) bool

IsFailedPrecondition reports whether err is a gRPC FailedPrecondition.

func IsPodSandboxNameReserved

func IsPodSandboxNameReserved(err error) bool

IsPodSandboxNameReserved reports whether err is a CRI name reservation conflict.

func ListLabeledPIDs added in v1.1.0

func ListLabeledPIDs(ctx context.Context, runtime WorkloadRuntime) ([]int, error)

ListLabeledPIDs returns host PIDs for labeled running workloads.

func ListLabeledResidueIDs added in v1.1.0

func ListLabeledResidueIDs(ctx context.Context, runtime WorkloadRuntime) ([]string, error)

ListLabeledResidueIDs returns labeled containers in any state and labeled pod sandboxes. An exited container is still a task containerd will try to restore.

func ListLabeledRunningIDs added in v1.1.0

func ListLabeledRunningIDs(ctx context.Context, runtime WorkloadRuntime) ([]string, error)

ListLabeledRunningIDs returns running CRI container IDs that carry an Edgelet microservice UID label (same selection as process-manager drain).

func ListLabeledTaskIDs added in v1.1.0

func ListLabeledTaskIDs(ctx context.Context, runtime WorkloadRuntime) ([]string, error)

ListLabeledTaskIDs returns labeled CRI containers that still have a runc task in the k8s.io namespace (created or running).

func LogPathsForCRI

func LogPathsForCRI(logDir, microserviceUUID string) (logDirectory, logPath string)

LogPathsForCRI returns the log directory and log path for the container. CRI expects log_directory on the pod sandbox and log_path on the container. Uses "0.log" (Kubernetes convention) — containerd CRI writes both stdout and stderr to this single file with CRI log format (timestamp stream flag message).

func ParseContainerPID added in v1.1.0

func ParseContainerPID(info map[string]string) int

ParseContainerPID reads a host PID from CRI verbose status info.

func PodSandboxConfigFromMicroservice

func PodSandboxConfigFromMicroservice(ms *models.Microservice, hostname, logDir, nodeUID string) *runtimeapi.PodSandboxConfig

PodSandboxConfigFromMicroservice builds a CRI PodSandboxConfig from a microservice. 1 microservice = 1 pod sandbox.

func PrepareHostTmpfs added in v1.1.0

func PrepareHostTmpfs(diskDir string, ms *models.Microservice) error

PrepareHostTmpfs mounts sized tmpfs directories used as CRI bind sources.

func ReleaseHostTmpfs added in v1.1.0

func ReleaseHostTmpfs(diskDir, msUUID string)

ReleaseHostTmpfs unmounts per-microservice tmpfs and shm host directories.

func ReleaseLabeledWorkloads added in v1.1.0

func ReleaseLabeledWorkloads(ctx context.Context, runtime WorkloadRuntime, stopTimeoutSec int64) error

ReleaseLabeledWorkloads deletes labeled containers and their pod sandboxes. StopContainer is skipped once a container has exited. A sandbox is removed only after every labeled container that referenced it has been deleted.

func ReservedPodSandboxID

func ReservedPodSandboxID(err error) string

ReservedPodSandboxID extracts the blocking sandbox id from a reservation error.

func ResolveCNINetwork

func ResolveCNINetwork(scope string, hostNetwork bool) string

func ResolveRuntimeHandler

func ResolveRuntimeHandler(ms *models.Microservice, runtimeClasses []*models.LocalRuntimeClass) (string, error)

ResolveRuntimeHandler resolves runtime handler using deterministic fallback and optional RuntimeClass mappings.

func WrapSandboxReleaseError

func WrapSandboxReleaseError(err error, sandboxID string) error

WrapSandboxReleaseError annotates release failures for observability.

Types

type CNINetworkSelection

type CNINetworkSelection struct {
	Scope       string
	NetworkName string
	HostNetwork bool
}

func SelectCNINetworkForMicroservice

func SelectCNINetworkForMicroservice(ms *models.Microservice) CNINetworkSelection

type Client

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

Client wraps the CRI RuntimeService gRPC client.

func NewClient

func NewClient(socketPath string) (*Client, error)

NewClient dials the containerd socket and creates a CRI RuntimeService client. The CRI plugin in containerd serves on the same gRPC server.

func (*Client) Close

func (c *Client) Close() error

Close closes the gRPC connection.

func (*Client) ContainerPID added in v1.1.0

func (c *Client) ContainerPID(ctx context.Context, containerID string) (int, error)

ContainerPID returns the host PID of a running CRI container.

func (*Client) ContainerStatus

func (c *Client) ContainerStatus(ctx context.Context, containerID string) (*runtimeapi.ContainerStatusResponse, error)

ContainerStatus returns the status of the container.

func (*Client) CreateContainer

func (c *Client) CreateContainer(ctx context.Context, podSandboxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error)

CreateContainer creates a new container in the given pod sandbox.

func (*Client) ListContainers

func (c *Client) ListContainers(ctx context.Context, filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error)

ListContainers lists containers matching the filter.

func (*Client) ListPodSandboxes

func (c *Client) ListPodSandboxes(ctx context.Context, filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error)

ListPodSandboxes lists pod sandboxes matching the filter.

func (*Client) PodSandboxStatus

func (c *Client) PodSandboxStatus(ctx context.Context, podSandboxID string) (*runtimeapi.PodSandboxStatusResponse, error)

PodSandboxStatus returns the status of the pod sandbox, including network IP.

func (*Client) RemoveContainer

func (c *Client) RemoveContainer(ctx context.Context, containerID string) error

RemoveContainer removes the container.

func (*Client) RemovePodSandbox

func (c *Client) RemovePodSandbox(ctx context.Context, podSandboxID string) error

RemovePodSandbox removes the pod sandbox.

func (*Client) RunPodSandbox

func (c *Client) RunPodSandbox(ctx context.Context, config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error)

RunPodSandbox creates and starts a pod-level sandbox. Returns the sandbox ID.

func (*Client) StartContainer

func (c *Client) StartContainer(ctx context.Context, containerID string) error

StartContainer starts the container.

func (*Client) StopContainer

func (c *Client) StopContainer(ctx context.Context, containerID string, timeout int64) error

StopContainer stops a running container with the given timeout (seconds).

func (*Client) StopPodSandbox

func (c *Client) StopPodSandbox(ctx context.Context, podSandboxID string) error

StopPodSandbox stops the pod sandbox and reclaims network resources.

type ContainerPIDLookup added in v1.1.0

type ContainerPIDLookup interface {
	ContainerPID(ctx context.Context, containerID string) (int, error)
}

ContainerPIDLookup resolves the host PID of a CRI container.

type WorkloadRuntime added in v1.1.0

type WorkloadRuntime interface {
	ListContainers(ctx context.Context, filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error)
	StopContainer(ctx context.Context, containerID string, timeout int64) error
}

WorkloadRuntime is the CRI surface used to list and stop labeled workloads.

Jump to

Keyboard shortcuts

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