Help us shape the future of Go! Take the 2026 Go Developer Survey

dockerrun

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package dockerrun ties the Docker resources a crossplane-diff run creates — function containers, the render container and the render network — to that run, and reclaims the ones left behind by runs that died without cleaning up (SIGKILL, OOM, a second Ctrl+C, a CI runner tearing down the job).

Ownership is carried by labels. A run's ID is the session ID it hands the upstream render engine (render.EngineFlags.SessionID), which labels every container and network the engine creates render.crossplane.io/session=<run ID>, alongside render.crossplane.io/managed-by=crossplane-cli. A run's resources are exactly the ones carrying both labels with its ID, so a container or network that lacks either, such as one created before session labels existed, is never touched.

Liveness is a lease: a run holds an exclusive lock on "<run ID>.lock" in the user's cache directory for as long as it has resources. The operating system drops the lock when the process exits however it exits, so a lease file whose lock can be taken belongs to a dead run. That needs no process table, cannot be fooled by PID reuse, and keeps concurrent runs — other worktrees, other test processes — from touching each other's resources. A lease that is not in this user's cache directory (another user, another container sharing the Docker socket) is never seen, so its resources are never touched.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLeaseDir

func DefaultLeaseDir() string

DefaultLeaseDir is where runs keep their leases: a per-user directory, so one user's runs never judge another's. It returns "" when the user has no cache directory, which disables leasing and reaping.

Types

type Docker

type Docker interface {
	ContainerList(ctx context.Context, options client.ContainerListOptions) (client.ContainerListResult, error)
	ContainerRemove(ctx context.Context, containerID string, options client.ContainerRemoveOptions) (client.ContainerRemoveResult, error)
	NetworkList(ctx context.Context, options client.NetworkListOptions) (client.NetworkListResult, error)
	NetworkRemove(ctx context.Context, networkID string, options client.NetworkRemoveOptions) (client.NetworkRemoveResult, error)
	Close() error
}

Docker is the subset of the Docker API client a Run uses.

func NewDockerClient

func NewDockerClient() (Docker, error)

NewDockerClient returns a Docker API client configured from the environment, the same way the upstream render engine configures its own.

type Run

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

Run is one crossplane-diff run's claim on the Docker resources it creates. It is not safe for concurrent use; the render engine that owns it serializes access.

func New

func New(dir string, newDocker func() (Docker, error), log logging.Logger) *Run

New returns a Run that keeps its lease in dir ("" disables leasing and reaping) and talks to Docker through a client from newDocker. New does no I/O.

func (*Run) Close

func (r *Run) Close(ctx context.Context, release func())

Close removes every container this run created, calls release, then removes every network of the run still left and gives up its lease. release is the render engine's own cleanup: it removes the network the engine created, which it can only do once no container is attached, so it runs between the two. Close removes what upstream cleanup should already have removed too, so a container or network upstream leaves behind does not outlive the run. If anything cannot be removed the lease file is kept, so the next run reclaims it, and a warning is raised. On a run that is not started, Close only calls release.

func (*Run) ID

func (r *Run) ID() string

ID is the run's ID. It must be the render engine's session ID: the session label is what makes a container or network this run's.

func (*Run) Start

func (r *Run) Start(ctx context.Context) error

Start prepares the run to create Docker resources; call it before starting any. It takes the run's lease and reclaims what dead runs left behind. Both are best effort: a failure there is at most a warning. Only failing to create a Docker client is an error. Start is a no-op on a started run.

Jump to

Keyboard shortcuts

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