Documentation ¶
Index ¶
Constants ¶
const ( // CPUUsagePercentStat counts CPU usage as a percentage of the container's // limit. If the container has no limit, the percentage is relative to total // CPU capacity of the host. CPUUsagePercentStat = StatType("CPUUsagePercent") // MemoryUsageBytesStat counts memory usage in absolute bytes. MemoryUsageBytesStat = StatType("MemoryUsageBytes") // MemoryUsagePercentStat counts memory usage as a percentage of the // container's limit. If the container has no limit, the percentage is // relative to total available memory on the host. MemoryUsagePercentStat = StatType("MemoryUsagePercent") // NetworkRxBytesStat counts total bytes received over the network. NetworkRxBytesStat = StatType("NetworkRxBytes") // NetworkTxBytesStat counts total bytes sent over the network. NetworkTxBytesStat = StatType("NetworkTxBytes") // BlockReadBytesStat counts total bytes read from block devices. BlockReadBytesStat = StatType("BlockReadBytes") // BlockWriteBytesStat counts total bytes written to block devices. BlockWriteBytesStat = StatType("BlockWriteBytes") )
Variables ¶
var ( // ErrNotFound indicates an operation was attempted on a nonexistent container. ErrNotFound = errors.New("container not found") // ErrNotStarted indicates failure because a container hasn't started yet. ErrNotStarted = errors.New("container has not started") // ErrNotImplemented indicates the underlying runtime hasn't implemented a function. ErrNotImplemented = errors.New("not implemented") )
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container interface { Name() string Start(ctx context.Context) error Info(ctx context.Context) (*ContainerInfo, error) Logs(ctx context.Context, since time.Time) (logging.LogReader, error) Stats(ctx context.Context) (*ContainerStats, error) Stop(ctx context.Context, timeout *time.Duration) error Remove(ctx context.Context) error }
Container is a containerized process.
type ContainerInfo ¶
type ContainerInfo struct { Labels map[string]string CreatedAt time.Time StartedAt time.Time EndedAt time.Time Status ContainerStatus Message string ExitCode *int // Resource limits Memory int64 // In bytes CPUCount float64 TCPPorts []TCPPortBinding }
ContainerInfo describes a container's details.
type ContainerOpts ¶
type ContainerOpts struct { // (optional) Name to give the container; randomly generated if absent. Name string Image *DockerImage Command []string Arguments []string Env map[string]string Labels map[string]string Mounts []Mount // Attach STDIN/STDOUT/STDERR and shell into the container. Interactive bool // Memory is a hard limit on the amount of memory a container can use. // Expressed as a number of bytes. Memory int64 SharedMemory int64 // CPUCount is a hard limit on the number of CPUs a container can use. CPUCount float64 // Each container defaults to 1024 shares. During periods of CPU contention, CPU is limited // in proportion to the number of shares a container has e.g. a container with 2048 // shares can use twice as much CPU as one with 1024 shares. // // CPUShares are ignored in the Kubernetes runtime. // CPUShares take precedence over CPUCount in the Docker and CRI runtimes. CPUShares int64 // GPUs assigned to the container as IDs or indices. GPUs []string // (optional) User that will run commands inside the container. Also supports "user:group". // If not provided, the container is run as root. User string // (optional) Groups the container will run as. Groups []string // (optional) WorkingDir where the command will be launched. WorkingDir string // (optional) Container ports to be exposed on the host. A random, ephemeral // host port will be bound to each. Supports TCP only. TCPPorts []TCPPort // (optional) Hostname to use. Otherwise the default per the runtime is used. Hostname string }
ContainerOpts allows a caller to specify options during container creation.
func (*ContainerOpts) OomScoreAdj ¶
func (o *ContainerOpts) OomScoreAdj() int
OomScoreAdj returns a score from -1000 to 1000 that signals how important a process is. The OOM killer first scores processes by how much memory they are using. For example, a process using 50% of the machine's memory gets a score of 500. The score adjustment is then applied to figure out which process to kill. The higher the score, the more likely a process will be killed.
For example, take the two processes:
- 50% memory usage, -100 OOM score = 400 adjusted score
- 30% memory usage, 200 OOM score = 500 adjusted score
In this case process 2 will be killed even though it is using less memory.
type ContainerStats ¶
type ContainerStats struct { // Time marks the system time at which stats were sampled. Time time.Time // Stats describes all tracked container statistics, keyed by type. Not all // keys are guaranteed to be present. Stats map[StatType]float64 }
ContainerStats provides point-in-time usage statistics for system resources.
type ContainerStatus ¶
type ContainerStatus int
ContainerStatus describes the runtime status of a containerized process.
const ( // StatusCreated indicates a container has been created, but not started. StatusCreated ContainerStatus = iota // StatusRunning indicates a container is currently running. StatusRunning // StatusExited indicates a container exited. StatusExited )
func (ContainerStatus) String ¶
func (s ContainerStatus) String() string
String converts the container status to a human-readable string, useful for diagnostics.
type DockerImage ¶
type DockerImage struct { // (required) Tag is a docker image refspec, as a tag or resolvable image hash. Tag string // (optional) Auth contains credentials for private registry access. Auth *RegistryAuth }
DockerImage specifies a Docker-based container image.
type PullPolicy ¶
type PullPolicy string
PullPolicy enumerates options for pulling images.
const ( // PullAlways indicates an image should always be pulled even if already present. PullAlways PullPolicy = "always" // PullIfMissing pulls an image only if it doesn't exist locally. The local // image will not be updated if the remote version has changed. PullIfMissing PullPolicy = "missing" // PullNever validates that an image exists locally. It does not attempt to // pull the remote version, even if the image is missing. PullNever PullPolicy = "never" )
type RegistryAuth ¶
RegistryAuth describes credentials for private Docker registry access.
type Runtime ¶
type Runtime interface { io.Closer PullImage(ctx context.Context, image *DockerImage, policy PullPolicy, quiet bool) error CreateContainer(ctx context.Context, opts *ContainerOpts) (Container, error) ListContainers(ctx context.Context) ([]Container, error) }
Runtime abstracts the specifics of interacting with the underlying container runtime (e.g. Docker) for execution.
type TCPPort ¶
type TCPPort = int32
We use int32 because it makes it simple to interface with the database.