Browse code

Merge pull request #40146 from thaJeztah/move_hcsshim

libcontainerd: move hcsshim import to windows-only file

Brian Goff authored on 2019/12/20 04:55:24
Showing 3 changed files
... ...
@@ -13,7 +13,6 @@ import (
13 13
 	"syscall"
14 14
 	"time"
15 15
 
16
-	"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
17 16
 	"github.com/containerd/containerd"
18 17
 	apievents "github.com/containerd/containerd/api/events"
19 18
 	"github.com/containerd/containerd/api/types"
... ...
@@ -28,7 +27,6 @@ import (
28 28
 	"github.com/docker/docker/errdefs"
29 29
 	"github.com/docker/docker/libcontainerd/queue"
30 30
 	libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
31
-
32 31
 	"github.com/docker/docker/pkg/ioutils"
33 32
 	v1 "github.com/opencontainers/image-spec/specs-go/v1"
34 33
 	specs "github.com/opencontainers/runtime-spec/specs-go"
... ...
@@ -192,6 +190,27 @@ func (c *client) Start(ctx context.Context, id, checkpointDir string, withStdin
192 192
 	}
193 193
 	bundle := labels[DockerContainerBundlePath]
194 194
 	uid, gid := getSpecUser(spec)
195
+
196
+	taskOpts := []containerd.NewTaskOpts{
197
+		func(_ context.Context, _ *containerd.Client, info *containerd.TaskInfo) error {
198
+			info.Checkpoint = cp
199
+			return nil
200
+		},
201
+	}
202
+
203
+	if runtime.GOOS != "windows" {
204
+		taskOpts = append(taskOpts, func(_ context.Context, _ *containerd.Client, info *containerd.TaskInfo) error {
205
+			info.Options = &runctypes.CreateOptions{
206
+				IoUid:       uint32(uid),
207
+				IoGid:       uint32(gid),
208
+				NoPivotRoot: os.Getenv("DOCKER_RAMDISK") != "",
209
+			}
210
+			return nil
211
+		})
212
+	} else {
213
+		taskOpts = append(taskOpts, withLogLevel(c.logger.Level))
214
+	}
215
+
195 216
 	t, err = ctr.NewTask(ctx,
196 217
 		func(id string) (cio.IO, error) {
197 218
 			fifos := newFIFOSet(bundle, libcontainerdtypes.InitProcessName, withStdin, spec.Process.Terminal)
... ...
@@ -199,22 +218,8 @@ func (c *client) Start(ctx context.Context, id, checkpointDir string, withStdin
199 199
 			rio, err = c.createIO(fifos, id, libcontainerdtypes.InitProcessName, stdinCloseSync, attachStdio)
200 200
 			return rio, err
201 201
 		},
202
-		func(_ context.Context, _ *containerd.Client, info *containerd.TaskInfo) error {
203
-			info.Checkpoint = cp
204
-			if runtime.GOOS != "windows" {
205
-				info.Options = &runctypes.CreateOptions{
206
-					IoUid:       uint32(uid),
207
-					IoGid:       uint32(gid),
208
-					NoPivotRoot: os.Getenv("DOCKER_RAMDISK") != "",
209
-				}
210
-			} else {
211
-				// Make sure we set the runhcs options to debug if we are at debug level.
212
-				if c.logger.Level == logrus.DebugLevel {
213
-					info.Options = &options.Options{Debug: true}
214
-				}
215
-			}
216
-			return nil
217
-		})
202
+		taskOpts...,
203
+	)
218 204
 	if err != nil {
219 205
 		close(stdinCloseSync)
220 206
 		if rio != nil {
... ...
@@ -94,6 +94,10 @@ func WithBundle(bundleDir string, ociSpec *specs.Spec) containerd.NewContainerOp
94 94
 	}
95 95
 }
96 96
 
97
+func withLogLevel(_ logrus.Level) containerd.NewTaskOpts {
98
+	panic("Not implemented")
99
+}
100
+
97 101
 func newFIFOSet(bundleDir, processID string, withStdin, withTerminal bool) *cio.FIFOSet {
98 102
 	config := cio.Config{
99 103
 		Terminal: withTerminal,
... ...
@@ -10,10 +10,10 @@ import (
10 10
 	"github.com/containerd/containerd"
11 11
 	"github.com/containerd/containerd/cio"
12 12
 	"github.com/containerd/containerd/containers"
13
-
14 13
 	libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
15 14
 	specs "github.com/opencontainers/runtime-spec/specs-go"
16 15
 	"github.com/pkg/errors"
16
+	"github.com/sirupsen/logrus"
17 17
 )
18 18
 
19 19
 const runtimeName = "io.containerd.runhcs.v1"
... ...
@@ -49,6 +49,16 @@ func WithBundle(bundleDir string, ociSpec *specs.Spec) containerd.NewContainerOp
49 49
 	}
50 50
 }
51 51
 
52
+func withLogLevel(level logrus.Level) containerd.NewTaskOpts {
53
+	// Make sure we set the runhcs options to debug if we are at debug level.
54
+	return func(_ context.Context, _ *containerd.Client, info *containerd.TaskInfo) error {
55
+		if level == logrus.DebugLevel {
56
+			info.Options = &options.Options{Debug: true}
57
+		}
58
+		return nil
59
+	}
60
+}
61
+
52 62
 func pipeName(containerID, processID, name string) string {
53 63
 	return fmt.Sprintf(`\\.\pipe\containerd-%s-%s-%s`, containerID, processID, name)
54 64
 }