Commit Graph

82 Commits

Author SHA1 Message Date
Michael Crosby
1a8df3f237 Reserve exec id to prevent race
ref #2820

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-06-21 14:52:44 -04:00
Lantao Liu
48b81e872c Do not return error when rootfs already exists.
Signed-off-by: Lantao Liu <lantaol@google.com>
2019-05-22 15:57:19 -07:00
Michael Crosby
fe6a2b03ed Add shim cgroup support for v2 runtimes
Closes #3198

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-05-20 16:04:06 +00:00
Michael Crosby
57fbb16234
Merge pull request #3149 from lifubang/pidnamespace
fix killall when use pidnamespace
2019-05-09 14:28:44 -04:00
Michael Crosby
19af235051
Merge pull request #3148 from masters-of-cats/wip-rootless-containerd
Skip rootfs unmount when no mounts are provided
2019-05-07 10:39:02 -04:00
Michael Crosby
ae87730ad2 Improve shim shutdown logic
Shims no longer call `os.Exit` but close the context on shutdown so that
events and other resources have hit the `defer`s.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-04-10 18:17:07 -04:00
Michael Crosby
a6f587e4c4 Use ttrpc to publish runtime v2 events
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-04-09 14:38:50 -04:00
Georgi Sabev
c0f0b21314 Apply PR feedback
* Rootfs dir is created during container creation not during bundle
  creation
* Add support for v2
* UnmountAll is a no-op when the path to unmount (i.e. the rootfs dir)
  does not exist or is invalid

Co-authored-by: Danail Branekov <danailster@gmail.com>
Signed-off-by: Georgi Sabev <georgethebeatle@gmail.com>
2019-04-04 18:40:30 +03:00
Sebastiaan van Stijn
2d11f5e6d5
Regenerate protobufs
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-04-03 23:41:15 +02:00
Sebastiaan van Stijn
01310eaebc
do not use unkeyed fields in compose literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-04-03 22:20:39 +02:00
Lifubang
872296642a fix shouldKillAllOnExit check for v2
Signed-off-by: Lifubang <lifubang@acmcoder.com>
2019-03-30 11:37:14 +08:00
Michael Crosby
e6ae9cc64f Shim pluggable logging
Closes #603

This adds logging facilities at the shim level to provide minimal I/O
overhead and pluggable logging options.  Log handling is done within the
shim so that all I/O, cpu, and memory can be charged to the container.

A sample logging driver setting up logging for a container the systemd
journal looks like this:

```go
package main

import (
	"bufio"
	"context"
	"fmt"
	"io"
	"sync"

	"github.com/containerd/containerd/runtime/v2/logging"
	"github.com/coreos/go-systemd/journal"
)

func main() {
	logging.Run(log)
}

func log(ctx context.Context, config *logging.Config, ready func() error) error {
	// construct any log metadata for the container
	vars := map[string]string{
		"SYSLOG_IDENTIFIER": fmt.Sprintf("%s:%s", config.Namespace, config.ID),
	}
	var wg sync.WaitGroup
	wg.Add(2)
	// forward both stdout and stderr to the journal
	go copy(&wg, config.Stdout, journal.PriInfo, vars)
	go copy(&wg, config.Stderr, journal.PriErr, vars)

	// signal that we are ready and setup for the container to be started
	if err := ready(); err != nil {
		return err
	}
	wg.Wait()
	return nil
}

func copy(wg *sync.WaitGroup, r io.Reader, pri journal.Priority, vars map[string]string) {
	defer wg.Done()
	s := bufio.NewScanner(r)
	for s.Scan() {
		if s.Err() != nil {
			return
		}
		journal.Send(s.Text(), pri, vars)
	}
}
```

A `logging` package has been created to assist log developers create
logging plugins for containerd.

This uses a URI based approach for logging drivers that can be expanded
in the future.

Supported URI scheme's are:

* binary
* fifo
* file

You can pass the log url via ctr on the command line:

```bash
> ctr run --rm --runtime io.containerd.runc.v2 --log-uri binary://shim-journald docker.io/library/redis:alpine redis
```

```bash
> journalctl -f -t default:redis

-- Logs begin at Tue 2018-12-11 16:29:51 EST. --
Mar 08 16:08:22 deathstar default:redis[120760]: 1:C 08 Mar 2019 21:08:22.703 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
Mar 08 16:08:22 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:22.704 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
Mar 08 16:08:22 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:22.704 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
Mar 08 16:08:22 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:22.704 # Current maximum open files is 1024. maxclients has been reduced to 992 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
Mar 08 16:08:22 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:22.705 * Running mode=standalone, port=6379.
Mar 08 16:08:22 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:22.705 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
Mar 08 16:08:22 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:22.705 # Server initialized
Mar 08 16:08:22 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:22.705 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
Mar 08 16:08:22 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:22.705 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
Mar 08 16:08:22 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:22.705 * Ready to accept connections
Mar 08 16:08:50 deathstar default:redis[120760]: 1:signal-handler (1552079330) Received SIGINT scheduling shutdown...
Mar 08 16:08:50 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:50.405 # User requested shutdown...
Mar 08 16:08:50 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:50.406 * Saving the final RDB snapshot before exiting.
Mar 08 16:08:50 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:50.452 * DB saved on disk
Mar 08 16:08:50 deathstar default:redis[120760]: 1:M 08 Mar 2019 21:08:50.453 # Redis is now ready to exit, bye bye...
```

The following client side Opts are added:

```go
// LogURI provides the raw logging URI
func LogURI(uri *url.URL) Creator { }
// BinaryIO forwards contianer STDOUT|STDERR directly to a logging binary
func BinaryIO(binary string, args map[string]string) Creator {}
```

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-03-12 12:18:28 -04:00
Michael Crosby
84a24711e8 Add runc.v2 multi-shim
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-02-21 11:09:46 -05:00
Michael Crosby
6bcbf88f82 Move runc shim code into common package
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-02-21 10:47:41 -05:00
Michael Crosby
85aa8ad361 Move task events to runc v2 shim
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-01-25 14:15:43 -05:00
Lantao Liu
26ab393e7d Use context.Background for O_NONBLOCK OpenFifo.
Signed-off-by: Lantao Liu <lantaol@google.com>
2019-01-23 10:18:54 -08:00
Ace-Tang
6593399e9f cr: support checkpoint/restore without image
support checkpoint without committing a checkpoint dir into a
checkpoint image and restore without untar image into checkpoint
directory. support for both v1 and v2 runtime

Signed-off-by: Ace-Tang <aceapril@126.com>
2018-11-29 10:19:39 +08:00
Ace-Tang
fd16bf6d46 runtimev2: add image-path and work-path for c/r
add ImagePath and WorkPath for checkpoint process, add CriuImagePath
and CriuWorkPath for create process in runtime v2 protobuf

Signed-off-by: Ace-Tang <aceapril@126.com>
2018-11-24 23:08:25 +08:00
Lifubang
e76a8879eb fix pipe in broken may cause shim lock forever for runtime v1
Signed-off-by: Lifubang <lifubang@acmcoder.com>
2018-11-19 09:25:43 +08:00
Lifubang
b3438f7a6f fix pipe in broken may cause shim lock forever for runtime v2
Signed-off-by: Lifubang <lifubang@acmcoder.com>
2018-11-19 09:02:49 +08:00
Ace-Tang
c4feaa75cf fix: fix failed to get container-shim relation with io.containerd.runc.v1
add '-id' flag when start container with io.containerd.runc.v1 shim, or user
can not get container-shim relation from 'ps -ef',like

```
/usr/bin/containerd-shim-runc-v1 -namespace default -address
/run/containerd/containerd.sock -publish-binary /usr/bin/containerd
```

Signed-off-by: Ace-Tang <aceapril@126.com>
2018-11-09 11:01:35 +08:00
Wei Fu
38d7d59e8a enhance: update v1/v2 runtime
1. avoid dead lock during kill, fetch allProcesses before handle events
2. use argu's ctx instead of context.Backgroud() in openlog

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2018-11-06 22:48:43 +08:00
Tom Godkin
b5ccc66c2c Do not kill all on task delete by default
- Still KillAll if the task uses the hosts pid namespace
 - Test for both host pid namespace and normal cases

Co-authored-by: Oliver Stenbom <ostenbom@pivotal.io>
Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
Signed-off-by: Oliver Stenbom <ostenbom@pivotal.io>
2018-08-30 15:58:33 +01:00
Michael Crosby
2205e8d67a Improve shim locking
Only lock around shim state and not on actions

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-08-29 11:22:02 -04:00
Michael Crosby
d50e25360c Add context cancel for epoll
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-08-29 10:44:47 -04:00
Michael Crosby
bc1ff51411 Don't block on STDIN open
This was found testing other runtime shims that are faster than runc(no
containerization).  This is a race that can cause the shim to block
forever.  It's not an issue for out/err because we open both sides of
the pipe, but for stdin, it expects the client to have it opened.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-08-27 10:44:53 -04:00
Michael Crosby
13549f7a07 Abstract to SocketAddress
This updates some methods for cross platform use as well as unifying
_unix files.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-07-27 12:39:53 -04:00
Michael Crosby
17ab11a236 Fixes for runtimev2 and checkpoint restore
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-07-20 12:09:29 -04:00
Michael Crosby
d53a96fbe4 Add comments for oci protos
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-07-18 15:12:18 -04:00
Michael Crosby
fd31052d9c Add oom events to shim
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-07-17 16:52:05 -04:00
Michael Crosby
7e49c601a8 Add shim start for shim creation
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-07-17 10:21:29 -04:00
Michael Crosby
da1b5470cd Runtime v2
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-07-17 10:21:29 -04:00