containers

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SchemaVersion     = "redeven.capability.container_resources.v1"
	CapabilityID      = "redeven.capability.container_resources"
	CapabilityVersion = "1.0.0"
)

Variables

View Source
var (
	ErrEngineUnavailable           = errors.New("container engine is unavailable")
	ErrInvalidEngine               = errors.New("container engine is invalid")
	ErrInvalidMethod               = errors.New("container method is invalid")
	ErrLogStreamBackpressure       = errors.New("logs stream sink backpressure")
	ErrLogsFollowUnsupported       = errors.New("logs follow requires a streaming adapter")
	ErrContainerOperationIDMissing = errors.New("container operation_id is required")
	ErrContainerOperationActive    = errors.New("container operation is already active")
	ErrContainerOperationNotFound  = errors.New("container operation is not active")
	ErrContainerOperationMismatch  = errors.New("container operation method mismatch")
)
View Source
var ErrInvalidSchemaVersion = errors.New("container schema_version is invalid")

Functions

This section is empty.

Types

type Adapter

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

func NewAdapter

func NewAdapter(client EngineClient) *Adapter

func (*Adapter) CallMethod

func (a *Adapter) CallMethod(ctx context.Context, method Method, request json.RawMessage) (any, error)

func (*Adapter) CallOperationMethod

func (a *Adapter) CallOperationMethod(ctx context.Context, operationID string, method Method, request json.RawMessage) (any, error)

func (*Adapter) FollowLogs

func (a *Adapter) FollowLogs(ctx context.Context, req LogsTailRequest, sink LogLineSink) error

func (*Adapter) Inspect

func (*Adapter) List

func (*Adapter) PullImage

func (a *Adapter) PullImage(ctx context.Context, req ImagePullRequest) (ImagePullResponse, error)

func (*Adapter) PullImageWithOperation

func (a *Adapter) PullImageWithOperation(ctx context.Context, operationID string, req ImagePullRequest) (ImagePullResponse, error)

func (*Adapter) Remove

func (*Adapter) RemoveWithOperation

func (a *Adapter) RemoveWithOperation(ctx context.Context, operationID string, req ContainerActionRequest) (ContainerActionResponse, error)

func (*Adapter) Restart

func (*Adapter) RestartWithOperation

func (a *Adapter) RestartWithOperation(ctx context.Context, operationID string, req ContainerActionRequest) (ContainerActionResponse, error)

func (*Adapter) Start

func (*Adapter) StartPreflight

func (a *Adapter) StartPreflight(ctx context.Context, req ContainerStartRequest) (StartPreflightPlan, error)

func (*Adapter) StartWithOperation

func (a *Adapter) StartWithOperation(ctx context.Context, operationID string, req ContainerStartRequest) (ContainerActionResponse, error)

func (*Adapter) Status

func (a *Adapter) Status(ctx context.Context, req StatusRequest) (StatusResponse, error)

func (*Adapter) Stop

func (*Adapter) StopWithOperation

func (a *Adapter) StopWithOperation(ctx context.Context, operationID string, req ContainerActionRequest) (ContainerActionResponse, error)

func (*Adapter) TailLogs

func (a *Adapter) TailLogs(ctx context.Context, req LogsTailRequest) (LogsTailResponse, error)

type CLIClient

type CLIClient struct {
	Runner        CommandRunner
	Timeout       time.Duration
	StreamTimeout time.Duration
}

func NewCLIClient

func NewCLIClient() *CLIClient

func (*CLIClient) Action

func (*CLIClient) FollowLogs

func (c *CLIClient) FollowLogs(ctx context.Context, req EngineLogsRequest, sink LogLineSink) error

func (*CLIClient) Inspect

func (c *CLIClient) Inspect(ctx context.Context, engine Engine, containerID string) (EngineContainer, error)

func (*CLIClient) List

func (c *CLIClient) List(ctx context.Context, engine Engine, all bool) ([]EngineContainer, error)

func (*CLIClient) PullImage

func (c *CLIClient) PullImage(ctx context.Context, engine Engine, imageRef string) (EngineImageResult, error)

func (*CLIClient) Status

func (c *CLIClient) Status(ctx context.Context, engine Engine) (EngineStatus, error)

func (*CLIClient) TailLogs

type CommandRunner

type CommandRunner interface {
	Run(ctx context.Context, name string, args ...string) ([]byte, error)
}

type CommandRunnerFunc

type CommandRunnerFunc func(ctx context.Context, name string, args ...string) ([]byte, error)

func (CommandRunnerFunc) Run

func (f CommandRunnerFunc) Run(ctx context.Context, name string, args ...string) ([]byte, error)

type CommandStreamer

type CommandStreamer interface {
	Stream(ctx context.Context, name string, args []string, onStdoutLine func([]byte) error) error
}

type ContainerActionRequest

type ContainerActionRequest struct {
	SchemaVersion string `json:"schema_version"`
	Engine        Engine `json:"engine"`
	ContainerID   string `json:"container_id"`
	Force         bool   `json:"force,omitempty"`
	TimeoutSec    int    `json:"timeout_sec,omitempty"`
}

type ContainerActionResponse

type ContainerActionResponse struct {
	SchemaVersion     string `json:"schema_version"`
	CapabilityID      string `json:"capability_id"`
	CapabilityVersion string `json:"capability_version"`
	Engine            Engine `json:"engine"`
	Method            Method `json:"method"`
	ContainerID       string `json:"container_id"`
	Completed         bool   `json:"completed"`
}

type ContainerInspect

type ContainerInspect struct {
	ContainerID     string          `json:"container_id"`
	Name            string          `json:"name,omitempty"`
	Image           ImageSummary    `json:"image"`
	State           ContainerState  `json:"state"`
	CreatedAtUnixMs int64           `json:"created_at_unix_ms,omitempty"`
	Runtime         RuntimeSummary  `json:"runtime"`
	Labels          LabelSummary    `json:"labels"`
	Ports           []PortSummary   `json:"ports,omitempty"`
	Mounts          []MountSummary  `json:"mounts,omitempty"`
	Devices         []DeviceSummary `json:"devices,omitempty"`
}

type ContainerInspectRequest

type ContainerInspectRequest struct {
	SchemaVersion string `json:"schema_version"`
	Engine        Engine `json:"engine"`
	ContainerID   string `json:"container_id"`
}

type ContainerInspectResponse

type ContainerInspectResponse struct {
	SchemaVersion string           `json:"schema_version"`
	CapabilityID  string           `json:"capability_id"`
	Engine        Engine           `json:"engine"`
	Container     ContainerInspect `json:"container"`
}

type ContainerListRequest

type ContainerListRequest struct {
	SchemaVersion string `json:"schema_version"`
	Engine        Engine `json:"engine,omitempty"`
	All           bool   `json:"all,omitempty"`
}

type ContainerListResponse

type ContainerListResponse struct {
	SchemaVersion string             `json:"schema_version"`
	CapabilityID  string             `json:"capability_id"`
	Engine        Engine             `json:"engine"`
	Containers    []ContainerSummary `json:"containers"`
}

type ContainerOperationCancelRequest

type ContainerOperationCancelRequest struct {
	OperationID string `json:"operation_id"`
	Method      Method `json:"method,omitempty"`
}

type ContainerOperationCancelResult

type ContainerOperationCancelResult struct {
	OperationID     string `json:"operation_id"`
	Method          Method `json:"method"`
	CancelRequested bool   `json:"cancel_requested"`
}

type ContainerStartRequest

type ContainerStartRequest struct {
	SchemaVersion string `json:"schema_version"`
	Engine        Engine `json:"engine"`
	ContainerID   string `json:"container_id"`
}

func NewStartRequest

func NewStartRequest(engine Engine, containerID string) ContainerStartRequest

type ContainerState

type ContainerState string
const (
	ContainerStateCreated    ContainerState = "created"
	ContainerStateRunning    ContainerState = "running"
	ContainerStatePaused     ContainerState = "paused"
	ContainerStateRestarting ContainerState = "restarting"
	ContainerStateExited     ContainerState = "exited"
	ContainerStateStopped    ContainerState = "stopped"
	ContainerStateUnknown    ContainerState = "unknown"
)

type ContainerSummary

type ContainerSummary struct {
	ContainerID     string         `json:"container_id"`
	Name            string         `json:"name,omitempty"`
	Image           ImageSummary   `json:"image"`
	State           ContainerState `json:"state"`
	CreatedAtUnixMs int64          `json:"created_at_unix_ms,omitempty"`
	Ports           []PortSummary  `json:"ports,omitempty"`
}

type DeviceInput

type DeviceInput struct {
	HostPath      string
	ContainerPath string
	Permissions   string
}

type DeviceSummary

type DeviceSummary struct {
	HostPath      string `json:"host_path,omitempty"`
	ContainerPath string `json:"container_path,omitempty"`
	Permissions   string `json:"permissions,omitempty"`
	SensitivePath bool   `json:"sensitive_path,omitempty"`
}

type Engine

type Engine string
const (
	EngineDocker Engine = "docker"
	EnginePodman Engine = "podman"
)

func (Engine) Valid

func (e Engine) Valid() bool

type EngineActionRequest

type EngineActionRequest struct {
	Engine      Engine
	Method      Method
	ContainerID string
	Force       bool
	TimeoutSec  int
}

type EngineActionResult

type EngineActionResult struct {
	Engine      Engine
	Method      Method
	ContainerID string
	Completed   bool
}

type EngineClient

type EngineClient interface {
	Status(ctx context.Context, engine Engine) (EngineStatus, error)
	List(ctx context.Context, engine Engine, all bool) ([]EngineContainer, error)
	Inspect(ctx context.Context, engine Engine, containerID string) (EngineContainer, error)
	Action(ctx context.Context, req EngineActionRequest) (EngineActionResult, error)
	TailLogs(ctx context.Context, req EngineLogsRequest) (EngineLogsResult, error)
	PullImage(ctx context.Context, engine Engine, imageRef string) (EngineImageResult, error)
}

type EngineContainer

type EngineContainer struct {
	Engine          Engine
	ContainerID     string
	Name            string
	Image           ImageInput
	State           ContainerState
	CreatedAtUnixMs int64
	Runtime         RuntimeInput
	Ports           []PortSummary
}

type EngineImageResult

type EngineImageResult struct {
	Engine    Engine
	Image     ImageInput
	Completed bool
}

type EngineLogFollower

type EngineLogFollower interface {
	FollowLogs(ctx context.Context, req EngineLogsRequest, sink LogLineSink) error
}

type EngineLogsRequest

type EngineLogsRequest struct {
	Engine      Engine
	ContainerID string
	TailLines   int
	SinceUnixMs int64
	Follow      bool
}

type EngineLogsResult

type EngineLogsResult struct {
	Engine      Engine
	ContainerID string
	Lines       []LogLine
}

type EngineStatus

type EngineStatus struct {
	Engine    Engine
	Available bool
	Version   string
}

type EnvSummary

type EnvSummary struct {
	Total           int `json:"total"`
	PlainCount      int `json:"plain_count"`
	SecretLikeCount int `json:"secret_like_count"`
}

type ImageInput

type ImageInput struct {
	Reference string
	Digest    string
}

type ImagePullRequest

type ImagePullRequest struct {
	SchemaVersion string `json:"schema_version"`
	Engine        Engine `json:"engine"`
	ImageRef      string `json:"image_ref"`
}

type ImagePullResponse

type ImagePullResponse struct {
	SchemaVersion     string       `json:"schema_version"`
	CapabilityID      string       `json:"capability_id"`
	CapabilityVersion string       `json:"capability_version"`
	Engine            Engine       `json:"engine"`
	Image             ImageSummary `json:"image"`
	Completed         bool         `json:"completed"`
}

type ImageSummary

type ImageSummary struct {
	Reference    string `json:"reference,omitempty"`
	Digest       string `json:"digest,omitempty"`
	DigestPinned bool   `json:"digest_pinned"`
}

type LabelSummary

type LabelSummary struct {
	Total           int `json:"total"`
	PlainCount      int `json:"plain_count"`
	SecretLikeCount int `json:"secret_like_count"`
}

type LogLine

type LogLine struct {
	TimestampUnixMs int64  `json:"timestamp_unix_ms,omitempty"`
	Message         string `json:"message"`
}

type LogLineChannelSink

type LogLineChannelSink struct {
	Lines chan<- LogLine
}

func NewLogLineChannelSink

func NewLogLineChannelSink(lines chan<- LogLine) LogLineChannelSink

func (LogLineChannelSink) AppendLogLine

func (s LogLineChannelSink) AppendLogLine(ctx context.Context, line LogLine) error

type LogLineSink

type LogLineSink interface {
	AppendLogLine(ctx context.Context, line LogLine) error
}

type LogLineSinkFunc

type LogLineSinkFunc func(ctx context.Context, line LogLine) error

func (LogLineSinkFunc) AppendLogLine

func (f LogLineSinkFunc) AppendLogLine(ctx context.Context, line LogLine) error

type LogsTailRequest

type LogsTailRequest struct {
	SchemaVersion string `json:"schema_version"`
	Engine        Engine `json:"engine"`
	ContainerID   string `json:"container_id"`
	TailLines     int    `json:"tail_lines,omitempty"`
	SinceUnixMs   int64  `json:"since_unix_ms,omitempty"`
	Follow        bool   `json:"follow,omitempty"`
}

type LogsTailResponse

type LogsTailResponse struct {
	SchemaVersion     string    `json:"schema_version"`
	CapabilityID      string    `json:"capability_id"`
	CapabilityVersion string    `json:"capability_version"`
	Engine            Engine    `json:"engine"`
	ContainerID       string    `json:"container_id"`
	Lines             []LogLine `json:"lines"`
}

type Method

type Method string
const (
	MethodStatus         Method = "containers.status"
	MethodList           Method = "containers.list"
	MethodInspect        Method = "containers.inspect"
	MethodStartPreflight Method = "containers.start.preflight"
	MethodStart          Method = "containers.start"
	MethodStop           Method = "containers.stop"
	MethodRestart        Method = "containers.restart"
	MethodRemove         Method = "containers.remove"
	MethodLogsTail       Method = "containers.logs.tail"
	MethodImagesPull     Method = "images.pull"
)

func Methods

func Methods() []Method

type MountInput

type MountInput struct {
	Type     MountType
	Source   string
	Target   string
	ReadOnly bool
}

type MountSourceKind

type MountSourceKind string
const (
	MountSourceHostPath        MountSourceKind = "host_path"
	MountSourceNamedVolume     MountSourceKind = "named_volume"
	MountSourceTmpfs           MountSourceKind = "tmpfs"
	MountSourceContainerSocket MountSourceKind = "container_socket"
	MountSourceUnknown         MountSourceKind = "unknown"
)

type MountSummary

type MountSummary struct {
	Type            MountType       `json:"type"`
	Source          string          `json:"source,omitempty"`
	Target          string          `json:"target,omitempty"`
	SourceKind      MountSourceKind `json:"source_kind"`
	ReadOnly        bool            `json:"read_only"`
	SensitivePath   bool            `json:"sensitive_path,omitempty"`
	ContainerSocket bool            `json:"container_socket,omitempty"`
}

type MountType

type MountType string
const (
	MountTypeBind   MountType = "bind"
	MountTypeVolume MountType = "volume"
	MountTypeTmpfs  MountType = "tmpfs"
	MountTypeOther  MountType = "other"
)

type PortSummary

type PortSummary struct {
	Protocol string `json:"protocol,omitempty"`
	HostIP   string `json:"host_ip,omitempty"`
	HostPort int    `json:"host_port,omitempty"`
	Port     int    `json:"port"`
}

type RiskFlag

type RiskFlag struct {
	ID            string       `json:"id"`
	Severity      RiskSeverity `json:"severity"`
	Title         string       `json:"title"`
	Detail        string       `json:"detail,omitempty"`
	AdminRequired bool         `json:"admin_required,omitempty"`
}

type RiskLevel

type RiskLevel string
const (
	RiskLevelNone     RiskLevel = "none"
	RiskLevelLow      RiskLevel = "low"
	RiskLevelMedium   RiskLevel = "medium"
	RiskLevelHigh     RiskLevel = "high"
	RiskLevelCritical RiskLevel = "critical"
)

type RiskSeverity

type RiskSeverity string
const (
	RiskSeverityLow      RiskSeverity = "low"
	RiskSeverityMedium   RiskSeverity = "medium"
	RiskSeverityHigh     RiskSeverity = "high"
	RiskSeverityCritical RiskSeverity = "critical"
)

type RuntimeInput

type RuntimeInput struct {
	Privileged    bool
	NetworkMode   string
	PIDMode       string
	IPCMode       string
	RestartPolicy string
	Env           []string
	Labels        map[string]string
	Mounts        []MountInput
	Devices       []DeviceInput
	CapAdd        []string
	CapDrop       []string
}

type RuntimeSummary

type RuntimeSummary struct {
	Privileged    bool            `json:"privileged"`
	NetworkMode   string          `json:"network_mode,omitempty"`
	PIDMode       string          `json:"pid_mode,omitempty"`
	IPCMode       string          `json:"ipc_mode,omitempty"`
	RestartPolicy string          `json:"restart_policy,omitempty"`
	Env           EnvSummary      `json:"env"`
	Labels        LabelSummary    `json:"labels"`
	Mounts        []MountSummary  `json:"mounts,omitempty"`
	Devices       []DeviceSummary `json:"devices,omitempty"`
	CapAdd        []string        `json:"cap_add,omitempty"`
	CapDrop       []string        `json:"cap_drop,omitempty"`
}

type StartPreflightInput

type StartPreflightInput struct {
	Engine        Engine
	ContainerID   string
	ContainerName string
	Image         ImageInput
	Runtime       RuntimeInput
}

type StartPreflightPlan

type StartPreflightPlan struct {
	SchemaVersion     string                `json:"schema_version"`
	CapabilityID      string                `json:"capability_id"`
	CapabilityVersion string                `json:"capability_version"`
	Method            Method                `json:"method"`
	Request           ContainerStartRequest `json:"request"`
	Target            TargetSummary         `json:"target"`
	Image             ImageSummary          `json:"image"`
	Runtime           RuntimeSummary        `json:"runtime"`
	RiskLevel         RiskLevel             `json:"risk_level"`
	RiskFlags         []RiskFlag            `json:"risk_flags"`
	RequiresAdmin     bool                  `json:"requires_admin"`
	Summary           []string              `json:"summary,omitempty"`
}

func BuildStartPreflightPlan

func BuildStartPreflightPlan(input StartPreflightInput) (StartPreflightPlan, error)

type StatusRequest

type StatusRequest struct {
	SchemaVersion string `json:"schema_version"`
	Engine        Engine `json:"engine,omitempty"`
}

type StatusResponse

type StatusResponse struct {
	SchemaVersion     string `json:"schema_version"`
	CapabilityID      string `json:"capability_id"`
	CapabilityVersion string `json:"capability_version"`
	Engine            Engine `json:"engine"`
	Available         bool   `json:"available"`
	EngineVersion     string `json:"engine_version,omitempty"`
}

type TargetSummary

type TargetSummary struct {
	Engine        Engine `json:"engine"`
	ContainerID   string `json:"container_id"`
	ContainerName string `json:"container_name,omitempty"`
	TargetHash    string `json:"target_hash"`
}

Jump to

Keyboard shortcuts

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