container

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

internal/container/k8s.go

internal/container/runtime.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsContainerRunning

func IsContainerRunning(runtime Runtime, containerName string) bool

IsContainerRunning checks if a container is currently running

func ValidateContainerOptions

func ValidateContainerOptions(opts *ContainerOptions) error

ValidateContainerOptions performs basic validation on container options

func WaitForContainerReady

func WaitForContainerReady(runtime Runtime, containerName string, maxWait int) error

WaitForContainerReady waits for a container to be ready (running and healthy)

Types

type BuildOptions

type BuildOptions struct {
	Context    string            `json:"context"`
	Dockerfile string            `json:"dockerfile"`
	Tags       []string          `json:"tags"`
	Args       map[string]string `json:"args"`
	Target     string            `json:"target"`
	NoCache    bool              `json:"no_cache"`
	Pull       bool              `json:"pull"`
	Platform   string            `json:"platform"`
}

BuildOptions represents build configuration options

type ContainerInfo

type ContainerInfo struct {
	ID           string                     `json:"id"`
	Name         string                     `json:"name"`
	Image        string                     `json:"image"`
	Status       string                     `json:"status"`
	State        string                     `json:"state"`
	Created      string                     `json:"created"`
	Ports        []PortBinding              `json:"ports"`
	Mounts       []MountInfo                `json:"mounts"`
	Networks     map[string]NetworkEndpoint `json:"networks"`
	Labels       map[string]string          `json:"labels"`
	Env          []string                   `json:"env"`
	Command      []string                   `json:"command"`
	RestartCount int                        `json:"restart_count"`
}

ContainerInfo represents detailed container information

type ContainerOptions

type ContainerOptions struct {
	Name        string
	Image       string
	Command     string
	Args        []string
	Env         map[string]string
	Ports       []string
	Volumes     []string
	WorkDir     string
	Pull        bool
	NetworkMode string   // Deprecated: Kubernetes handles networking
	Networks    []string // Deprecated: Kubernetes handles networking
	Build       config.BuildConfig

	// Security context
	Privileged  bool     `yaml:"privileged,omitempty"`
	User        string   `yaml:"user,omitempty"`
	Groups      []string `yaml:"groups,omitempty"`
	CapAdd      []string `yaml:"cap_add,omitempty"`
	CapDrop     []string `yaml:"cap_drop,omitempty"`
	SecurityOpt []string `yaml:"security_opt,omitempty"`
	ReadOnly    bool     `yaml:"read_only,omitempty"`
	Tmpfs       []string `yaml:"tmpfs,omitempty"`

	// Resource limits
	CPUs       string `yaml:"cpus,omitempty"`
	Memory     string `yaml:"memory,omitempty"`
	MemorySwap string `yaml:"memory_swap,omitempty"`
	PidsLimit  int    `yaml:"pids_limit,omitempty"`

	// Lifecycle
	RestartPolicy string       `yaml:"restart,omitempty"`
	StopSignal    string       `yaml:"stop_signal,omitempty"`
	StopTimeout   *int         `yaml:"stop_grace_period,omitempty"`
	HealthCheck   *HealthCheck `yaml:"healthcheck,omitempty"`

	// Runtime options
	Runtime    string   `yaml:"runtime,omitempty"`
	Platform   string   `yaml:"platform,omitempty"`
	Hostname   string   `yaml:"hostname,omitempty"`
	DomainName string   `yaml:"domainname,omitempty"`
	DNS        []string `yaml:"dns,omitempty"`
	DNSSearch  []string `yaml:"dns_search,omitempty"`
	ExtraHosts []string `yaml:"extra_hosts,omitempty"`

	// Logging
	LogDriver  string            `yaml:"log_driver,omitempty"`
	LogOptions map[string]string `yaml:"log_options,omitempty"`

	// Labels and metadata
	Labels      map[string]string `yaml:"labels,omitempty"`
	Annotations map[string]string `yaml:"annotations,omitempty"`

	// Security configuration for validation
	Security SecurityConfig `yaml:"security,omitempty"`
}

ContainerOptions holds container creation options NOTE: This is deprecated in container mode - use MCPServer CRDs instead

func ConvertConfigToContainerOptions

func ConvertConfigToContainerOptions(serverName string, serverCfg config.ServerConfig) *ContainerOptions

ConvertConfigToContainerOptions converts server config to container options

func GetDefaultContainerOptions

func GetDefaultContainerOptions() *ContainerOptions

GetDefaultContainerOptions returns default container options

func MergeContainerOptions

func MergeContainerOptions(opts, defaults *ContainerOptions) *ContainerOptions

MergeContainerOptions merges container options with defaults

type ContainerStats

type ContainerStats struct {
	CPUUsage    float64 `json:"cpu_usage"`
	MemoryUsage int64   `json:"memory_usage"`
	MemoryLimit int64   `json:"memory_limit"`
	NetworkIO   struct {
		RxBytes int64 `json:"rx_bytes"`
		TxBytes int64 `json:"tx_bytes"`
	} `json:"network_io"`
	BlockIO struct {
		ReadBytes  int64 `json:"read_bytes"`
		WriteBytes int64 `json:"write_bytes"`
	} `json:"block_io"`
}

ContainerStats represents container statistics

type HealthCheck

type HealthCheck struct {
	Test        []string `yaml:"test,omitempty"`
	Interval    string   `yaml:"interval,omitempty"`
	Timeout     string   `yaml:"timeout,omitempty"`
	Retries     int      `yaml:"retries,omitempty"`
	StartPeriod string   `yaml:"start_period,omitempty"`
}

HealthCheck defines health check configuration

type ImageAuth

type ImageAuth struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Registry string `json:"registry"`
}

ImageAuth represents image authentication credentials

type ImageInfo

type ImageInfo struct {
	ID      string            `json:"id"`
	Tags    []string          `json:"tags"`
	Size    int64             `json:"size"`
	Created string            `json:"created"`
	Labels  map[string]string `json:"labels"`
}

ImageInfo represents image information

type KubernetesRuntime

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

KubernetesRuntime implements container runtime using Kubernetes

func (*KubernetesRuntime) BuildImage

func (k *KubernetesRuntime) BuildImage(opts *BuildOptions) error

func (*KubernetesRuntime) ConnectToNetwork

func (k *KubernetesRuntime) ConnectToNetwork(containerName, networkName string) error

func (*KubernetesRuntime) CreateNetwork

func (k *KubernetesRuntime) CreateNetwork(name string) error

func (*KubernetesRuntime) CreateVolume

func (k *KubernetesRuntime) CreateVolume(name string, opts *VolumeOptions) error

func (*KubernetesRuntime) DisconnectFromNetwork

func (k *KubernetesRuntime) DisconnectFromNetwork(containerName, networkName string) error

func (*KubernetesRuntime) ExecContainer

func (k *KubernetesRuntime) ExecContainer(containerName string, command []string, interactive bool) (*exec.Cmd, io.Writer, io.Reader, error)

ExecContainer executes command in pod

func (*KubernetesRuntime) GetContainerInfo

func (k *KubernetesRuntime) GetContainerInfo(name string) (*ContainerInfo, error)

GetContainerInfo returns detailed container information

func (*KubernetesRuntime) GetContainerStats

func (k *KubernetesRuntime) GetContainerStats(name string) (*ContainerStats, error)

GetContainerStats returns container statistics (from metrics server if available)

func (*KubernetesRuntime) GetContainerStatus

func (k *KubernetesRuntime) GetContainerStatus(name string) (string, error)

GetContainerStatus returns the deployment status

func (*KubernetesRuntime) GetNetworkInfo

func (k *KubernetesRuntime) GetNetworkInfo(name string) (*NetworkInfo, error)

func (*KubernetesRuntime) GetRuntimeName

func (k *KubernetesRuntime) GetRuntimeName() string

GetRuntimeName returns the runtime name

func (*KubernetesRuntime) ListContainers

func (k *KubernetesRuntime) ListContainers(filters map[string]string) ([]ContainerInfo, error)

ListContainers returns list of deployments

func (*KubernetesRuntime) ListImages

func (k *KubernetesRuntime) ListImages() ([]ImageInfo, error)

func (*KubernetesRuntime) ListNetworks

func (k *KubernetesRuntime) ListNetworks() ([]NetworkInfo, error)

func (*KubernetesRuntime) ListVolumes

func (k *KubernetesRuntime) ListVolumes() ([]VolumeInfo, error)

func (*KubernetesRuntime) NetworkExists

func (k *KubernetesRuntime) NetworkExists(name string) (bool, error)

func (*KubernetesRuntime) PauseContainer

func (k *KubernetesRuntime) PauseContainer(name string) error

PauseContainer - not directly supported in Kubernetes, scale to 0 instead

func (*KubernetesRuntime) PullImage

func (k *KubernetesRuntime) PullImage(image string, auth *ImageAuth) error

Placeholder implementations for other interface methods

func (*KubernetesRuntime) RemoveImage

func (k *KubernetesRuntime) RemoveImage(image string, force bool) error

func (*KubernetesRuntime) RemoveNetwork

func (k *KubernetesRuntime) RemoveNetwork(name string) error

func (*KubernetesRuntime) RemoveVolume

func (k *KubernetesRuntime) RemoveVolume(name string, force bool) error

func (*KubernetesRuntime) RestartContainer

func (k *KubernetesRuntime) RestartContainer(name string) error

RestartContainer restarts the deployment

func (*KubernetesRuntime) ShowContainerLogs

func (k *KubernetesRuntime) ShowContainerLogs(name string, follow bool) error

ShowContainerLogs shows logs from pods

func (*KubernetesRuntime) StartContainer

func (k *KubernetesRuntime) StartContainer(opts *ContainerOptions) (string, error)

StartContainer creates and starts a Kubernetes deployment

func (*KubernetesRuntime) StopContainer

func (k *KubernetesRuntime) StopContainer(name string) error

StopContainer scales deployment to 0 replicas

func (*KubernetesRuntime) UnpauseContainer

func (k *KubernetesRuntime) UnpauseContainer(name string) error

UnpauseContainer - scale back to 1 replica

func (*KubernetesRuntime) UpdateContainerResources

func (k *KubernetesRuntime) UpdateContainerResources(name string, resources *ResourceLimits) error

func (*KubernetesRuntime) ValidateSecurityContext

func (k *KubernetesRuntime) ValidateSecurityContext(opts *ContainerOptions) error

func (*KubernetesRuntime) WaitForContainer

func (k *KubernetesRuntime) WaitForContainer(name string, condition string) error

WaitForContainer waits for deployment to reach desired state

type MountInfo

type MountInfo struct {
	Type        string `json:"type"`
	Source      string `json:"source"`
	Destination string `json:"destination"`
	Mode        string `json:"mode"`
	RW          bool   `json:"rw"`
}

MountInfo represents mount information

type NetworkEndpoint

type NetworkEndpoint struct {
	EndpointID  string `json:"endpoint_id"`
	MacAddress  string `json:"mac_address"`
	IPv4Address string `json:"ipv4_address"`
	IPv6Address string `json:"ipv6_address"`
}

NetworkEndpoint represents a network endpoint

type NetworkInfo

type NetworkInfo struct {
	ID         string                     `json:"id"`
	Name       string                     `json:"name"`
	Driver     string                     `json:"driver"`
	Scope      string                     `json:"scope"`
	Internal   bool                       `json:"internal"`
	Attachable bool                       `json:"attachable"`
	Containers map[string]NetworkEndpoint `json:"containers"`
	Options    map[string]string          `json:"options"`
	Labels     map[string]string          `json:"labels"`
}

NetworkInfo represents network information

type NullRuntime

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

NullRuntime implements the Runtime interface for testing purposes All methods return appropriate no-op responses or test-friendly errors

func NewNullRuntime

func NewNullRuntime() *NullRuntime

NewNullRuntime creates a new null runtime for testing

func (*NullRuntime) BuildImage

func (n *NullRuntime) BuildImage(opts *BuildOptions) error

func (*NullRuntime) ConnectToNetwork

func (n *NullRuntime) ConnectToNetwork(containerName, networkName string) error

func (*NullRuntime) CreateNetwork

func (n *NullRuntime) CreateNetwork(name string) error

func (*NullRuntime) CreateVolume

func (n *NullRuntime) CreateVolume(name string, opts *VolumeOptions) error

Volume management

func (*NullRuntime) DisconnectFromNetwork

func (n *NullRuntime) DisconnectFromNetwork(containerName, networkName string) error

func (*NullRuntime) ExecContainer

func (n *NullRuntime) ExecContainer(containerName string, command []string, interactive bool) (*exec.Cmd, io.Writer, io.Reader, error)

func (*NullRuntime) GetContainerInfo

func (n *NullRuntime) GetContainerInfo(name string) (*ContainerInfo, error)

func (*NullRuntime) GetContainerStats

func (n *NullRuntime) GetContainerStats(name string) (*ContainerStats, error)

func (*NullRuntime) GetContainerStatus

func (n *NullRuntime) GetContainerStatus(name string) (string, error)

Container inspection and monitoring

func (*NullRuntime) GetNetworkInfo

func (n *NullRuntime) GetNetworkInfo(name string) (*NetworkInfo, error)

func (*NullRuntime) GetRuntimeName

func (n *NullRuntime) GetRuntimeName() string

Runtime information

func (*NullRuntime) ListContainers

func (n *NullRuntime) ListContainers(filters map[string]string) ([]ContainerInfo, error)

func (*NullRuntime) ListImages

func (n *NullRuntime) ListImages() ([]ImageInfo, error)

func (*NullRuntime) ListNetworks

func (n *NullRuntime) ListNetworks() ([]NetworkInfo, error)

func (*NullRuntime) ListVolumes

func (n *NullRuntime) ListVolumes() ([]VolumeInfo, error)

func (*NullRuntime) NetworkExists

func (n *NullRuntime) NetworkExists(name string) (bool, error)

Network management

func (*NullRuntime) PauseContainer

func (n *NullRuntime) PauseContainer(name string) error

func (*NullRuntime) PullImage

func (n *NullRuntime) PullImage(image string, auth *ImageAuth) error

Image management

func (*NullRuntime) RemoveImage

func (n *NullRuntime) RemoveImage(image string, force bool) error

func (*NullRuntime) RemoveNetwork

func (n *NullRuntime) RemoveNetwork(name string) error

func (*NullRuntime) RemoveVolume

func (n *NullRuntime) RemoveVolume(name string, force bool) error

func (*NullRuntime) RestartContainer

func (n *NullRuntime) RestartContainer(name string) error

func (*NullRuntime) ShowContainerLogs

func (n *NullRuntime) ShowContainerLogs(name string, follow bool) error

Container logs and execution

func (*NullRuntime) StartContainer

func (n *NullRuntime) StartContainer(opts *ContainerOptions) (string, error)

Container lifecycle management

func (*NullRuntime) StopContainer

func (n *NullRuntime) StopContainer(name string) error

func (*NullRuntime) UnpauseContainer

func (n *NullRuntime) UnpauseContainer(name string) error

func (*NullRuntime) UpdateContainerResources

func (n *NullRuntime) UpdateContainerResources(name string, resources *ResourceLimits) error

Resource management

func (*NullRuntime) ValidateSecurityContext

func (n *NullRuntime) ValidateSecurityContext(opts *ContainerOptions) error

Security and validation

func (*NullRuntime) WaitForContainer

func (n *NullRuntime) WaitForContainer(name string, condition string) error

type PortBinding

type PortBinding struct {
	PrivatePort int    `json:"private_port"`
	PublicPort  int    `json:"public_port"`
	Type        string `json:"type"`
	IP          string `json:"ip"`
}

PortBinding represents a port binding

type ResourceLimits

type ResourceLimits struct {
	CPUs        string `json:"cpus"`
	Memory      string `json:"memory"`
	PidsLimit   int    `json:"pids_limit"`
	BlkioWeight int    `json:"blkio_weight"`
}

ResourceLimits represents resource limits for container updates

type Runtime

type Runtime interface {
	// Container lifecycle management
	StartContainer(opts *ContainerOptions) (string, error)
	StopContainer(name string) error
	RestartContainer(name string) error
	PauseContainer(name string) error
	UnpauseContainer(name string) error

	// Container inspection and monitoring
	GetContainerStatus(name string) (string, error)
	GetContainerInfo(name string) (*ContainerInfo, error)
	ListContainers(filters map[string]string) ([]ContainerInfo, error)
	GetContainerStats(name string) (*ContainerStats, error)
	WaitForContainer(name string, condition string) error

	// Container logs and execution
	ShowContainerLogs(name string, follow bool) error
	ExecContainer(containerName string, command []string, interactive bool) (*exec.Cmd, io.Writer, io.Reader, error)

	// Image management
	PullImage(image string, auth *ImageAuth) error
	BuildImage(opts *BuildOptions) error
	RemoveImage(image string, force bool) error
	ListImages() ([]ImageInfo, error)

	// Volume management
	CreateVolume(name string, opts *VolumeOptions) error
	RemoveVolume(name string, force bool) error
	ListVolumes() ([]VolumeInfo, error)

	// Network management
	NetworkExists(name string) (bool, error)
	CreateNetwork(name string) error
	RemoveNetwork(name string) error
	ListNetworks() ([]NetworkInfo, error)
	GetNetworkInfo(name string) (*NetworkInfo, error)
	ConnectToNetwork(containerName, networkName string) error
	DisconnectFromNetwork(containerName, networkName string) error

	// Resource management
	UpdateContainerResources(name string, resources *ResourceLimits) error

	// Security and validation
	ValidateSecurityContext(opts *ContainerOptions) error

	// Runtime information
	GetRuntimeName() string
}

Runtime defines the interface for container runtimes

func DetectRuntime

func DetectRuntime() (Runtime, error)

DetectRuntime tries to detect and initialize a container runtime

func NewKubernetesRuntime

func NewKubernetesRuntime(namespace string) (Runtime, error)

NewKubernetesRuntime creates a Kubernetes runtime

type SecurityConfig

type SecurityConfig struct {
	AllowHostMounts    []string `yaml:"allow_host_mounts,omitempty"`
	AllowPrivilegedOps bool     `yaml:"allow_privileged_ops,omitempty"`
	TrustedImage       bool     `yaml:"trusted_image,omitempty"`
}

SecurityConfig for container validation - deprecated in container mode

type VolumeInfo

type VolumeInfo struct {
	Name       string            `json:"name"`
	Driver     string            `json:"driver"`
	Mountpoint string            `json:"mountpoint"`
	Labels     map[string]string `json:"labels"`
	Options    map[string]string `json:"options"`
	Scope      string            `json:"scope"`
}

VolumeInfo represents volume information

type VolumeOptions

type VolumeOptions struct {
	Driver     string            `json:"driver"`
	DriverOpts map[string]string `json:"driver_opts"`
	Labels     map[string]string `json:"labels"`
}

VolumeOptions represents volume creation options

Jump to

Keyboard shortcuts

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