daemon

package
v20.10.8+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: Apache-2.0 Imports: 30 Imported by: 74

Documentation

Overview

Package daemon launches dockerd for testing purposes.

Index

Constants

View Source
const (
	// DefaultSwarmPort is the default port use for swarm in the tests
	DefaultSwarmPort = 2477
)

Variables

View Source
var SockRoot = filepath.Join(os.TempDir(), "docker-integration")

SockRoot holds the path of the default docker integration daemon socket

Functions

func SignalDaemonDump

func SignalDaemonDump(pid int)

SignalDaemonDump sends a signal to the daemon to write a dump file

Types

type ConfigConstructor

type ConfigConstructor func(*swarm.Config)

ConfigConstructor defines a swarm config constructor

type Daemon

type Daemon struct {
	Root              string
	Folder            string
	Wait              chan error
	UseDefaultHost    bool
	UseDefaultTLSHost bool

	SwarmPort       int // FIXME(vdemeester) should probably not be exported
	DefaultAddrPool []string
	SubnetSize      uint32
	DataPathPort    uint32
	OOMScoreAdjust  int
	// cached information
	CachedInfo types.Info
	// contains filtered or unexported fields
}

Daemon represents a Docker daemon for the testing framework

func New

func New(t testing.TB, ops ...Option) *Daemon

New returns a Daemon instance to be used for testing. This will create a directory such as d123456789 in the folder specified by $DOCKER_INTEGRATION_DAEMON_DEST or $DEST. The daemon will not automatically start.

func NewDaemon

func NewDaemon(workingDir string, ops ...Option) (*Daemon, error)

NewDaemon returns a Daemon instance to be used for testing. The daemon will not automatically start. The daemon will modify and create files under workingDir.

func (*Daemon) ActiveContainers

func (d *Daemon) ActiveContainers(t testing.TB) []string

ActiveContainers returns the list of ids of the currently running containers

func (*Daemon) CgroupNamespace

func (d *Daemon) CgroupNamespace(t testing.TB) string

CgroupNamespace returns the cgroup namespace the daemon is running in

func (*Daemon) Cleanup

func (d *Daemon) Cleanup(t testing.TB)

Cleanup cleans the daemon files : exec root (network namespaces, ...), swarmkit files

func (*Daemon) ContainersNamespace

func (d *Daemon) ContainersNamespace() string

ContainersNamespace returns the containerd namespace used for containers.

func (*Daemon) CreateConfig

func (d *Daemon) CreateConfig(t testing.TB, configSpec swarm.ConfigSpec) string

CreateConfig creates a config given the specified spec

func (*Daemon) CreateSecret

func (d *Daemon) CreateSecret(t testing.TB, secretSpec swarm.SecretSpec) string

CreateSecret creates a secret given the specified spec

func (*Daemon) CreateService

func (d *Daemon) CreateService(t testing.TB, f ...ServiceConstructor) string

CreateService creates a swarm service given the specified service constructor

func (*Daemon) DeleteConfig

func (d *Daemon) DeleteConfig(t testing.TB, id string)

DeleteConfig removes the swarm config identified by the specified id

func (*Daemon) DeleteSecret

func (d *Daemon) DeleteSecret(t testing.TB, id string)

DeleteSecret removes the swarm secret identified by the specified id

func (*Daemon) DumpStackAndQuit

func (d *Daemon) DumpStackAndQuit()

DumpStackAndQuit sends SIGQUIT to the daemon, which triggers it to dump its stack to its log file and exit This is used primarily for gathering debug information on test timeout

func (*Daemon) FindContainerIP

func (d *Daemon) FindContainerIP(t testing.TB, id string) string

FindContainerIP returns the ip of the specified container

func (*Daemon) GetConfig

func (d *Daemon) GetConfig(t testing.TB, id string) *swarm.Config

GetConfig returns a swarm config identified by the specified id

func (*Daemon) GetNode

func (d *Daemon) GetNode(t testing.TB, id string, errCheck ...func(error) bool) *swarm.Node

GetNode returns a swarm node identified by the specified id

func (*Daemon) GetSecret

func (d *Daemon) GetSecret(t testing.TB, id string) *swarm.Secret

GetSecret returns a swarm secret identified by the specified id

func (*Daemon) GetService

func (d *Daemon) GetService(t testing.TB, id string) *swarm.Service

GetService returns the swarm service corresponding to the specified id

func (*Daemon) GetServiceTasks

func (d *Daemon) GetServiceTasks(t testing.TB, service string, additionalFilters ...filters.KeyValuePair) []swarm.Task

GetServiceTasks returns the swarm tasks for the specified service

func (*Daemon) GetSwarm

func (d *Daemon) GetSwarm(t testing.TB) swarm.Swarm

GetSwarm returns the current swarm object

func (*Daemon) GetTask

func (d *Daemon) GetTask(t testing.TB, id string) swarm.Task

GetTask returns the swarm task identified by the specified id

func (*Daemon) ID

func (d *Daemon) ID() string

ID returns the generated id of the daemon

func (*Daemon) Info

func (d *Daemon) Info(t testing.TB) types.Info

Info returns the info struct for this daemon

func (*Daemon) Interrupt

func (d *Daemon) Interrupt() error

Interrupt stops the daemon by sending it an Interrupt signal

func (*Daemon) JoinTokens

func (d *Daemon) JoinTokens(t testing.TB) swarm.JoinTokens

JoinTokens returns the current swarm join tokens

func (*Daemon) Kill

func (d *Daemon) Kill() error

Kill will send a SIGKILL to the daemon

func (*Daemon) ListConfigs

func (d *Daemon) ListConfigs(t testing.TB) []swarm.Config

ListConfigs returns the list of the current swarm configs

func (*Daemon) ListNodes

func (d *Daemon) ListNodes(t testing.TB) []swarm.Node

ListNodes returns the list of the current swarm nodes

func (*Daemon) ListSecrets

func (d *Daemon) ListSecrets(t testing.TB) []swarm.Secret

ListSecrets returns the list of the current swarm secrets

func (*Daemon) ListServices

func (d *Daemon) ListServices(t testing.TB) []swarm.Service

ListServices returns the list of the current swarm services

func (*Daemon) LoadBusybox

func (d *Daemon) LoadBusybox(t testing.TB)

LoadBusybox image into the daemon

func (*Daemon) LogFileName

func (d *Daemon) LogFileName() string

LogFileName returns the path the daemon's log file

func (*Daemon) NewClient

func (d *Daemon) NewClient(extraOpts ...client.Opt) (*client.Client, error)

NewClient creates new client based on daemon's socket path

func (*Daemon) NewClientT

func (d *Daemon) NewClientT(t testing.TB, extraOpts ...client.Opt) *client.Client

NewClientT creates new client based on daemon's socket path

func (*Daemon) NodeID

func (d *Daemon) NodeID() string

NodeID returns the swarm mode node ID

func (*Daemon) Pid

func (d *Daemon) Pid() int

Pid returns the pid of the daemon

func (*Daemon) PluginIsNotPresent

func (d *Daemon) PluginIsNotPresent(t testing.TB, name string) func(poll.LogT) poll.Result

PluginIsNotPresent provides a poller to check if the specified plugin is not present

func (*Daemon) PluginIsNotRunning

func (d *Daemon) PluginIsNotRunning(t testing.TB, name string) func(poll.LogT) poll.Result

PluginIsNotRunning provides a poller to check if the specified plugin is not running

func (*Daemon) PluginIsRunning

func (d *Daemon) PluginIsRunning(t testing.TB, name string) func(poll.LogT) poll.Result

PluginIsRunning provides a poller to check if the specified plugin is running

func (*Daemon) PluginReferenceIs

func (d *Daemon) PluginReferenceIs(t testing.TB, name, expectedRef string) func(poll.LogT) poll.Result

PluginReferenceIs provides a poller to check if the specified plugin has the specified reference

func (*Daemon) ReadLogFile

func (d *Daemon) ReadLogFile() ([]byte, error)

ReadLogFile returns the content of the daemon log file

func (*Daemon) ReloadConfig

func (d *Daemon) ReloadConfig() error

ReloadConfig asks the daemon to reload its configuration

func (*Daemon) RemoveNode

func (d *Daemon) RemoveNode(t testing.TB, id string, force bool)

RemoveNode removes the specified node

func (*Daemon) RemoveService

func (d *Daemon) RemoveService(t testing.TB, id string)

RemoveService removes the specified service

func (*Daemon) Restart

func (d *Daemon) Restart(t testing.TB, args ...string)

Restart will restart the daemon by first stopping it and the starting it. If an error occurs while starting the daemon, the test will fail.

func (*Daemon) RestartNode

func (d *Daemon) RestartNode(t testing.TB)

RestartNode restarts a daemon to be used as a swarm node

func (*Daemon) RestartWithError

func (d *Daemon) RestartWithError(arg ...string) error

RestartWithError will restart the daemon by first stopping it and then starting it.

func (*Daemon) RootDir

func (d *Daemon) RootDir() string

RootDir returns the root directory of the daemon.

func (*Daemon) RotateTokens

func (d *Daemon) RotateTokens(t testing.TB)

RotateTokens update the swarm to rotate tokens

func (*Daemon) Signal

func (d *Daemon) Signal(signal os.Signal) error

Signal sends the specified signal to the daemon if running

func (*Daemon) Sock

func (d *Daemon) Sock() string

Sock returns the socket path of the daemon

func (*Daemon) Start

func (d *Daemon) Start(t testing.TB, args ...string)

Start starts the daemon and return once it is ready to receive requests.

func (*Daemon) StartAndSwarmInit

func (d *Daemon) StartAndSwarmInit(t testing.TB)

StartAndSwarmInit starts the daemon (with busybox) and init the swarm

func (*Daemon) StartAndSwarmJoin

func (d *Daemon) StartAndSwarmJoin(t testing.TB, leader *Daemon, manager bool)

StartAndSwarmJoin starts the daemon (with busybox) and join the specified swarm as worker or manager

func (*Daemon) StartNode

func (d *Daemon) StartNode(t testing.TB)

StartNode (re)starts the daemon

func (*Daemon) StartNodeWithBusybox

func (d *Daemon) StartNodeWithBusybox(t testing.TB)

StartNodeWithBusybox starts daemon to be used as a swarm node, and loads the busybox image

func (*Daemon) StartWithBusybox

func (d *Daemon) StartWithBusybox(t testing.TB, arg ...string)

StartWithBusybox will first start the daemon with Daemon.Start() then save the busybox image from the main daemon and load it into this Daemon instance.

func (*Daemon) StartWithError

func (d *Daemon) StartWithError(args ...string) error

StartWithError starts the daemon and return once it is ready to receive requests. It returns an error in case it couldn't start.

func (*Daemon) StartWithLogFile

func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error

StartWithLogFile will start the daemon and attach its streams to a given file.

func (*Daemon) Stop

func (d *Daemon) Stop(t testing.TB)

Stop will send a SIGINT every second and wait for the daemon to stop. If it times out, a SIGKILL is sent. Stop will not delete the daemon directory. If a purged daemon is needed, instantiate a new one with NewDaemon. If an error occurs while starting the daemon, the test will fail.

func (*Daemon) StopWithError

func (d *Daemon) StopWithError() (err error)

StopWithError will send a SIGINT every second and wait for the daemon to stop. If it timeouts, a SIGKILL is sent. Stop will not delete the daemon directory. If a purged daemon is needed, instantiate a new one with NewDaemon.

func (*Daemon) StorageDriver

func (d *Daemon) StorageDriver() string

StorageDriver returns the configured storage driver of the daemon

func (*Daemon) SwarmInfo

func (d *Daemon) SwarmInfo(t testing.TB) swarm.Info

SwarmInfo returns the swarm information of the daemon

func (*Daemon) SwarmInit

func (d *Daemon) SwarmInit(t testing.TB, req swarm.InitRequest)

SwarmInit initializes a new swarm cluster.

func (*Daemon) SwarmJoin

func (d *Daemon) SwarmJoin(t testing.TB, req swarm.JoinRequest)

SwarmJoin joins a daemon to an existing cluster.

func (*Daemon) SwarmLeave

func (d *Daemon) SwarmLeave(t testing.TB, force bool) error

SwarmLeave forces daemon to leave current cluster.

The passed in testing.TB is only used to validate that the client was successfully created Some tests rely on error checking the result of the actual unlock, so allow the error to be returned.

func (*Daemon) SwarmListenAddr

func (d *Daemon) SwarmListenAddr() string

SwarmListenAddr returns the listen-addr used for the daemon

func (*Daemon) SwarmUnlock

func (d *Daemon) SwarmUnlock(t testing.TB, req swarm.UnlockRequest) error

SwarmUnlock tries to unlock a locked swarm

The passed in testing.TB is only used to validate that the client was successfully created Some tests rely on error checking the result of the actual unlock, so allow the error to be returned.

func (*Daemon) UpdateConfig

func (d *Daemon) UpdateConfig(t testing.TB, id string, f ...ConfigConstructor)

UpdateConfig updates the swarm config identified by the specified id Currently, only label update is supported.

func (*Daemon) UpdateNode

func (d *Daemon) UpdateNode(t testing.TB, id string, f ...NodeConstructor)

UpdateNode updates a swarm node with the specified node constructor

func (*Daemon) UpdateSecret

func (d *Daemon) UpdateSecret(t testing.TB, id string, f ...SecretConstructor)

UpdateSecret updates the swarm secret identified by the specified id Currently, only label update is supported.

func (*Daemon) UpdateService

func (d *Daemon) UpdateService(t testing.TB, service *swarm.Service, f ...ServiceConstructor)

UpdateService updates a swarm service with the specified service constructor

func (*Daemon) UpdateSwarm

func (d *Daemon) UpdateSwarm(t testing.TB, f ...SpecConstructor)

UpdateSwarm updates the current swarm object with the specified spec constructors

type LogT

type LogT interface {
	Logf(string, ...interface{})
}

LogT is the subset of the testing.TB interface used by the daemon.

type NodeConstructor

type NodeConstructor func(*swarm.Node)

NodeConstructor defines a swarm node constructor

type Option

type Option func(*Daemon)

Option is used to configure a daemon.

func WithContainerdSocket

func WithContainerdSocket(socket string) Option

WithContainerdSocket sets the --containerd option on the daemon. Use an empty string to remove the option.

If unset the --containerd option will be used with a default value.

func WithDefaultCgroupNamespaceMode

func WithDefaultCgroupNamespaceMode(mode string) Option

WithDefaultCgroupNamespaceMode sets the default cgroup namespace mode for the daemon

func WithDockerdBinary

func WithDockerdBinary(dockerdBinary string) Option

WithDockerdBinary sets the dockerd binary to the specified one

func WithEnvironment

func WithEnvironment(e environment.Execution) Option

WithEnvironment sets options from testutil/environment.Execution struct

func WithExperimental

func WithExperimental() Option

WithExperimental sets the daemon in experimental mode

func WithInit

func WithInit() Option

WithInit sets the daemon init

func WithOOMScoreAdjust

func WithOOMScoreAdjust(score int) Option

WithOOMScoreAdjust sets OOM score for the daemon

func WithRootlessUser

func WithRootlessUser(username string) Option

WithRootlessUser sets the daemon to be rootless

func WithStorageDriver

func WithStorageDriver(driver string) Option

WithStorageDriver sets store driver option

func WithSwarmDataPathPort

func WithSwarmDataPathPort(datapathPort uint32) Option

WithSwarmDataPathPort sets the swarm datapath port to use for swarm mode

func WithSwarmDefaultAddrPool

func WithSwarmDefaultAddrPool(defaultAddrPool []string) Option

WithSwarmDefaultAddrPool sets the swarm default address pool to use for swarm mode

func WithSwarmDefaultAddrPoolSubnetSize

func WithSwarmDefaultAddrPoolSubnetSize(subnetSize uint32) Option

WithSwarmDefaultAddrPoolSubnetSize sets the subnet length mask of swarm default address pool to use for swarm mode

func WithSwarmListenAddr

func WithSwarmListenAddr(listenAddr string) Option

WithSwarmListenAddr sets the swarm listen addr to use for swarm mode

func WithSwarmPort

func WithSwarmPort(port int) Option

WithSwarmPort sets the swarm port to use for swarm mode

func WithTestLogger

func WithTestLogger(t LogT) Option

WithTestLogger causes the daemon to log certain actions to the provided test.

type SecretConstructor

type SecretConstructor func(*swarm.Secret)

SecretConstructor defines a swarm secret constructor

type ServiceConstructor

type ServiceConstructor func(*swarm.Service)

ServiceConstructor defines a swarm service constructor function

type SpecConstructor

type SpecConstructor func(*swarm.Spec)

SpecConstructor defines a swarm spec constructor

Jump to

Keyboard shortcuts

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