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 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 LogPathsForCRI(logDir, microserviceUUID string) (logDirectory, logPath string)
- func PodSandboxConfigFromMicroservice(ms *models.Microservice, hostname, logDir, nodeUID string) *runtimeapi.PodSandboxConfig
- 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) 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
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 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 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 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 ¶
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) 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).