runtime

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package runtime - execute system calls in specific runtime environments

Index

Constants

View Source
const (
	// DefaultInMemoryWritableDirSize default memory-backed writable dir size in bytes (64 MiB)
	DefaultInMemoryWritableDirSize = int64(67108864)
	// DefaultContainerRunAsUser default container run-as user
	DefaultContainerRunAsUser = "nobody"
	// DefaultContainerRunAsGroup default container run-as group
	DefaultContainerRunAsGroup = "nogroup"
	// DefaultContainerWorkingDir default container working directory
	DefaultContainerWorkingDir = "/tmp"
	// DefaultContainerMemReservation default container memory reservation
	DefaultContainerMemReservation = "32m"
	// DefaultContainerMemLimit default container memory limit
	DefaultContainerMemLimit = "128m"
	// DefaultContainerStopSignal default signal used to stop the container process
	DefaultContainerStopSignal = goutils.ContainerStopSignalSIGINT
	// DefaultContainerTimeoutPolicy default packaging of a timeout into the result
	DefaultContainerTimeoutPolicy = goutils.ContainerTimeoutPolicyError
)

Default values applied for omitted container driver parameters.

View Source
const (
	// DefaultDockerNetworkMode default container network mode (no networking)
	DefaultDockerNetworkMode = "none"
	// DefaultDockerPortProtocol default published port protocol
	DefaultDockerPortProtocol = "tcp"
	// DefaultDockerPublishHostIP default host interface a published port binds to
	DefaultDockerPublishHostIP = "127.0.0.1"
)

Default values applied for omitted docker driver parameters.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerCommand

type ContainerCommand struct {
	// Entrypoint container entrypoint
	Entrypoint []string `json:"entrypoint" validate:"required,gte=1" jsonschema:"container entrypoint; required and must contain at least one element"`
	// Commands ran by the entry point
	Commands []string `json:"commands,omitempty" validate:"-" jsonschema:"the arguments passed to the entrypoint"`
}

ContainerCommand the command to execute in a container runtime

type ContainerEnvVar

type ContainerEnvVar struct {
	// Name the environment variable name
	Name string `json:"name" validate:"required" jsonschema:"the environment variable name; required"`
	// Value the environment variable value
	Value string `json:"value" jsonschema:"the environment variable value; may be an empty string"`
}

ContainerEnvVar an environment variable set on the container process

type ContainerExtraHost

type ContainerExtraHost struct {
	// Hosts the hostname to map
	Hosts []string `` /* 129-byte string literal not displayed */
	// Address the IP address the hostname resolves to
	Address string `` /* 131-byte string literal not displayed */
}

ContainerExtraHost an extra host-to-IP mapping injected into the container's /etc/hosts

type ContainerHostMount

type ContainerHostMount struct {
	// Path host path to mount
	Path string `json:"path" validate:"required" jsonschema:"the host path to mount; required and must be an absolute path"`
	// ReadOnly whether to mount the path read-only; defaults to true when nil
	ReadOnly *bool `json:"read_only,omitempty" jsonschema:"whether to mount the path read-only; defaults to true when omitted"`
	// MountPath path within the container to mount the host path. The mount path will
	// mirror the host path if this is not specified.
	MountPath *string `` /* 137-byte string literal not displayed */
}

ContainerHostMount a host path bind-mounted into the container

func (ContainerHostMount) GetMountPath

func (m ContainerHostMount) GetMountPath() string

GetMountPath get the in-container mount path

func (ContainerHostMount) IsReadOnly

func (m ContainerHostMount) IsReadOnly() bool

IsReadOnly resolve ReadOnly, defaulting to true when unset

type ContainerRuntimeParams

type ContainerRuntimeParams struct {
	// Image container image reference to run
	Image string `json:"image" validate:"required" jsonschema:"container image reference to run; required"`

	// Streaming when streaming STDIN, STDERR, and STDOUT to and from the container,
	// additional configurations needed for streaming.
	Streaming *StreamIOParams `` /* 197-byte string literal not displayed */

	// MemReservation soft memory reservation (e.g. "32m"); defaults when empty
	MemReservation string `json:"mem_reservation,omitempty" jsonschema:"soft memory reservation (e.g. '32m'); defaults to '32m' when omitted"`
	// MemLimit hard memory limit (e.g. "128m"); defaults when empty
	MemLimit string `json:"mem_limit,omitempty" jsonschema:"hard memory limit (e.g. '128m'); defaults to '128m' when omitted"`

	// WorkingDir working directory for the container process; defaults to DefaultContainerWorkingDir
	WorkingDir string `json:"working_dir,omitempty" jsonschema:"working directory for the container process; defaults to '/tmp' when omitted"`

	// WritableDirs memory-backed writable directories overlaid on the read-only rootfs
	WritableDirs []InMemoryWritableDir `` /* 137-byte string literal not displayed */
	// HostMounts host paths bind-mounted into the container
	HostMounts []ContainerHostMount `json:"host_mounts,omitempty" validate:"omitempty,dive" jsonschema:"host paths bind-mounted into the container"`
	// VolumeMounts named persistent volumes / PVCs mounted into the container. The volumes
	// themselves are provisioned by the runtime's controller client, not by this spec.
	VolumeMounts []ContainerVolumeMount `` /* 221-byte string literal not displayed */

	// AddCapabilities Linux capabilities to add back on top of the dropped-by-default set
	// (e.g. NET_BIND_SERVICE to bind ports below 1024)
	AddCapabilities []string `` /* 155-byte string literal not displayed */

	// ExtraHosts additional host-to-IP mappings for the container
	ExtraHosts []ContainerExtraHost `json:"extra_hosts,omitempty" validate:"omitempty,dive" jsonschema:"additional host-to-IP mappings for the container"`
	// Environment additional environment variables for the container process
	Environment []ContainerEnvVar `` /* 126-byte string literal not displayed */

	// StopSignal signal sent to request the container process stop during teardown;
	// defaults to DefaultContainerStopSignal when empty
	StopSignal goutils.ContainerStopSignalENUMType `` /* 183-byte string literal not displayed */

	// TimeoutSecs wall-clock timeout in seconds; clamped to the server ceiling. 0 (unset)
	// means clamp to the server ceiling (treated as +infinity before the min).
	TimeoutSecs int `` /* 192-byte string literal not displayed */
	// TimeoutPolicy how a timeout is packaged into the result; defaults to
	// DefaultContainerTimeoutPolicy when empty
	TimeoutPolicy goutils.ContainerTimeoutPolicyENUMType `` /* 192-byte string literal not displayed */

	// ReadOnlyRootFS mount the container root filesystem read-only; defaults to true when nil
	ReadOnlyRootFS *bool `json:"read_only_rootfs,omitempty" jsonschema:"mount the container root filesystem read-only; defaults to true when omitted"`
	// DropAllCapabilities drop all Linux capabilities; defaults to true when nil
	DropAllCapabilities *bool `json:"drop_all_caps,omitempty" jsonschema:"drop all Linux capabilities; defaults to true when omitted"`
	// NoNewPrivileges set the no-new-privileges security option; defaults to true when nil
	NoNewPrivileges *bool `json:"no_new_privileges,omitempty" jsonschema:"set the no-new-privileges security option; defaults to true when omitted"`
}

ContainerRuntimeParams parameters common to any container-orchestrating runtime (Docker containers, Kubernetes Jobs, ...). Each field maps onto a Pod/Container spec plus its security context, so runtime-specific params (e.g. DockerRuntimeParams) embed this base and add only the fields with no cross-runtime equivalent.

func (ContainerRuntimeParams) IsDropAllCapabilities

func (p ContainerRuntimeParams) IsDropAllCapabilities() bool

IsDropAllCapabilities resolve DropAllCapabilities, defaulting to true when unset

func (ContainerRuntimeParams) IsNoNewPrivileges

func (p ContainerRuntimeParams) IsNoNewPrivileges() bool

IsNoNewPrivileges resolve NoNewPrivileges, defaulting to true when unset

func (ContainerRuntimeParams) IsReadOnlyRootFS

func (p ContainerRuntimeParams) IsReadOnlyRootFS() bool

IsReadOnlyRootFS resolve ReadOnlyRootFS, defaulting to true when unset

func (ContainerRuntimeParams) IsStreaming

func (p ContainerRuntimeParams) IsStreaming() bool

IsStreaming whether runtime setup for streaming

func (ContainerRuntimeParams) ResolvedStopSignal

ResolvedStopSignal resolve StopSignal, defaulting when empty

func (ContainerRuntimeParams) ResolvedTimeoutPolicy

ResolvedTimeoutPolicy resolve TimeoutPolicy, defaulting when empty

func (ContainerRuntimeParams) Timeout

func (p ContainerRuntimeParams) Timeout() time.Duration

Timeout convert `TimeoutSecs` to `time.Duration`

func (ContainerRuntimeParams) ValidateMounts

func (p ContainerRuntimeParams) ValidateMounts() error

ValidateMounts verify every mount path is absolute, as required by the container runtime: the in-container target of each writable dir, host mount, and volume mount, and the host-side source of each host mount. A named volume mount's source is a name rather than a path, so it is not path-checked here. Intended to run before the runtime builds its container config so a malformed mount fails fast.

type ContainerVolume

type ContainerVolume struct {
	// Name identity of the volume / PVC
	Name string `json:"name" validate:"required" jsonschema:"identity of the volume / PVC; required"`
	// Size requested capacity in bytes. Honored by Kubernetes (storage request) and by
	// capacity-aware Docker volume drivers; the default Docker "local" driver treats it as
	// advisory.
	Size int64 `` /* 249-byte string literal not displayed */
}

ContainerVolume the shared minimum to request a persistent volume (Docker volume) / PersistentVolumeClaim (Kubernetes). The runtime-specific provisioning (Docker driver + opts, Kubernetes access modes + storage class) lives in the per-runtime controller client, not here.

type ContainerVolumeMount

type ContainerVolumeMount struct {
	// Name the ContainerVolume / PVC name to mount
	Name string `json:"name" validate:"required" jsonschema:"the ContainerVolume / PVC name to mount; required"`
	// MountPath path within the container to mount at
	MountPath string `` /* 140-byte string literal not displayed */
	// ReadOnly whether to mount read-only; defaults to false when nil. Unlike a host mount,
	// a persistent volume exists to be written to, so read-write is the sensible default.
	ReadOnly *bool `` /* 203-byte string literal not displayed */
}

ContainerVolumeMount mounts a named ContainerVolume / PVC into the container.

func (ContainerVolumeMount) IsReadOnly

func (m ContainerVolumeMount) IsReadOnly() bool

IsReadOnly resolve ReadOnly, defaulting to false when unset

type DockerPortPublish

type DockerPortPublish struct {
	// ContainerPort the port the session command listens on inside the container
	ContainerPort uint16 `` /* 148-byte string literal not displayed */
	// Protocol the port protocol; defaults to DefaultContainerPortProtocol when empty
	Protocol string `` /* 154-byte string literal not displayed */
	// HostPort the host port to bind; 0 requests an ephemeral host port
	HostPort uint16 `json:"host_port,omitempty" jsonschema:"the host port to bind, in 1-65535; omit (0) to request an ephemeral host port"`
	// HostIP the host interface to bind to; defaults to DefaultContainerPublishHostIP when empty
	HostIP string `` /* 166-byte string literal not displayed */
}

DockerPortPublish publishes a container port to a host interface so the session command can accept inbound connections

func (DockerPortPublish) ResolvedHostIP

func (p DockerPortPublish) ResolvedHostIP() string

ResolvedHostIP resolve HostIP, defaulting when empty

func (DockerPortPublish) ResolvedProtocol

func (p DockerPortPublish) ResolvedProtocol() string

ResolvedProtocol resolve Protocol, defaulting when empty

type DockerRuntimeParams

type DockerRuntimeParams struct {
	ContainerRuntimeParams

	// RunAsUser user to run the container process as; defaults to DefaultContainerRunAsUser
	RunAsUser string `json:"run_as_user,omitempty" jsonschema:"user to run the container process as; defaults to 'nobody' when omitted"`
	// RunAsGroup group to run the container process as; defaults to DefaultContainerRunAsGroup
	RunAsGroup string `json:"run_as_group,omitempty" jsonschema:"group to run the container process as; defaults to 'nogroup' when omitted"`

	// NetworkMode the container network mode (e.g. "none", "bridge"); defaults to
	// DefaultDockerNetworkMode. Must be routable when PublishPorts is set.
	NetworkMode string `` /* 183-byte string literal not displayed */
	// PublishPorts container ports published to the host for inbound connections
	PublishPorts []DockerPortPublish `` /* 165-byte string literal not displayed */

	// RemoveOnExit remove the container on teardown; defaults to true when nil
	RemoveOnExit *bool `json:"remove_on_exit,omitempty" jsonschema:"remove the container on teardown; defaults to true when omitted"`
}

DockerRuntimeParams parameters for a Docker container runtime. It embeds the cross-runtime ContainerRuntimeParams and adds only the fields with no Kubernetes-Job equivalent (Docker daemon networking, host port publishing, container lifecycle) plus the string-valued run-as user/group (Kubernetes requires numeric UIDs/GIDs).

func (DockerRuntimeParams) IsRemoveOnExit

func (p DockerRuntimeParams) IsRemoveOnExit() bool

IsRemoveOnExit resolve RemoveOnExit, defaulting to true when unset

type DockerVolumeMetadata

type DockerVolumeMetadata struct {
	// Driver the volume driver to provision with (e.g. "local"); defaults to the daemon's
	// default driver when empty
	Driver string `json:"driver,omitempty"`
	// DriverOpts driver-specific options (e.g. "type", "device", "o" for the local driver)
	DriverOpts map[string]string `json:"driver_opts,omitempty"`
	// Labels user-defined key/value metadata applied to the volume
	Labels map[string]string `json:"labels,omitempty"`
}

DockerVolumeMetadata Docker-specific provisioning parameters passed as the `metadata` argument to VolumeManager.DefineVolume for a dockerVolumeManager. It carries the volume driver, its driver options, and labels; a zero value provisions a default "local" volume.

type InMemoryWritableDir

type InMemoryWritableDir struct {
	// Path the directory within the container to back with the memory-backed writable mount
	Path string `` /* 178-byte string literal not displayed */
	// SizeLimit size of the mount in bytes; defaults to DefaultInMemoryWritableDirSize when 0
	SizeLimit int64 `` /* 159-byte string literal not displayed */
}

InMemoryWritableDir a memory-backed writable directory overlaid on the (otherwise read-only) container rootfs. Backed by a tmpfs mount on Docker and by an emptyDir{medium: Memory} on Kubernetes.

func (InMemoryWritableDir) Size

func (m InMemoryWritableDir) Size() int64

Size resolve SizeLimit, defaulting when unset

type StreamIOParams

type StreamIOParams struct {
	// DisplayRows TTY number of rows (in cells).
	DisplayRows uint16 `json:"display_rows" validate:"gte=30" jsonschema:"TTY number of rows (in cells); must be >= 30"`
	// DisplayCols TTY number of columns (in cells).
	DisplayCols uint16 `json:"display_cols" validate:"gte=80" jsonschema:"TTY number of columns (in cells); must be >= 80"`
}

StreamIOParams settings for when streaming STDIN, STDERR, and STDOUT to and from the container

type SystemCallResp

type SystemCallResp struct {
	// ExitCode the wrapped program's exit code.
	ExitCode int `json:"exit_code"`
	// Output the combined STDOUT+STDERR captured from the program in execution order
	Output string `json:"output"`
}

SystemCallResp the fixed structured result for every runtime: the wrapped program's exit code and its combined output.

type SystemCallRuntime

type SystemCallRuntime interface {
	/*
		Start launch the runtime and begin executing the system cll

			@param ctx context.Context - execution context
	*/
	Start(ctx context.Context) error

	/*
		PipeInput only usable on runtimes configured with streaming, stream data from `input`
		into the runtime's STDIN until EOF.

			@param ctx context.Context - execution context
	*/
	PipeInput(input io.Reader) error

	/*
		PipeOutput only usable on runtimes configured with streaming, stream data from runtime
		STDERR and STDOUT to `output` until EOF

			@param ctx context.Context - execution context
	*/
	PipeOutput(output io.Writer) error

	/*
		Wait for the runtime to finish or time out, then collect the exit code and combined output.

			@param ctx context.Context - execution context
			@returns the execution result process status code and combined output
	*/
	Wait(ctx context.Context) (SystemCallResp, error)

	/*
		Cleanup tear down the runtime. For container backed runtimes that are configured with
		RemoveOnExit, the container associated with this runtime is removed; otherwise this
		is a NOOP beyond releasing internal resources.

			@param ctx context.Context - execution context
			@returns error if cleanup failed
	*/
	Cleanup(ctx context.Context) error
}

SystemCallRuntime system call runtime operator. This will execute the system call with in runtime supported by the implementation.

func NewDockerSystemCallRuntime

func NewDockerSystemCallRuntime(
	_ context.Context,
	name string,
	command ContainerCommand,
	params DockerRuntimeParams,
	clearANSIFromOutput bool,
) (SystemCallRuntime, error)

NewDockerSystemCallRuntime define a new Docker-container-backed system call runtime for a single system call. The runtime generates its own ULID instance ID and does not touch Docker until Start is called.

@param ctx context.Context - execution context (used for log-tag derivation)
@param name string - a descriptive name for the runtime
@param command ContainerCommandParams - the command to execute within the container
@param params DockerRuntimeParams - docker runtime parameter
@param clearANSIFromOutput bool - whether to remove ANSI escape sequences from output
    when returning system call output
@returns the new runtime

type VolumeManager

type VolumeManager interface {
	/*
		Start perform any initialization the manager needs before serving volume operations
		(e.g. establishing the Docker client connection).

			@param ctxt context.Context - the operational context
	*/
	Start(ctxt context.Context) error

	/*
		Cleanup release any resources the manager acquired in Start (e.g. closing the Docker
		client connection).

			@param ctxt context.Context - the operational context
	*/
	Cleanup(ctxt context.Context) error

	/*
		ListVolumes list the managed volumes, optionally restricted to those whose name
		carries a given prefix.

			@param ctxt context.Context - the operational context
			@param namePrefix *string - only volumes whose name starts with this prefix are
			    returned; an empty string returns all volumes
			@returns the matching volumes
	*/
	ListVolumes(ctxt context.Context, namePrefix *string) ([]ContainerVolume, error)

	/*
		GetVolume find a specific volume by name, returning it along with the identities of the
		entities that currently mount it (container names/IDs for Docker, pod names for
		Kubernetes). Returns a not-found error when no volume by that name exists.

			@param ctxt context.Context - the operational context
			@param name string - the volume name
			@returns the volume, and the identities of the entities currently mounting it
	*/
	GetVolume(ctxt context.Context, name string) (ContainerVolume, []string, error)

	/*
		DefineVolume create a new volume.

			@param ctxt context.Context - the operational context
			@param volume ContainerVolume - the volume to create
			@param metadata any - manager-specific provisioning parameters (e.g. Docker driver
			    and driver options); the concrete type is defined by the implementation
			@returns the created volume
	*/
	DefineVolume(ctxt context.Context, volume ContainerVolume, metadata any) (ContainerVolume, error)

	/*
		DeleteVolume delete a volume by name. Deleting a volume that does not exist is a
		no-op success (idempotent).

			@param ctxt context.Context - the operational context
			@param name string - the volume name
	*/
	DeleteVolume(ctxt context.Context, name string) error
}

VolumeManager a controller client that manages persistent volumes for a runtime (Docker volumes, Kubernetes PersistentVolumeClaims, ...). It provisions and inspects the volumes that a ContainerRuntimeParams.VolumeMounts entry refers to by name.

Start must be called before any volume operation and Cleanup once the manager is no longer needed; the manager owns whatever client/connection it establishes in Start.

func NewDockerVolumeManager

func NewDockerVolumeManager(_ context.Context) (VolumeManager, error)

NewDockerVolumeManager define a new Docker-volume-backed VolumeManager. The manager does not touch Docker until Setup is called, and owns the client it then establishes.

@param ctxt context.Context - execution context (used for log-tag derivation)
@returns the new volume manager

Jump to

Keyboard shortcuts

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