2018-04-10 10:29:48 -04:00
|
|
|
package daemon
|
|
|
|
|
2019-09-17 11:50:24 -04:00
|
|
|
import (
|
2020-03-13 09:37:09 -04:00
|
|
|
"os/user"
|
|
|
|
|
2019-09-17 11:50:24 -04:00
|
|
|
"github.com/docker/docker/testutil/environment"
|
|
|
|
)
|
2018-04-13 11:02:56 -04:00
|
|
|
|
2019-09-17 13:44:35 -04:00
|
|
|
// Option is used to configure a daemon.
|
|
|
|
type Option func(*Daemon)
|
|
|
|
|
2019-11-05 16:40:27 -05:00
|
|
|
// 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 WithContainerdSocket(socket string) Option {
|
|
|
|
return func(d *Daemon) {
|
|
|
|
d.containerdSocket = socket
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-14 23:44:18 -04:00
|
|
|
// WithDefaultCgroupNamespaceMode sets the default cgroup namespace mode for the daemon
|
2019-09-17 13:44:35 -04:00
|
|
|
func WithDefaultCgroupNamespaceMode(mode string) Option {
|
2019-03-14 23:44:18 -04:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.defaultCgroupNamespaceMode = mode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-17 11:50:24 -04:00
|
|
|
// WithTestLogger causes the daemon to log certain actions to the provided test.
|
2019-10-16 16:27:22 -04:00
|
|
|
func WithTestLogger(t LogT) Option {
|
2019-09-17 11:50:24 -04:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.log = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-10 10:29:48 -04:00
|
|
|
// WithExperimental sets the daemon in experimental mode
|
2019-09-30 08:23:56 -04:00
|
|
|
func WithExperimental() Option {
|
|
|
|
return func(d *Daemon) {
|
|
|
|
d.experimental = true
|
|
|
|
}
|
2018-06-01 06:47:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// WithInit sets the daemon init
|
2019-09-30 08:44:09 -04:00
|
|
|
func WithInit() Option {
|
|
|
|
return func(d *Daemon) {
|
|
|
|
d.init = true
|
|
|
|
}
|
2018-04-10 10:29:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// WithDockerdBinary sets the dockerd binary to the specified one
|
2019-09-17 13:44:35 -04:00
|
|
|
func WithDockerdBinary(dockerdBinary string) Option {
|
2018-04-10 10:29:48 -04:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.dockerdBinary = dockerdBinary
|
|
|
|
}
|
|
|
|
}
|
2018-04-11 06:10:17 -04:00
|
|
|
|
|
|
|
// WithSwarmPort sets the swarm port to use for swarm mode
|
2019-09-17 13:44:35 -04:00
|
|
|
func WithSwarmPort(port int) Option {
|
2018-04-11 06:10:17 -04:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.SwarmPort = port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithSwarmListenAddr sets the swarm listen addr to use for swarm mode
|
2019-09-17 13:44:35 -04:00
|
|
|
func WithSwarmListenAddr(listenAddr string) Option {
|
2018-04-11 06:10:17 -04:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.swarmListenAddr = listenAddr
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 11:02:56 -04:00
|
|
|
|
2018-07-30 11:25:02 -04:00
|
|
|
// WithSwarmDefaultAddrPool sets the swarm default address pool to use for swarm mode
|
2019-09-17 13:44:35 -04:00
|
|
|
func WithSwarmDefaultAddrPool(defaultAddrPool []string) Option {
|
2018-07-30 11:25:02 -04:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.DefaultAddrPool = defaultAddrPool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithSwarmDefaultAddrPoolSubnetSize sets the subnet length mask of swarm default address pool to use for swarm mode
|
2019-09-17 13:44:35 -04:00
|
|
|
func WithSwarmDefaultAddrPoolSubnetSize(subnetSize uint32) Option {
|
2018-07-30 11:25:02 -04:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.SubnetSize = subnetSize
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 16:44:40 -05:00
|
|
|
// WithSwarmDataPathPort sets the swarm datapath port to use for swarm mode
|
2019-09-17 13:44:35 -04:00
|
|
|
func WithSwarmDataPathPort(datapathPort uint32) Option {
|
2018-11-20 16:44:40 -05:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.DataPathPort = datapathPort
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-29 16:52:40 -04:00
|
|
|
// WithEnvironment sets options from testutil/environment.Execution struct
|
2019-09-17 13:44:35 -04:00
|
|
|
func WithEnvironment(e environment.Execution) Option {
|
2018-04-13 11:02:56 -04:00
|
|
|
return func(d *Daemon) {
|
|
|
|
if e.DaemonInfo.ExperimentalBuild {
|
|
|
|
d.experimental = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-07 21:27:15 -04:00
|
|
|
|
|
|
|
// WithStorageDriver sets store driver option
|
2019-09-30 08:22:21 -04:00
|
|
|
func WithStorageDriver(driver string) Option {
|
2019-05-07 21:27:15 -04:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.storageDriver = driver
|
|
|
|
}
|
|
|
|
}
|
2020-03-13 09:37:09 -04:00
|
|
|
|
|
|
|
// WithRootlessUser sets the daemon to be rootless
|
|
|
|
func WithRootlessUser(username string) Option {
|
|
|
|
return func(d *Daemon) {
|
|
|
|
u, err := user.Lookup(username)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
d.rootlessUser = u
|
|
|
|
}
|
|
|
|
}
|