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
- Variables
- func ApplyOCIRlimits(spec *specs.Spec, ms *models.Microservice)
- func ContainerConfigFromMicroservice(ms *models.Microservice, hostname string, envVars []string, logPath string, ...) (*runtimeapi.ContainerConfig, error)
- func GRPCStatusCode(err error) int
- func GetRuntimeHandler(ms *models.Microservice) (string, error)
- func IsFailedPrecondition(err error) bool
- func IsPodSandboxNameReserved(err error) bool
- func ListLabeledPIDs(ctx context.Context, runtime WorkloadRuntime) ([]int, error)
- func ListLabeledResidueIDs(ctx context.Context, runtime WorkloadRuntime) ([]string, error)
- func ListLabeledRunningIDs(ctx context.Context, runtime WorkloadRuntime) ([]string, error)
- func ListLabeledTaskIDs(ctx context.Context, runtime WorkloadRuntime) ([]string, error)
- func LogPathsForCRI(logDir, microserviceUUID string) (logDirectory, logPath string)
- func ParseContainerPID(info map[string]string) int
- func PodSandboxConfigFromMicroservice(ms *models.Microservice, hostname, logDir, nodeUID string) *runtimeapi.PodSandboxConfig
- func PrepareHostTmpfs(diskDir string, ms *models.Microservice) error
- func ReleaseHostTmpfs(diskDir, msUUID string)
- func ReleaseLabeledWorkloads(ctx context.Context, runtime WorkloadRuntime, stopTimeoutSec int64) error
- func ReservedPodSandboxID(err error) string
- func ResolveCNINetwork(scope string, hostNetwork bool) string
- func ResolveRuntimeHandler(ms *models.Microservice, runtimeClasses []*models.LocalRuntimeClass) (string, error)
- func WrapSandboxReleaseError(err error, sandboxID string) error
- type CNINetworkSelection
- type Client
- func (c *Client) Close() error
- func (c *Client) ContainerPID(ctx context.Context, containerID string) (int, error)
- func (c *Client) ContainerStatus(ctx context.Context, containerID string) (*runtimeapi.ContainerStatusResponse, error)
- func (c *Client) CreateContainer(ctx context.Context, podSandboxID string, config *runtimeapi.ContainerConfig, ...) (string, error)
- func (c *Client) ListContainers(ctx context.Context, filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error)
- func (c *Client) ListPodSandboxes(ctx context.Context, filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error)
- func (c *Client) PodSandboxStatus(ctx context.Context, podSandboxID string) (*runtimeapi.PodSandboxStatusResponse, error)
- func (c *Client) RemoveContainer(ctx context.Context, containerID string) error
- func (c *Client) RemovePodSandbox(ctx context.Context, podSandboxID string) error
- func (c *Client) RunPodSandbox(ctx context.Context, config *runtimeapi.PodSandboxConfig, ...) (string, error)
- func (c *Client) StartContainer(ctx context.Context, containerID string) error
- func (c *Client) StopContainer(ctx context.Context, containerID string, timeout int64) error
- func (c *Client) StopPodSandbox(ctx context.Context, podSandboxID string) error
- type ContainerPIDLookup
- type WorkloadRuntime
Constants ¶
const (
AnnotationIofogNetwork = "iofog.network"
)
const (
RuntimeHandlerCrun = "crun"
)
Runtime handler names — must match containerd config.
Variables ¶
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 ¶
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 ¶
IsFailedPrecondition reports whether err is a gRPC FailedPrecondition.
func IsPodSandboxNameReserved ¶
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 ¶
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
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 ¶
ReservedPodSandboxID extracts the blocking sandbox id from a reservation error.
func ResolveCNINetwork ¶
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 ¶
WrapSandboxReleaseError annotates release failures for observability.
Types ¶
type CNINetworkSelection ¶
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 ¶
NewClient dials the containerd socket and creates a CRI RuntimeService client. The CRI plugin in containerd serves on the same gRPC server.
func (*Client) ContainerPID ¶ added in v1.1.0
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 ¶
RemoveContainer removes the container.
func (*Client) RemovePodSandbox ¶
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 ¶
StartContainer starts the container.
func (*Client) StopContainer ¶
StopContainer stops a running container with the given timeout (seconds).
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.