Documentation ¶
Overview ¶
Package container provides an interface for interacting with Docker and potentially other container runtimes.
Index ¶
- func RuntimeInto(ctx context.Context, runtime Runtime) context.Context
- type Container
- type ExecContainerArgs
- type ExecContainerInput
- type FakeRuntime
- func (f *FakeRuntime) ContainerDebugInfo(_ context.Context, _ string, _ io.Writer) error
- func (f *FakeRuntime) DeleteContainer(_ context.Context, containerName string) error
- func (f *FakeRuntime) DeleteContainerCalls() []string
- func (f *FakeRuntime) ExecContainer(_ context.Context, containerName string, config *ExecContainerInput, ...) error
- func (f *FakeRuntime) ExecContainerCalls() []ExecContainerArgs
- func (f *FakeRuntime) GetContainerIPs(_ context.Context, containerName string) (string, string, error)
- func (f *FakeRuntime) GetHostPort(_ context.Context, _, _ string) (string, error)
- func (f *FakeRuntime) ImageExistsLocally(_ context.Context, _ string) (bool, error)
- func (f *FakeRuntime) KillContainer(_ context.Context, containerName, signal string) error
- func (f *FakeRuntime) KillContainerCalls() []KillContainerArgs
- func (f *FakeRuntime) ListContainers(_ context.Context, _ FilterBuilder) ([]Container, error)
- func (f *FakeRuntime) PullContainerImage(_ context.Context, _ string) error
- func (f *FakeRuntime) PullContainerImageIfNotExists(_ context.Context, _ string) error
- func (f *FakeRuntime) ResetDeleteContainerCallLogs()
- func (f *FakeRuntime) ResetExecContainerCallLogs()
- func (f *FakeRuntime) ResetKillContainerCallLogs()
- func (f *FakeRuntime) ResetRunContainerCallLogs()
- func (f *FakeRuntime) RunContainer(_ context.Context, runConfig *RunContainerInput, output io.Writer) error
- func (f *FakeRuntime) RunContainerCalls() []RunContainerArgs
- func (f *FakeRuntime) SaveContainerImage(_ context.Context, _, _ string) error
- type FilterBuilder
- type KillContainerArgs
- type Mount
- type PortMapping
- type RunContainerArgs
- type RunContainerInput
- type Runtime
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Container ¶ added in v0.4.1
type Container struct { // Name is the name of the container Name string // Image is the name of the container's image Image string // Status is the status of the container Status string }
Container represents a runtime container.
type ExecContainerArgs ¶ added in v1.1.0
type ExecContainerArgs struct { ContainerName string Config *ExecContainerInput Command string Args []string }
ExecContainerArgs contains the arguments passed to calls to ExecContainer.
type ExecContainerInput ¶ added in v0.4.1
type ExecContainerInput struct { // OutputBuffer receives the stdout of the execution. OutputBuffer io.Writer // ErrorBuffer receives the stderr of the execution. ErrorBuffer io.Writer // InputBuffer contains stdin or nil if no input. InputBuffer io.Reader // EnvironmentVars is a collection of name=values to pass as environment variables in the container. EnvironmentVars []string }
ExecContainerInput contains values for running exec on a container.
type FakeRuntime ¶ added in v1.1.0
type FakeRuntime struct { }
func (*FakeRuntime) ContainerDebugInfo ¶ added in v1.1.0
ContainerDebugInfo gets the container metadata and logs from the runtime (docker inspect, docker logs).
func (*FakeRuntime) DeleteContainer ¶ added in v1.1.0
func (f *FakeRuntime) DeleteContainer(_ context.Context, containerName string) error
DeleteContainer will remove a container, forcing removal if still running.
func (*FakeRuntime) DeleteContainerCalls ¶ added in v1.1.0
func (f *FakeRuntime) DeleteContainerCalls() []string
DeleteContainerCalls returns the list of containerName arguments passed to calls to DeleteContainer.
func (*FakeRuntime) ExecContainer ¶ added in v1.1.0
func (f *FakeRuntime) ExecContainer(_ context.Context, containerName string, config *ExecContainerInput, command string, args ...string) error
ExecContainer executes a command in a running container and writes any output to the provided writer.
func (*FakeRuntime) ExecContainerCalls ¶ added in v1.1.0
func (f *FakeRuntime) ExecContainerCalls() []ExecContainerArgs
ExecContainerCalls returns the set of arguments that have been passed to the ExecContainer method. This can be used by test code to validate the expected input.
func (*FakeRuntime) GetContainerIPs ¶ added in v1.1.0
func (f *FakeRuntime) GetContainerIPs(_ context.Context, containerName string) (string, string, error)
GetContainerIPs inspects a container to get its IPv4 and IPv6 IP addresses. Will not error if there is no IP address assigned. Calling code will need to determine whether that is an issue or not.
func (*FakeRuntime) GetHostPort ¶ added in v1.1.0
GetHostPort looks up the host port bound for the port and protocol (e.g. "6443/tcp").
func (*FakeRuntime) ImageExistsLocally ¶ added in v1.2.0
ImageExistsLocally returns if the specified image exists in local container image cache.
func (*FakeRuntime) KillContainer ¶ added in v1.1.0
func (f *FakeRuntime) KillContainer(_ context.Context, containerName, signal string) error
KillContainer will kill a running container with the specified signal.
func (*FakeRuntime) KillContainerCalls ¶ added in v1.1.0
func (f *FakeRuntime) KillContainerCalls() []KillContainerArgs
KillContainerCalls returns the list of arguments passed to calls to the KillContainer method.
func (*FakeRuntime) ListContainers ¶ added in v1.1.0
func (f *FakeRuntime) ListContainers(_ context.Context, _ FilterBuilder) ([]Container, error)
ListContainers returns a list of all containers.
func (*FakeRuntime) PullContainerImage ¶ added in v1.2.0
func (f *FakeRuntime) PullContainerImage(_ context.Context, _ string) error
PullContainerImage triggers the Docker engine to pull an image.
func (*FakeRuntime) PullContainerImageIfNotExists ¶ added in v1.1.0
func (f *FakeRuntime) PullContainerImageIfNotExists(_ context.Context, _ string) error
PullContainerImageIfNotExists triggers the Docker engine to pull an image, but only if it doesn't already exist. This is important when we're using locally built images in CI which do not exist remotely.
func (*FakeRuntime) ResetDeleteContainerCallLogs ¶ added in v1.1.0
func (f *FakeRuntime) ResetDeleteContainerCallLogs()
ResetDeleteContainerCallLogs clears all existing records of any calls to the DeleteContainer method.
func (*FakeRuntime) ResetExecContainerCallLogs ¶ added in v1.1.0
func (f *FakeRuntime) ResetExecContainerCallLogs()
ResetExecContainerCallLogs clears all existing records of any calls to the ExecContainer method.
func (*FakeRuntime) ResetKillContainerCallLogs ¶ added in v1.1.0
func (f *FakeRuntime) ResetKillContainerCallLogs()
ResetKillContainerCallLogs clears all existing records of any calls to the KillContainer method.
func (*FakeRuntime) ResetRunContainerCallLogs ¶ added in v1.1.0
func (f *FakeRuntime) ResetRunContainerCallLogs()
ResetRunContainerCallLogs clears all existing records of calls to the RunContainer method.
func (*FakeRuntime) RunContainer ¶ added in v1.1.0
func (f *FakeRuntime) RunContainer(_ context.Context, runConfig *RunContainerInput, output io.Writer) error
RunContainer will run a docker container with the given settings and arguments, returning any errors.
func (*FakeRuntime) RunContainerCalls ¶ added in v1.1.0
func (f *FakeRuntime) RunContainerCalls() []RunContainerArgs
RunContainerCalls returns a list of arguments passed in to all calls to RunContainer.
func (*FakeRuntime) SaveContainerImage ¶ added in v1.1.0
func (f *FakeRuntime) SaveContainerImage(_ context.Context, _, _ string) error
SaveContainerImage saves a Docker image to the file specified by dest.
type FilterBuilder ¶ added in v0.4.1
FilterBuilder is a helper for building up filter strings of "key=value" or "key=name=value".
func (FilterBuilder) AddKeyNameValue ¶ added in v0.4.1
func (f FilterBuilder) AddKeyNameValue(key, name, value string)
AddKeyNameValue adds a filter with a name=value (--filter "label=io.x-k8s.kind.cluster=quick-start-n95t5z").
func (FilterBuilder) AddKeyValue ¶ added in v0.4.1
func (f FilterBuilder) AddKeyValue(key, value string)
AddKeyValue adds a filter with a single name (--filter "label=io.x-k8s.kind.cluster").
type KillContainerArgs ¶ added in v1.1.0
KillContainerArgs contains the arguments passed to calls to Kill.
type Mount ¶ added in v0.4.1
type Mount struct { // Source is the source host path to mount. Source string // Target is the path to mount in the container. Target string // ReadOnly specifies if the mount should be mounted read only. ReadOnly bool }
Mount contains mount details.
type PortMapping ¶ added in v0.4.1
type PortMapping struct { // ContainerPort is the port in the container to map to. ContainerPort int32 // HostPort is the port to expose on the host. HostPort int32 // ListenAddress is the address to bind to. ListenAddress string // Protocol is the protocol (tcp, udp, etc.) to use. Protocol string }
PortMapping contains port mapping information for the container.
type RunContainerArgs ¶ added in v1.1.0
type RunContainerArgs struct { RunConfig *RunContainerInput Output io.Writer }
RunContainerArgs contains the arguments passed to calls to RunContainer.
type RunContainerInput ¶
type RunContainerInput struct { // Image is the name of the image to run. Image string // Name is the name to set for the container. Name string // Network is the name of the network to connect to. Network string // User is the user name to run as. User string // Group is the user group to run as. Group string // Volumes is a collection of any volumes (docker's "-v" arg) to mount in the container. Volumes map[string]string // Tmpfs is the temporary filesystem mounts to add. Tmpfs map[string]string // Mount contains mount information for the container. Mounts []Mount // EnvironmentVars is a collection of name/values to pass as environment variables in the container. EnvironmentVars map[string]string // CommandArgs is the command and any additional arguments to execute in the container. CommandArgs []string // Entrypoint defines the entry point to use. Entrypoint []string // Labels to apply to the container. Labels map[string]string // PortMappings contains host<>container ports to map. PortMappings []PortMapping // IPFamily is the IP version to use. IPFamily clusterv1.ClusterIPFamily // RestartPolicy to use for the container. // If not set, defaults to RestartPolicyUnlessStopped. RestartPolicy dockercontainer.RestartPolicyMode // Defines how the kindest/node image must be started. KindMode kind.Mode }
RunContainerInput holds the configuration settings for running a container.
type Runtime ¶ added in v0.4.1
type Runtime interface { SaveContainerImage(ctx context.Context, image, dest string) error PullContainerImageIfNotExists(ctx context.Context, image string) error PullContainerImage(ctx context.Context, image string) error ImageExistsLocally(ctx context.Context, image string) (bool, error) GetHostPort(ctx context.Context, containerName, portAndProtocol string) (string, error) GetContainerIPs(ctx context.Context, containerName string) (string, string, error) ExecContainer(ctx context.Context, containerName string, config *ExecContainerInput, command string, args ...string) error RunContainer(ctx context.Context, runConfig *RunContainerInput, output io.Writer) error ListContainers(ctx context.Context, filters FilterBuilder) ([]Container, error) ContainerDebugInfo(ctx context.Context, containerName string, w io.Writer) error DeleteContainer(ctx context.Context, containerName string) error KillContainer(ctx context.Context, containerName, signal string) error }
Runtime defines the interface for interacting with a container runtime.
func NewDockerClient ¶
NewDockerClient gets a client for interacting with a Docker container runtime.
func NewFakeClient ¶ added in v1.1.0
NewFakeClient gets a client for testing.