containerd

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	ID        string
	Name      string
	Image     string
	Status    ContainerStatus
	NodeID    string
	CreatedAt time.Time
	StartedAt *time.Time
	StoppedAt *time.Time
	Command   []string
	Env       []EnvVar
	Ports     []PortMapping
	Resources ResourceLimits
}

Container represents a container in the system

type ContainerOptions

type ContainerOptions struct {
	Name      string
	Image     string
	Command   []string
	Env       []EnvVar
	Ports     []PortMapping
	Volumes   []Volume
	Resources ResourceLimits
}

ContainerOptions represents options for creating a container

type ContainerRuntime

type ContainerRuntime interface {
	PullImage(ctx context.Context, image string) error
	CreateContainer(ctx context.Context, opts ContainerOptions) (string, error)
	StopContainer(ctx context.Context, containerID string) error
	ListContainers(ctx context.Context) ([]*Container, error)
	GetContainerMetrics(ctx context.Context, containerID string) (*ContainerStats, error)
	CreateVolume(ctx context.Context, name string, opts map[string]string) error
	DeleteVolume(ctx context.Context, name string) error
	ListVolumes(ctx context.Context) ([]*Volume, error)
}

ContainerRuntime defines the interface for container runtime operations

type ContainerStats

type ContainerStats struct {
	CPUUsage    float64 // Percentage
	MemoryUsage uint64  // Bytes
	NetworkRx   uint64  // Bytes
	NetworkTx   uint64  // Bytes
	LastUpdated int64   // Unix timestamp
}

ContainerStats represents resource usage statistics for a container

type ContainerStatus

type ContainerStatus string

ContainerStatus represents the status of a container

const (
	// ContainerStatusCreated indicates the container is created but not started
	ContainerStatusCreated ContainerStatus = "created"
	// ContainerStatusRunning indicates the container is running
	ContainerStatusRunning ContainerStatus = "running"
	// ContainerStatusStopped indicates the container is stopped
	ContainerStatusStopped ContainerStatus = "stopped"
	// ContainerStatusPaused indicates the container is paused
	ContainerStatusPaused ContainerStatus = "paused"
	// ContainerStatusFailed indicates the container failed to start or run
	ContainerStatusFailed ContainerStatus = "failed"
)

type EnvVar

type EnvVar struct {
	Key   string
	Value string
}

EnvVar represents an environment variable for a container

type HealthCheckStatus

type HealthCheckStatus string

HealthCheckStatus represents the health status of a container

const (
	// HealthCheckHealthy indicates the container is healthy
	HealthCheckHealthy HealthCheckStatus = "healthy"
	// HealthCheckUnhealthy indicates the container is unhealthy
	HealthCheckUnhealthy HealthCheckStatus = "unhealthy"
	// HealthCheckUnknown indicates the container health is unknown
	HealthCheckUnknown HealthCheckStatus = "unknown"
)

type Image

type Image struct {
	Name    string
	Tag     string
	Digest  string
	Size    int64
	Created time.Time
}

Image represents a container image

type Manager

type Manager struct {
	Runtime ContainerRuntime
	// contains filtered or unexported fields
}

Manager handles interactions with the containerd daemon

func NewManager

func NewManager(socketPath string, logger *logrus.Logger) (*Manager, error)

NewManager creates a new containerd manager

func NewManagerWithoutClient

func NewManagerWithoutClient(logger *logrus.Logger) *Manager

NewManagerWithoutClient creates a new containerd manager without connecting to containerd This is useful when using an alternative runtime like Docker

func (*Manager) BackupVolume

func (m *Manager) BackupVolume(ctx context.Context, name string, outputPath string) error

BackupVolume backs up a volume to a file

func (*Manager) Close

func (m *Manager) Close() error

Close closes the containerd client connection

func (*Manager) CreateContainer

func (m *Manager) CreateContainer(ctx context.Context, name, image string, command []string, env map[string]string, volumes []string, ports map[string]string) (string, error)

CreateContainer implements the app.ContainerManager interface

func (*Manager) CreateContainerWithOptions

func (m *Manager) CreateContainerWithOptions(ctx context.Context, name, image string, command []string, env map[string]string, volumes []string, ports map[string]string) (string, error)

CreateContainerWithOptions creates a new container with the given parameters

func (*Manager) CreateContainerWithOpts

func (m *Manager) CreateContainerWithOpts(ctx context.Context, opts ContainerOptions) (string, error)

CreateContainerWithOptions creates a new container with the given options CreateContainerWithOpts creates a new container with the given ContainerOptions

func (*Manager) CreateContainerWithVolumes

func (m *Manager) CreateContainerWithVolumes(ctx context.Context, image string, name string, envVars []EnvVar, ports []PortMapping, volumes []Volume) (string, error)

CreateContainerWithVolumes creates a new container with volume mounts

func (*Manager) CreateVolume

func (m *Manager) CreateVolume(ctx context.Context, name string, opts map[string]string) error

CreateVolume creates a new volume

func (*Manager) DeleteVolume

func (m *Manager) DeleteVolume(ctx context.Context, name string) error

DeleteVolume deletes a volume

func (*Manager) ExecInContainer

func (m *Manager) ExecInContainer(ctx context.Context, id string, command []string) (string, error)

ExecInContainer executes a command in a container

func (*Manager) GetContainer

func (m *Manager) GetContainer(id string) (*api.Container, bool)

GetContainer returns a container by ID

func (*Manager) GetContainerLogs

func (m *Manager) GetContainerLogs(ctx context.Context, id string) (string, error)

GetContainerLogs returns the logs for a container

func (*Manager) GetContainerMetrics

func (m *Manager) GetContainerMetrics(ctx context.Context, containerID string) (*ContainerStats, error)

GetContainerMetrics returns metrics for a container

func (*Manager) GetContainerStats

func (m *Manager) GetContainerStats(ctx context.Context, containerID string) (*api.ContainerStats, error)

GetContainerStats returns statistics for a container

func (*Manager) GetContainerStatus

func (m *Manager) GetContainerStatus(ctx context.Context, id string) (string, error)

GetContainerStatus returns the status of a container

func (*Manager) GetContainers

func (m *Manager) GetContainers() []*api.Container

GetContainers returns a list of Hivemind containers

func (*Manager) IsVolumeInUse

func (m *Manager) IsVolumeInUse(ctx context.Context, name string) (bool, error)

IsVolumeInUse checks if a volume is in use by any container

func (*Manager) ListContainers

func (m *Manager) ListContainers(ctx context.Context) ([]api.Container, error)

ListContainers returns a list of containers

func (*Manager) ListImages

func (m *Manager) ListImages(ctx context.Context) ([]api.Image, error)

ListImages returns a list of available container images

func (*Manager) ListVolumes

func (m *Manager) ListVolumes(ctx context.Context) ([]*Volume, error)

ListVolumes returns a list of volumes

func (*Manager) PullImage

func (m *Manager) PullImage(ctx context.Context, image string) error

PullImage pulls an image from a registry

func (*Manager) RemoveContainer

func (m *Manager) RemoveContainer(ctx context.Context, id string) error

RemoveContainer removes a container

func (*Manager) RestoreVolume

func (m *Manager) RestoreVolume(ctx context.Context, name string, inputPath string) error

RestoreVolume restores a volume from a backup file

func (*Manager) StartContainer

func (m *Manager) StartContainer(ctx context.Context, id string) error

StartContainer starts a container

func (*Manager) StopContainer

func (m *Manager) StopContainer(ctx context.Context, containerID string) error

StopContainer stops and removes a container

func (*Manager) WithNamespace

func (m *Manager) WithNamespace(namespace string) *Manager

WithNamespace sets the namespace for the containerd manager

func (*Manager) WithRuntime

func (m *Manager) WithRuntime(runtime ContainerRuntime) *Manager

WithRuntime sets the container runtime for the manager

type PortMapping

type PortMapping struct {
	ContainerPort uint16
	HostPort      uint16
	Protocol      string // "tcp" or "udp"
}

PortMapping represents a port mapping for a container

type ResourceLimits

type ResourceLimits struct {
	CPU    float64
	Memory uint64
	Disk   uint64
}

ResourceLimits represents resource limits for a container

type Volume

type Volume struct {
	Name      string
	Path      string
	Size      uint64 // in bytes
	CreatedAt int64
}

Volume represents a volume in the Hivemind system

Jump to

Keyboard shortcuts

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