Browse code

vendor: github.com/containerd/containerd 0edc412565dcc6e3d6125ff9e4b009ad4b89c638

full diff: https://github.com/containerd/containerd/compare/d4e78200d6da62480c85bf6f26b7221ea938f396...0edc412565dcc6e3d6125ff9e4b009ad4b89c638

- integrates containerd/cri into main containerd repository
- seccomp: add `pidfd_open` and `pidfd_send_signal`
- seccomp: add `pidfd_getfd` syscall (gated by `CAP_SYS_PTRACE`)
- docker: don’t hide pusher response error

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2020/11/18 18:58:41
Showing 25 changed files
... ...
@@ -130,7 +130,7 @@ github.com/googleapis/gax-go                        bd5b16380fd03dc758d11cef74ba
130 130
 google.golang.org/genproto                          3f1135a288c9a07e340ae8ba4cc6c7065a3160e8
131 131
 
132 132
 # containerd
133
-github.com/containerd/containerd                    d4e78200d6da62480c85bf6f26b7221ea938f396
133
+github.com/containerd/containerd                    0edc412565dcc6e3d6125ff9e4b009ad4b89c638 # master (v1.5.0-dev)
134 134
 github.com/containerd/fifo                          0724c46b320cf96bb172a0550c19a4b1fca4dacb
135 135
 github.com/containerd/continuity                    efbc4488d8fe1bdc16bde3b2d2990d9b3a899165
136 136
 github.com/containerd/cgroups                       0b889c03f102012f1d93a97ddd3ef71cd6f4f510
... ...
@@ -1,6 +1,6 @@
1 1
 ![containerd banner](https://raw.githubusercontent.com/cncf/artwork/master/projects/containerd/horizontal/color/containerd-horizontal-color.png)
2 2
 
3
-[![GoDoc](https://godoc.org/github.com/containerd/containerd?status.svg)](https://godoc.org/github.com/containerd/containerd)
3
+[![PkgGoDev](https://pkg.go.dev/badge/github.com/containerd/containerd)](https://pkg.go.dev/github.com/containerd/containerd)
4 4
 [![Build Status](https://github.com/containerd/containerd/workflows/CI/badge.svg)](https://github.com/containerd/containerd/actions?query=workflow%3ACI)
5 5
 [![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/containerd/containerd?branch=master&svg=true)](https://ci.appveyor.com/project/mlaventure/containerd-3g73f?branch=master)
6 6
 [![Nightlies](https://github.com/containerd/containerd/workflows/Nightly/badge.svg)](https://github.com/containerd/containerd/actions?query=workflow%3ANightly)
... ...
@@ -260,6 +260,26 @@ func BinaryIO(binary string, args map[string]string) Creator {
260 260
 	}
261 261
 }
262 262
 
263
+// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary
264
+// It also sets the terminal option to true
265
+func TerminalBinaryIO(binary string, args map[string]string) Creator {
266
+	return func(_ string) (IO, error) {
267
+		uri, err := LogURIGenerator("binary", binary, args)
268
+		if err != nil {
269
+			return nil, err
270
+		}
271
+
272
+		res := uri.String()
273
+		return &logURI{
274
+			config: Config{
275
+				Stdout:   res,
276
+				Stderr:   res,
277
+				Terminal: true,
278
+			},
279
+		}, nil
280
+	}
281
+}
282
+
263 283
 // LogFile creates a file on disk that logs the task's STDOUT,STDERR.
264 284
 // If the log file already exists, the logs will be appended to the file.
265 285
 func LogFile(path string) Creator {
... ...
@@ -87,21 +87,21 @@ func WithRestoreRuntime(ctx context.Context, id string, client *Client, checkpoi
87 87
 				return err
88 88
 			}
89 89
 		}
90
-		var options *ptypes.Any
90
+		var options ptypes.Any
91 91
 		if m != nil {
92 92
 			store := client.ContentStore()
93 93
 			data, err := content.ReadBlob(ctx, store, *m)
94 94
 			if err != nil {
95 95
 				return errors.Wrap(err, "unable to read checkpoint runtime")
96 96
 			}
97
-			if err := proto.Unmarshal(data, options); err != nil {
97
+			if err := proto.Unmarshal(data, &options); err != nil {
98 98
 				return err
99 99
 			}
100 100
 		}
101 101
 
102 102
 		c.Runtime = containers.RuntimeInfo{
103 103
 			Name:    name,
104
-			Options: options,
104
+			Options: &options,
105 105
 		}
106 106
 		return nil
107 107
 	}
... ...
@@ -229,9 +229,47 @@ func seekReader(r io.Reader, offset, size int64) (io.Reader, error) {
229 229
 	return r, nil
230 230
 }
231 231
 
232
+// copyWithBuffer is very similar to  io.CopyBuffer https://golang.org/pkg/io/#CopyBuffer
233
+// but instead of using Read to read from the src, we use ReadAtLeast to make sure we have
234
+// a full buffer before we do a write operation to dst to reduce overheads associated
235
+// with the write operations of small buffers.
232 236
 func copyWithBuffer(dst io.Writer, src io.Reader) (written int64, err error) {
233
-	buf := bufPool.Get().(*[]byte)
234
-	written, err = io.CopyBuffer(dst, src, *buf)
235
-	bufPool.Put(buf)
237
+	// If the reader has a WriteTo method, use it to do the copy.
238
+	// Avoids an allocation and a copy.
239
+	if wt, ok := src.(io.WriterTo); ok {
240
+		return wt.WriteTo(dst)
241
+	}
242
+	// Similarly, if the writer has a ReadFrom method, use it to do the copy.
243
+	if rt, ok := dst.(io.ReaderFrom); ok {
244
+		return rt.ReadFrom(src)
245
+	}
246
+	bufRef := bufPool.Get().(*[]byte)
247
+	defer bufPool.Put(bufRef)
248
+	buf := *bufRef
249
+	for {
250
+		nr, er := io.ReadAtLeast(src, buf, len(buf))
251
+		if nr > 0 {
252
+			nw, ew := dst.Write(buf[0:nr])
253
+			if nw > 0 {
254
+				written += int64(nw)
255
+			}
256
+			if ew != nil {
257
+				err = ew
258
+				break
259
+			}
260
+			if nr != nw {
261
+				err = io.ErrShortWrite
262
+				break
263
+			}
264
+		}
265
+		if er != nil {
266
+			// If an EOF happens after reading fewer than the requested bytes,
267
+			// ReadAtLeast returns ErrUnexpectedEOF.
268
+			if er != io.EOF && er != io.ErrUnexpectedEOF {
269
+				err = er
270
+			}
271
+			break
272
+		}
273
+	}
236 274
 	return
237 275
 }
... ...
@@ -1,4 +1,4 @@
1
-// +build linux solaris darwin freebsd
1
+// +build linux solaris darwin freebsd netbsd
2 2
 
3 3
 /*
4 4
    Copyright The containerd Authors.
... ...
@@ -40,7 +40,13 @@ func (ra *remoteReaderAt) ReadAt(p []byte, off int64) (n int, err error) {
40 40
 		Offset: off,
41 41
 		Size_:  int64(len(p)),
42 42
 	}
43
-	rc, err := ra.client.Read(ra.ctx, rr)
43
+	// we need a child context with cancel, or the eventually called
44
+	// grpc.NewStream will leak the goroutine until the whole thing is cleared.
45
+	// See comment at https://godoc.org/google.golang.org/grpc#ClientConn.NewStream
46
+	childCtx, cancel := context.WithCancel(ra.ctx)
47
+	// we MUST cancel the child context; see comment above
48
+	defer cancel()
49
+	rc, err := ra.client.Read(childCtx, rr)
44 50
 	if err != nil {
45 51
 		return 0, err
46 52
 	}
... ...
@@ -232,6 +232,8 @@ func DefaultProfile(sp *specs.Spec) *specs.LinuxSeccomp {
232 232
 				"openat",
233 233
 				"openat2",
234 234
 				"pause",
235
+				"pidfd_open",
236
+				"pidfd_send_signal",
235 237
 				"pipe",
236 238
 				"pipe2",
237 239
 				"poll",
... ...
@@ -571,6 +573,7 @@ func DefaultProfile(sp *specs.Spec) *specs.LinuxSeccomp {
571 571
 			s.Syscalls = append(s.Syscalls, specs.LinuxSyscall{
572 572
 				Names: []string{
573 573
 					"kcmp",
574
+					"pidfd_getfd",
574 575
 					"process_vm_readv",
575 576
 					"process_vm_writev",
576 577
 					"ptrace",
... ...
@@ -106,26 +106,37 @@ func Unmount(target string, flags int) error {
106 106
 	return nil
107 107
 }
108 108
 
109
-func isFUSE(dir string) (bool, error) {
110
-	// fuseSuperMagic is defined in statfs(2)
111
-	const fuseSuperMagic = 0x65735546
109
+// fuseSuperMagic is defined in statfs(2)
110
+const fuseSuperMagic = 0x65735546
111
+
112
+func isFUSE(dir string) bool {
112 113
 	var st unix.Statfs_t
113 114
 	if err := unix.Statfs(dir, &st); err != nil {
114
-		return false, err
115
+		return false
115 116
 	}
116
-	return st.Type == fuseSuperMagic, nil
117
+	return st.Type == fuseSuperMagic
118
+}
119
+
120
+// unmountFUSE attempts to unmount using fusermount/fusermount3 helper binary.
121
+//
122
+// For FUSE mounts, using these helper binaries is preferred, see:
123
+// https://github.com/containerd/containerd/pull/3765#discussion_r342083514
124
+func unmountFUSE(target string) error {
125
+	var err error
126
+	for _, helperBinary := range []string{"fusermount3", "fusermount"} {
127
+		cmd := exec.Command(helperBinary, "-u", target)
128
+		err = cmd.Run()
129
+		if err == nil {
130
+			return nil
131
+		}
132
+	}
133
+	return err
117 134
 }
118 135
 
119 136
 func unmount(target string, flags int) error {
120
-	// For FUSE mounts, attempting to execute fusermount helper binary is preferred
121
-	// https://github.com/containerd/containerd/pull/3765#discussion_r342083514
122
-	if ok, err := isFUSE(target); err == nil && ok {
123
-		for _, helperBinary := range []string{"fusermount3", "fusermount"} {
124
-			cmd := exec.Command(helperBinary, "-u", target)
125
-			if err := cmd.Run(); err == nil {
126
-				return nil
127
-			}
128
-			// ignore error and try unix.Unmount
137
+	if isFUSE(target) {
138
+		if err := unmountFUSE(target); err == nil {
139
+			return nil
129 140
 		}
130 141
 	}
131 142
 	for i := 0; i < 50; i++ {
... ...
@@ -221,7 +221,7 @@ func (e *execProcess) start(ctx context.Context) (err error) {
221 221
 		if err != nil {
222 222
 			return errors.Wrap(err, "failed to retrieve console master")
223 223
 		}
224
-		if e.console, err = e.parent.Platform.CopyConsole(ctx, console, e.stdio.Stdin, e.stdio.Stdout, e.stdio.Stderr, &e.wg); err != nil {
224
+		if e.console, err = e.parent.Platform.CopyConsole(ctx, console, e.id, e.stdio.Stdin, e.stdio.Stdout, e.stdio.Stderr, &e.wg); err != nil {
225 225
 			return errors.Wrap(err, "failed to start console copy")
226 226
 		}
227 227
 	} else {
... ...
@@ -157,7 +157,7 @@ func (p *Init) Create(ctx context.Context, r *CreateConfig) error {
157 157
 		if err != nil {
158 158
 			return errors.Wrap(err, "failed to retrieve console master")
159 159
 		}
160
-		console, err = p.Platform.CopyConsole(ctx, console, r.Stdin, r.Stdout, r.Stderr, &p.wg)
160
+		console, err = p.Platform.CopyConsole(ctx, console, p.id, r.Stdin, r.Stdout, r.Stderr, &p.wg)
161 161
 		if err != nil {
162 162
 			return errors.Wrap(err, "failed to start console copy")
163 163
 		}
... ...
@@ -172,7 +172,7 @@ func (s *createdCheckpointState) Start(ctx context.Context) error {
172 172
 		if err != nil {
173 173
 			return errors.Wrap(err, "failed to retrieve console master")
174 174
 		}
175
-		console, err = p.Platform.CopyConsole(ctx, console, sio.Stdin, sio.Stdout, sio.Stderr, &p.wg)
175
+		console, err = p.Platform.CopyConsole(ctx, console, p.id, sio.Stdin, sio.Stdout, sio.Stderr, &p.wg)
176 176
 		if err != nil {
177 177
 			return errors.Wrap(err, "failed to start console copy")
178 178
 		}
... ...
@@ -26,7 +26,7 @@ import (
26 26
 // Platform handles platform-specific behavior that may differs across
27 27
 // platform implementations
28 28
 type Platform interface {
29
-	CopyConsole(ctx context.Context, console console.Console, stdin, stdout, stderr string,
29
+	CopyConsole(ctx context.Context, console console.Console, id, stdin, stdout, stderr string,
30 30
 		wg *sync.WaitGroup) (console.Console, error)
31 31
 	ShutdownConsole(ctx context.Context, console console.Console) error
32 32
 	Close() error
... ...
@@ -96,6 +96,15 @@ func getCPUVariant() string {
96 96
 		return ""
97 97
 	}
98 98
 
99
+	// handle edge case for Raspberry Pi ARMv6 devices (which due to a kernel quirk, report "CPU architecture: 7")
100
+	// https://www.raspberrypi.org/forums/viewtopic.php?t=12614
101
+	if runtime.GOARCH == "arm" && variant == "7" {
102
+		model, err := getCPUInfo("model name")
103
+		if err == nil && strings.HasPrefix(strings.ToLower(model), "armv6-compatible") {
104
+			variant = "6"
105
+		}
106
+	}
107
+
99 108
 	switch strings.ToLower(variant) {
100 109
 	case "8", "aarch64":
101 110
 		// special case: if running a 32-bit userspace on aarch64, the variant should be "v7"
... ...
@@ -106,10 +106,8 @@ func FetchTokenWithOAuth(ctx context.Context, client *http.Client, headers http.
106 106
 		return nil, err
107 107
 	}
108 108
 	req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
109
-	if headers != nil {
110
-		for k, v := range headers {
111
-			req.Header[k] = append(req.Header[k], v...)
112
-		}
109
+	for k, v := range headers {
110
+		req.Header[k] = append(req.Header[k], v...)
113 111
 	}
114 112
 
115 113
 	resp, err := ctxhttp.Do(ctx, client, req)
... ...
@@ -152,10 +150,8 @@ func FetchToken(ctx context.Context, client *http.Client, headers http.Header, t
152 152
 		return nil, err
153 153
 	}
154 154
 
155
-	if headers != nil {
156
-		for k, v := range headers {
157
-			req.Header[k] = append(req.Header[k], v...)
158
-		}
155
+	for k, v := range headers {
156
+		req.Header[k] = append(req.Header[k], v...)
159 157
 	}
160 158
 
161 159
 	reqParams := req.URL.Query()
... ...
@@ -45,7 +45,7 @@ func (r dockerFetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.R
45 45
 		return nil, errors.Wrap(errdefs.ErrNotFound, "no pull hosts")
46 46
 	}
47 47
 
48
-	ctx, err := contextWithRepositoryScope(ctx, r.refspec, false)
48
+	ctx, err := ContextWithRepositoryScope(ctx, r.refspec, false)
49 49
 	if err != nil {
50 50
 		return nil, err
51 51
 	}
... ...
@@ -121,7 +121,7 @@ func (hrs *httpReadSeeker) reader() (io.Reader, error) {
121 121
 
122 122
 		rc, err := hrs.open(hrs.offset)
123 123
 		if err != nil {
124
-			return nil, errors.Wrapf(err, "httpReaderSeeker: failed open")
124
+			return nil, errors.Wrapf(err, "httpReadSeeker: failed open")
125 125
 		}
126 126
 
127 127
 		if hrs.rc != nil {
... ...
@@ -45,7 +45,7 @@ type dockerPusher struct {
45 45
 }
46 46
 
47 47
 func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (content.Writer, error) {
48
-	ctx, err := contextWithRepositoryScope(ctx, p.refspec, true)
48
+	ctx, err := ContextWithRepositoryScope(ctx, p.refspec, true)
49 49
 	if err != nil {
50 50
 		return nil, err
51 51
 	}
... ...
@@ -130,7 +130,7 @@ func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (conten
130 130
 		var resp *http.Response
131 131
 		if fromRepo := selectRepositoryMountCandidate(p.refspec, desc.Annotations); fromRepo != "" {
132 132
 			preq := requestWithMountFrom(req, desc.Digest.String(), fromRepo)
133
-			pctx := contextWithAppendPullRepositoryScope(ctx, fromRepo)
133
+			pctx := ContextWithAppendPullRepositoryScope(ctx, fromRepo)
134 134
 
135 135
 			// NOTE: the fromRepo might be private repo and
136 136
 			// auth service still can grant token without error.
... ...
@@ -222,7 +222,7 @@ func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (conten
222 222
 	// TODO: Support chunked upload
223 223
 
224 224
 	pr, pw := io.Pipe()
225
-	respC := make(chan *http.Response, 1)
225
+	respC := make(chan response, 1)
226 226
 	body := ioutil.NopCloser(pr)
227 227
 
228 228
 	req.body = func() (io.ReadCloser, error) {
... ...
@@ -240,6 +240,7 @@ func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (conten
240 240
 		defer close(respC)
241 241
 		resp, err := req.do(ctx)
242 242
 		if err != nil {
243
+			respC <- response{err: err}
243 244
 			pr.CloseWithError(err)
244 245
 			return
245 246
 		}
... ...
@@ -251,7 +252,7 @@ func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (conten
251 251
 			log.G(ctx).WithField("resp", resp).WithField("body", string(err.(remoteserrors.ErrUnexpectedStatus).Body)).Debug("unexpected response")
252 252
 			pr.CloseWithError(err)
253 253
 		}
254
-		respC <- resp
254
+		respC <- response{Response: resp}
255 255
 	}()
256 256
 
257 257
 	return &pushWriter{
... ...
@@ -284,12 +285,17 @@ func getManifestPath(object string, dgst digest.Digest) []string {
284 284
 	return []string{"manifests", object}
285 285
 }
286 286
 
287
+type response struct {
288
+	*http.Response
289
+	err error
290
+}
291
+
287 292
 type pushWriter struct {
288 293
 	base *dockerBase
289 294
 	ref  string
290 295
 
291 296
 	pipe       *io.PipeWriter
292
-	responseC  <-chan *http.Response
297
+	responseC  <-chan response
293 298
 	isManifest bool
294 299
 
295 300
 	expected digest.Digest
... ...
@@ -339,8 +345,8 @@ func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Di
339 339
 
340 340
 	// TODO: timeout waiting for response
341 341
 	resp := <-pw.responseC
342
-	if resp == nil {
343
-		return errors.New("no response")
342
+	if resp.err != nil {
343
+		return resp.err
344 344
 	}
345 345
 
346 346
 	// 201 is specified return status, some registries return
... ...
@@ -263,7 +263,7 @@ func (r *dockerResolver) Resolve(ctx context.Context, ref string) (string, ocisp
263 263
 		return "", ocispec.Descriptor{}, errors.Wrap(errdefs.ErrNotFound, "no resolve hosts")
264 264
 	}
265 265
 
266
-	ctx, err = contextWithRepositoryScope(ctx, refspec, false)
266
+	ctx, err = ContextWithRepositoryScope(ctx, refspec, false)
267 267
 	if err != nil {
268 268
 		return "", ocispec.Descriptor{}, err
269 269
 	}
... ...
@@ -26,10 +26,10 @@ import (
26 26
 	"github.com/containerd/containerd/reference"
27 27
 )
28 28
 
29
-// repositoryScope returns a repository scope string such as "repository:foo/bar:pull"
29
+// RepositoryScope returns a repository scope string such as "repository:foo/bar:pull"
30 30
 // for "host/foo/bar:baz".
31 31
 // When push is true, both pull and push are added to the scope.
32
-func repositoryScope(refspec reference.Spec, push bool) (string, error) {
32
+func RepositoryScope(refspec reference.Spec, push bool) (string, error) {
33 33
 	u, err := url.Parse("dummy://" + refspec.Locator)
34 34
 	if err != nil {
35 35
 		return "", err
... ...
@@ -45,9 +45,9 @@ func repositoryScope(refspec reference.Spec, push bool) (string, error) {
45 45
 // value: []string (e.g. {"registry:foo/bar:pull"})
46 46
 type tokenScopesKey struct{}
47 47
 
48
-// contextWithRepositoryScope returns a context with tokenScopesKey{} and the repository scope value.
49
-func contextWithRepositoryScope(ctx context.Context, refspec reference.Spec, push bool) (context.Context, error) {
50
-	s, err := repositoryScope(refspec, push)
48
+// ContextWithRepositoryScope returns a context with tokenScopesKey{} and the repository scope value.
49
+func ContextWithRepositoryScope(ctx context.Context, refspec reference.Spec, push bool) (context.Context, error) {
50
+	s, err := RepositoryScope(refspec, push)
51 51
 	if err != nil {
52 52
 		return nil, err
53 53
 	}
... ...
@@ -66,9 +66,9 @@ func WithScope(ctx context.Context, scope string) context.Context {
66 66
 	return context.WithValue(ctx, tokenScopesKey{}, scopes)
67 67
 }
68 68
 
69
-// contextWithAppendPullRepositoryScope is used to append repository pull
69
+// ContextWithAppendPullRepositoryScope is used to append repository pull
70 70
 // scope into existing scopes indexed by the tokenScopesKey{}.
71
-func contextWithAppendPullRepositoryScope(ctx context.Context, repo string) context.Context {
71
+func ContextWithAppendPullRepositoryScope(ctx context.Context, repo string) context.Context {
72 72
 	return WithScope(ctx, fmt.Sprintf("repository:%s:pull", repo))
73 73
 }
74 74
 
... ...
@@ -22,6 +22,7 @@ import (
22 22
 	"context"
23 23
 	"fmt"
24 24
 	"io"
25
+	"io/ioutil"
25 26
 	"net"
26 27
 	"os"
27 28
 	"os/exec"
... ...
@@ -67,22 +68,24 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
67 67
 		}
68 68
 		defer f.Close()
69 69
 
70
-		var stdoutLog io.ReadWriteCloser
71
-		var stderrLog io.ReadWriteCloser
72
-		if debug {
73
-			stdoutLog, err = v1.OpenShimStdoutLog(ctx, config.WorkDir)
74
-			if err != nil {
75
-				return nil, nil, errors.Wrapf(err, "failed to create stdout log")
76
-			}
77
-
78
-			stderrLog, err = v1.OpenShimStderrLog(ctx, config.WorkDir)
79
-			if err != nil {
80
-				return nil, nil, errors.Wrapf(err, "failed to create stderr log")
81
-			}
70
+		stdoutCopy := ioutil.Discard
71
+		stderrCopy := ioutil.Discard
72
+		stdoutLog, err := v1.OpenShimStdoutLog(ctx, config.WorkDir)
73
+		if err != nil {
74
+			return nil, nil, errors.Wrapf(err, "failed to create stdout log")
75
+		}
82 76
 
83
-			go io.Copy(os.Stdout, stdoutLog)
84
-			go io.Copy(os.Stderr, stderrLog)
77
+		stderrLog, err := v1.OpenShimStderrLog(ctx, config.WorkDir)
78
+		if err != nil {
79
+			return nil, nil, errors.Wrapf(err, "failed to create stderr log")
85 80
 		}
81
+		if debug {
82
+			stdoutCopy = os.Stdout
83
+			stderrCopy = os.Stderr
84
+		}
85
+
86
+		go io.Copy(stdoutCopy, stdoutLog)
87
+		go io.Copy(stderrCopy, stderrLog)
86 88
 
87 89
 		cmd, err := newCommand(binary, daemonAddress, debug, config, f, stdoutLog, stderrLog)
88 90
 		if err != nil {
... ...
@@ -19,10 +19,14 @@ package shim
19 19
 import (
20 20
 	"context"
21 21
 	"io"
22
+	"net/url"
23
+	"os"
22 24
 	"sync"
23 25
 	"syscall"
24 26
 
25 27
 	"github.com/containerd/console"
28
+	"github.com/containerd/containerd/namespaces"
29
+	"github.com/containerd/containerd/runtime"
26 30
 	"github.com/containerd/fifo"
27 31
 	"github.com/pkg/errors"
28 32
 )
... ...
@@ -31,7 +35,7 @@ type linuxPlatform struct {
31 31
 	epoller *console.Epoller
32 32
 }
33 33
 
34
-func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console, stdin, stdout, stderr string, wg *sync.WaitGroup) (console.Console, error) {
34
+func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console, id, stdin, stdout, stderr string, wg *sync.WaitGroup) (cons console.Console, retErr error) {
35 35
 	if p.epoller == nil {
36 36
 		return nil, errors.New("uninitialized epoller")
37 37
 	}
... ...
@@ -59,26 +63,98 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console
59 59
 		}()
60 60
 	}
61 61
 
62
-	outw, err := fifo.OpenFifo(ctx, stdout, syscall.O_WRONLY, 0)
62
+	uri, err := url.Parse(stdout)
63 63
 	if err != nil {
64
-		return nil, err
64
+		return nil, errors.Wrap(err, "unable to parse stdout uri")
65 65
 	}
66
-	outr, err := fifo.OpenFifo(ctx, stdout, syscall.O_RDONLY, 0)
67
-	if err != nil {
68
-		return nil, err
66
+
67
+	switch uri.Scheme {
68
+	case "binary":
69
+		ns, err := namespaces.NamespaceRequired(ctx)
70
+		if err != nil {
71
+			return nil, err
72
+		}
73
+
74
+		cmd := runtime.NewBinaryCmd(uri, id, ns)
75
+
76
+		// In case of unexpected errors during logging binary start, close open pipes
77
+		var filesToClose []*os.File
78
+
79
+		defer func() {
80
+			if retErr != nil {
81
+				runtime.CloseFiles(filesToClose...)
82
+			}
83
+		}()
84
+
85
+		// Create pipe to be used by logging binary for Stdout
86
+		outR, outW, err := os.Pipe()
87
+		if err != nil {
88
+			return nil, errors.Wrap(err, "failed to create stdout pipes")
89
+		}
90
+		filesToClose = append(filesToClose, outR)
91
+
92
+		// Stderr is created for logging binary but unused when terminal is true
93
+		serrR, _, err := os.Pipe()
94
+		if err != nil {
95
+			return nil, errors.Wrap(err, "failed to create stderr pipes")
96
+		}
97
+		filesToClose = append(filesToClose, serrR)
98
+
99
+		r, w, err := os.Pipe()
100
+		if err != nil {
101
+			return nil, err
102
+		}
103
+		filesToClose = append(filesToClose, r)
104
+
105
+		cmd.ExtraFiles = append(cmd.ExtraFiles, outR, serrR, w)
106
+
107
+		wg.Add(1)
108
+		cwg.Add(1)
109
+		go func() {
110
+			cwg.Done()
111
+			io.Copy(outW, epollConsole)
112
+			outW.Close()
113
+			wg.Done()
114
+		}()
115
+
116
+		if err := cmd.Start(); err != nil {
117
+			return nil, errors.Wrap(err, "failed to start logging binary process")
118
+		}
119
+
120
+		// Close our side of the pipe after start
121
+		if err := w.Close(); err != nil {
122
+			return nil, errors.Wrap(err, "failed to close write pipe after start")
123
+		}
124
+
125
+		// Wait for the logging binary to be ready
126
+		b := make([]byte, 1)
127
+		if _, err := r.Read(b); err != nil && err != io.EOF {
128
+			return nil, errors.Wrap(err, "failed to read from logging binary")
129
+		}
130
+		cwg.Wait()
131
+
132
+	default:
133
+		outw, err := fifo.OpenFifo(ctx, stdout, syscall.O_WRONLY, 0)
134
+		if err != nil {
135
+			return nil, err
136
+		}
137
+		outr, err := fifo.OpenFifo(ctx, stdout, syscall.O_RDONLY, 0)
138
+		if err != nil {
139
+			return nil, err
140
+		}
141
+		wg.Add(1)
142
+		cwg.Add(1)
143
+		go func() {
144
+			cwg.Done()
145
+			p := bufPool.Get().(*[]byte)
146
+			defer bufPool.Put(p)
147
+			io.CopyBuffer(outw, epollConsole, *p)
148
+			outw.Close()
149
+			outr.Close()
150
+			wg.Done()
151
+		}()
152
+		cwg.Wait()
69 153
 	}
70
-	wg.Add(1)
71
-	cwg.Add(1)
72
-	go func() {
73
-		cwg.Done()
74
-		p := bufPool.Get().(*[]byte)
75
-		defer bufPool.Put(p)
76
-		io.CopyBuffer(outw, epollConsole, *p)
77
-		outw.Close()
78
-		outr.Close()
79
-		wg.Done()
80
-	}()
81
-	cwg.Wait()
82 154
 	return epollConsole, nil
83 155
 }
84 156
 
... ...
@@ -21,17 +21,22 @@ package shim
21 21
 import (
22 22
 	"context"
23 23
 	"io"
24
+	"net/url"
25
+	"os"
24 26
 	"sync"
25 27
 	"syscall"
26 28
 
27 29
 	"github.com/containerd/console"
30
+	"github.com/containerd/containerd/namespaces"
31
+	"github.com/containerd/containerd/runtime"
28 32
 	"github.com/containerd/fifo"
33
+	"github.com/pkg/errors"
29 34
 )
30 35
 
31 36
 type unixPlatform struct {
32 37
 }
33 38
 
34
-func (p *unixPlatform) CopyConsole(ctx context.Context, console console.Console, stdin, stdout, stderr string, wg *sync.WaitGroup) (console.Console, error) {
39
+func (p *unixPlatform) CopyConsole(ctx context.Context, console console.Console, id, stdin, stdout, stderr string, wg *sync.WaitGroup) (cons console.Console, retErr error) {
35 40
 	var cwg sync.WaitGroup
36 41
 	if stdin != "" {
37 42
 		in, err := fifo.OpenFifo(ctx, stdin, syscall.O_RDONLY, 0)
... ...
@@ -47,28 +52,98 @@ func (p *unixPlatform) CopyConsole(ctx context.Context, console console.Console,
47 47
 			io.CopyBuffer(console, in, *p)
48 48
 		}()
49 49
 	}
50
-	outw, err := fifo.OpenFifo(ctx, stdout, syscall.O_WRONLY, 0)
50
+	uri, err := url.Parse(stdout)
51 51
 	if err != nil {
52
-		return nil, err
52
+		return nil, errors.Wrap(err, "unable to parse stdout uri")
53 53
 	}
54
-	outr, err := fifo.OpenFifo(ctx, stdout, syscall.O_RDONLY, 0)
55
-	if err != nil {
56
-		return nil, err
54
+
55
+	switch uri.Scheme {
56
+	case "binary":
57
+		ns, err := namespaces.NamespaceRequired(ctx)
58
+		if err != nil {
59
+			return nil, err
60
+		}
61
+
62
+		cmd := runtime.NewBinaryCmd(uri, id, ns)
63
+
64
+		// In case of unexpected errors during logging binary start, close open pipes
65
+		var filesToClose []*os.File
66
+
67
+		defer func() {
68
+			if retErr != nil {
69
+				runtime.CloseFiles(filesToClose...)
70
+			}
71
+		}()
72
+
73
+		// Create pipe to be used by logging binary for Stdout
74
+		outR, outW, err := os.Pipe()
75
+		if err != nil {
76
+			return nil, errors.Wrap(err, "failed to create stdout pipes")
77
+		}
78
+		filesToClose = append(filesToClose, outR)
79
+
80
+		// Stderr is created for logging binary but unused when terminal is true
81
+		serrR, _, err := os.Pipe()
82
+		if err != nil {
83
+			return nil, errors.Wrap(err, "failed to create stderr pipes")
84
+		}
85
+		filesToClose = append(filesToClose, serrR)
86
+
87
+		r, w, err := os.Pipe()
88
+		if err != nil {
89
+			return nil, err
90
+		}
91
+		filesToClose = append(filesToClose, r)
92
+
93
+		cmd.ExtraFiles = append(cmd.ExtraFiles, outR, serrR, w)
94
+
95
+		wg.Add(1)
96
+		cwg.Add(1)
97
+		go func() {
98
+			cwg.Done()
99
+			io.Copy(outW, console)
100
+			outW.Close()
101
+			wg.Done()
102
+		}()
103
+
104
+		if err := cmd.Start(); err != nil {
105
+			return nil, errors.Wrap(err, "failed to start logging binary process")
106
+		}
107
+
108
+		// Close our side of the pipe after start
109
+		if err := w.Close(); err != nil {
110
+			return nil, errors.Wrap(err, "failed to close write pipe after start")
111
+		}
112
+
113
+		// Wait for the logging binary to be ready
114
+		b := make([]byte, 1)
115
+		if _, err := r.Read(b); err != nil && err != io.EOF {
116
+			return nil, errors.Wrap(err, "failed to read from logging binary")
117
+		}
118
+		cwg.Wait()
119
+
120
+	default:
121
+		outw, err := fifo.OpenFifo(ctx, stdout, syscall.O_WRONLY, 0)
122
+		if err != nil {
123
+			return nil, err
124
+		}
125
+		outr, err := fifo.OpenFifo(ctx, stdout, syscall.O_RDONLY, 0)
126
+		if err != nil {
127
+			return nil, err
128
+		}
129
+		wg.Add(1)
130
+		cwg.Add(1)
131
+		go func() {
132
+			cwg.Done()
133
+			p := bufPool.Get().(*[]byte)
134
+			defer bufPool.Put(p)
135
+			io.CopyBuffer(outw, console, *p)
136
+			outw.Close()
137
+			outr.Close()
138
+			wg.Done()
139
+		}()
140
+		cwg.Wait()
57 141
 	}
58
-	wg.Add(1)
59
-	cwg.Add(1)
60
-	go func() {
61
-		cwg.Done()
62
-		p := bufPool.Get().(*[]byte)
63
-		defer bufPool.Put(p)
64
-
65
-		io.CopyBuffer(outw, console, *p)
66
-		console.Close()
67
-		outr.Close()
68
-		outw.Close()
69
-		wg.Done()
70
-	}()
71
-	cwg.Wait()
72 142
 	return console, nil
73 143
 }
74 144
 
... ...
@@ -1,4 +1,4 @@
1
-// +build darwin freebsd
1
+// +build darwin freebsd netbsd
2 2
 
3 3
 /*
4 4
    Copyright The containerd Authors.
... ...
@@ -1,14 +1,14 @@
1 1
 github.com/beorn7/perks                             v1.0.1
2 2
 github.com/BurntSushi/toml                          v0.3.1
3 3
 github.com/cespare/xxhash/v2                        v2.1.1
4
-github.com/containerd/btrfs                         153935315f4ab9be5bf03650a1341454b05efa5d
5
-github.com/containerd/cgroups                       318312a373405e5e91134d8063d04d59768a1bff
6
-github.com/containerd/console                       v1.0.0
4
+github.com/containerd/btrfs                         404b9149801e455c8076f615b06dc0abee0a977a
5
+github.com/containerd/cgroups                       0b889c03f102012f1d93a97ddd3ef71cd6f4f510
6
+github.com/containerd/console                       v1.0.1
7 7
 github.com/containerd/continuity                    efbc4488d8fe1bdc16bde3b2d2990d9b3a899165
8
-github.com/containerd/fifo                          f15a3290365b9d2627d189e619ab4008e0069caf
8
+github.com/containerd/fifo                          0724c46b320cf96bb172a0550c19a4b1fca4dacb
9 9
 github.com/containerd/go-runc                       7016d3ce2328dd2cb1192b2076ebd565c4e8df0c
10
-github.com/containerd/nri                           0afc7f031eaf9c7d9c1a381b7ab5462e89c998fc
11
-github.com/containerd/ttrpc                         v1.0.1
10
+github.com/containerd/nri                           eb1350a75164f76de48e3605389e7a3fbc85d06e
11
+github.com/containerd/ttrpc                         v1.0.2
12 12
 github.com/containerd/typeurl                       v1.0.1
13 13
 github.com/coreos/go-systemd/v22                    v22.1.0
14 14
 github.com/cpuguy83/go-md2man/v2                    v2.0.0
... ...
@@ -26,10 +26,10 @@ github.com/hashicorp/errwrap                        v1.0.0
26 26
 github.com/hashicorp/go-multierror                  v1.0.0
27 27
 github.com/hashicorp/golang-lru                     v0.5.3
28 28
 github.com/imdario/mergo                            v0.3.7
29
-github.com/konsorten/go-windows-terminal-sequences  v1.0.3
30 29
 github.com/matttproud/golang_protobuf_extensions    v1.0.1
31 30
 github.com/Microsoft/go-winio                       v0.4.14
32
-github.com/Microsoft/hcsshim                        v0.8.9
31
+github.com/Microsoft/hcsshim                        v0.8.10
32
+github.com/moby/sys                                 symlink/v0.1.0
33 33
 github.com/opencontainers/go-digest                 v1.0.0
34 34
 github.com/opencontainers/image-spec                v1.0.1
35 35
 github.com/opencontainers/runc                      v1.0.0-rc92
... ...
@@ -41,14 +41,14 @@ github.com/prometheus/common                        v0.9.1
41 41
 github.com/prometheus/procfs                        v0.0.11
42 42
 github.com/russross/blackfriday/v2                  v2.0.1
43 43
 github.com/shurcooL/sanitized_anchor_name           v1.0.0
44
-github.com/sirupsen/logrus                          v1.6.0
44
+github.com/sirupsen/logrus                          v1.7.0
45 45
 github.com/syndtr/gocapability                      d98352740cb2c55f81556b63d4a1ec64c5a319c2
46 46
 github.com/urfave/cli                               v1.22.1 # NOTE: urfave/cli must be <= v1.22.1 due to a regression: https://github.com/urfave/cli/issues/1092
47 47
 go.etcd.io/bbolt                                    v1.3.5
48 48
 go.opencensus.io                                    v0.22.0
49 49
 golang.org/x/net                                    ab34263943818b32f575efc978a3d24e80b04bd7
50 50
 golang.org/x/sync                                   42b317875d0fa942474b76e1b46a6060d720ae6e
51
-golang.org/x/sys                                    ed371f2e16b4b305ee99df548828de367527b76b
51
+golang.org/x/sys                                    0aaa2718063a42560507fce2cc04508608ca23b3
52 52
 golang.org/x/text                                   v0.3.3
53 53
 google.golang.org/genproto                          e50cd9704f63023d62cd06a1994b98227fc4d21a
54 54
 google.golang.org/grpc                              v1.27.1
... ...
@@ -58,9 +58,7 @@ gotest.tools/v3                                     v3.0.2
58 58
 github.com/cilium/ebpf                              1c8d4c9ef7759622653a1d319284a44652333b28
59 59
 
60 60
 # cri dependencies
61
-github.com/containerd/cri                           35e623e6bf7512e8c82b8ac6052cb1d720189f28 # master
62 61
 github.com/davecgh/go-spew                          v1.1.1
63
-github.com/docker/docker                            4634ce647cf2ce2c6031129ccd109e557244986f
64 62
 github.com/docker/spdystream                        449fdfce4d962303d702fec724ef0ad181c92528
65 63
 github.com/emicklei/go-restful                      v2.9.5
66 64
 github.com/go-logr/logr                             v0.2.0
... ...
@@ -69,21 +67,24 @@ github.com/json-iterator/go                         v1.1.10
69 69
 github.com/modern-go/concurrent                     1.0.3
70 70
 github.com/modern-go/reflect2                       v1.0.1
71 71
 github.com/opencontainers/selinux                   v1.6.0
72
+github.com/pmezard/go-difflib                       v1.0.0
73
+github.com/stretchr/testify                         v1.4.0
72 74
 github.com/tchap/go-patricia                        v2.2.6
73
-github.com/willf/bitset                             d5bec3311243426a3c6d1b7a795f24b17c686dbb # 1.1.10+ used by selinux pkg
75
+github.com/willf/bitset                             v1.1.11
74 76
 golang.org/x/crypto                                 75b288015ac94e66e3d6715fb68a9b41bf046ec2
75 77
 golang.org/x/oauth2                                 858c2ad4c8b6c5d10852cb89079f6ca1c7309787
76 78
 golang.org/x/time                                   555d28b269f0569763d25dbe1a237ae74c6bcc82
77 79
 gopkg.in/inf.v0                                     v0.9.1
78 80
 gopkg.in/yaml.v2                                    v2.2.8
79
-k8s.io/api                                          v0.19.0-rc.4
80
-k8s.io/apimachinery                                 v0.19.0-rc.4
81
-k8s.io/apiserver                                    v0.19.0-rc.4
82
-k8s.io/client-go                                    v0.19.0-rc.4
83
-k8s.io/cri-api                                      v0.19.0-rc.4
81
+k8s.io/api                                          v0.19.4
82
+k8s.io/apimachinery                                 v0.19.4
83
+k8s.io/apiserver                                    v0.19.4
84
+k8s.io/client-go                                    v0.19.4
85
+k8s.io/component-base                               v0.19.4
86
+k8s.io/cri-api                                      v0.19.4
84 87
 k8s.io/klog/v2                                      v2.2.0
85
-k8s.io/utils                                        2df71ebbae66f39338aed4cd0bb82d2212ee33cc
86
-sigs.k8s.io/structured-merge-diff/v3                v3.0.0
88
+k8s.io/utils                                        d5654de09c73da55eb19ae4ab4f734f7a61747a6
89
+sigs.k8s.io/structured-merge-diff/v4                v4.0.1
87 90
 sigs.k8s.io/yaml                                    v1.2.0
88 91
 
89 92
 # cni dependencies
... ...
@@ -99,8 +100,8 @@ github.com/fullsailor/pkcs7                         8306686428a5fe132eac8cb7c484
99 99
 gopkg.in/square/go-jose.v2                          v2.3.1
100 100
 
101 101
 # zfs dependencies
102
-github.com/containerd/zfs                           9abf673ca6ff9ab8d9bd776a4ceff8f6dc699c3d
102
+github.com/containerd/zfs                           0a33824f23a2ab8ec84166f47b571ecb793b0354
103 103
 github.com/mistifyio/go-zfs                         f784269be439d704d3dfa1906f45dd848fed2beb
104 104
 
105 105
 # aufs dependencies
106
-github.com/containerd/aufs                          371312c1e31c210a21e49bf3dfd3f31729ed9f2f
106
+github.com/containerd/aufs                          dab0cbea06f43329c07667afe1a70411ad555a86