cri

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: EPL-2.0 Imports: 20 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 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 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 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 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) 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.

Jump to

Keyboard shortcuts

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