From b96a0c775400821d80972619fbfe6a2070f3e9ba Mon Sep 17 00:00:00 2001 From: Sam Whited Date: Tue, 5 Nov 2019 16:40:27 -0500 Subject: [PATCH] Add daemon options required by buildkit tests Signed-off-by: Sam Whited --- testutil/daemon/daemon.go | 33 ++++++++++++++++++++------------- testutil/daemon/ops.go | 10 ++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/testutil/daemon/daemon.go b/testutil/daemon/daemon.go index cf0ce671a6..6a1b97fe17 100644 --- a/testutil/daemon/daemon.go +++ b/testutil/daemon/daemon.go @@ -39,8 +39,10 @@ type nopLog struct{} func (nopLog) Logf(string, ...interface{}) {} -const defaultDockerdBinary = "dockerd" -const containerdSocket = "/var/run/docker/containerd/containerd.sock" +const ( + defaultDockerdBinary = "dockerd" + defaultContainerdSocket = "/var/run/docker/containerd/containerd.sock" +) var errDaemonNotStarted = errors.New("daemon not started") @@ -75,6 +77,7 @@ type Daemon struct { log LogT pidFile string args []string + containerdSocket string // swarm related field swarmListenAddr string @@ -120,11 +123,12 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) { storageDriver: storageDriver, userlandProxy: userlandProxy, // dxr stands for docker-execroot (shortened for avoiding unix(7) path length limitation) - execRoot: filepath.Join(os.TempDir(), "dxr", id), - dockerdBinary: defaultDockerdBinary, - swarmListenAddr: defaultSwarmListenAddr, - SwarmPort: DefaultSwarmPort, - log: nopLog{}, + execRoot: filepath.Join(os.TempDir(), "dxr", id), + dockerdBinary: defaultDockerdBinary, + swarmListenAddr: defaultSwarmListenAddr, + SwarmPort: DefaultSwarmPort, + log: nopLog{}, + containerdSocket: defaultContainerdSocket, } for _, op := range ops { @@ -252,17 +256,20 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error { d.pidFile = filepath.Join(d.Folder, "docker.pid") } - d.args = append(d.GlobalFlags, - "--containerd", containerdSocket, - "--data-root", d.Root, + d.args = append(d.GlobalFlags, "--data-root", d.Root) + if d.containerdSocket != "" { + d.args = append(d.args, "--containerd", d.containerdSocket) + } + d.args = append(d.args, "--exec-root", d.execRoot, "--pidfile", d.pidFile, fmt.Sprintf("--userland-proxy=%t", d.userlandProxy), "--containerd-namespace", d.id, "--containerd-plugins-namespace", d.id+"p", ) + if d.defaultCgroupNamespaceMode != "" { - d.args = append(d.args, []string{"--default-cgroupns-mode", d.defaultCgroupNamespaceMode}...) + d.args = append(d.args, "--default-cgroupns-mode", d.defaultCgroupNamespaceMode) } if d.experimental { d.args = append(d.args, "--experimental") @@ -271,10 +278,10 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error { d.args = append(d.args, "--init") } if !(d.UseDefaultHost || d.UseDefaultTLSHost) { - d.args = append(d.args, []string{"--host", d.Sock()}...) + d.args = append(d.args, "--host", d.Sock()) } if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" { - d.args = append(d.args, []string{"--userns-remap", root}...) + d.args = append(d.args, "--userns-remap", root) } // If we don't explicitly set the log-level or debug flag(-D) then diff --git a/testutil/daemon/ops.go b/testutil/daemon/ops.go index a866ff8be6..7875822a59 100644 --- a/testutil/daemon/ops.go +++ b/testutil/daemon/ops.go @@ -7,6 +7,16 @@ import ( // Option is used to configure a daemon. type Option func(*Daemon) +// 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 + } +} + // WithDefaultCgroupNamespaceMode sets the default cgroup namespace mode for the daemon func WithDefaultCgroupNamespaceMode(mode string) Option { return func(d *Daemon) {