Commit Graph

63 Commits

Author SHA1 Message Date
Claudiu Belu
5b222d54ad commands: Enables task metrics for Windows
The command already contains logic for Windows container
metrics, we just need to enable the command.

Signed-off-by: Claudiu Belu <cbelu@cloudbasesolutions.com>
2021-10-05 09:25:12 -07:00
jonyhy
e6ddffc2af fix: make exec-id flag required in exec command
Signed-off-by: jonyhy <yun.hao@daocloud.io>
2021-09-28 18:19:32 +08:00
Daniel Canter
27046a9e06 Fix cwd flag for ctr tasks exec
It seems like the cwd flag isn't used anywhere for ctr tasks exec. This change
just sets the cwd field on the spec for the execed process if a new one was
asked for, otherwise it will continue using whatever was on the containers spec.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
2021-09-02 03:59:56 -07:00
Akihiro Suda
d3aa7ee9f0
Run go fmt with Go 1.17
The new `go fmt` adds `//go:build` lines (https://golang.org/doc/go1.17#tools).

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-08-22 09:31:50 +09:00
Kazuyoshi Kato
1d3d08026d Support SIGRTMIN+n signals
systemd uses SIGRTMIN+n signals, but containerd didn't support the signals
since Go's sys/unix doesn't support them.

This change introduces SIGRTMIN+n handling by utilizing moby/sys/signal.

Fixes #5402.

https://www.freedesktop.org/software/systemd/man/systemd.html#Signals

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2021-07-26 09:36:43 -07:00
Samuel Karp
5dec27b6f1
ctr: exec handle pty resize after Start
Handle initial pty resize after the exec process has started and the pty
is available, consistent with the behavior of ctr run.

Signed-off-by: Samuel Karp <me@samuelkarp.com>
2021-05-25 00:12:21 -07:00
Samuel Karp
b9378b4529
ctr: exec setup IO with console
Use cio.WithStreams with explicit console device when --tty is passed,
consistent with how ctr run behaves.

Signed-off-by: Samuel Karp <me@samuelkarp.com>
2021-05-22 23:19:46 -07:00
acetang
5e94745f26 ctr: add --user for task exec
set user in exec container

$ ctr t exec --exec-id e1 --user admin container id
uid=500(admin) gid=500(admin) groups=500(admin)

Signed-off-by: chuangxue <chenglong.lcl@alibaba-inc.com>
Signed-off-by: acetang <aceapril@126.com>
2021-03-25 19:29:30 +08:00
Maksim An
ddb5e1651a Enhance logging driver and ctr tasks to support windows
Signed-off-by: Maksim An <maksiman@microsoft.com>
2021-01-21 12:17:32 -08:00
Phil Estes
534be84c5d
Merge pull request #4529 from gongguan/creator
avoid unnecessary NewCreator calls
2020-09-21 13:33:51 -04:00
Guanjun Gong
0dea724fc0 NewTask avoid unnecessary cio.NewCreator calls
Signed-off-by: Guanjun Gong <gongguanjun@hotmail.com>
2020-09-21 11:45:37 +08:00
Li Yuxuan
bdb5b2ce47 ctr: Return error if task.Metrics fails
Signed-off-by: Li Yuxuan <liyuxuan04@baidu.com>
2020-09-10 16:42:35 +08:00
Prashant Bhutani
35b63c064f Report correct stats for windows containers
Windows container stats were reporting incorrect metrics for cpu kernel runtime.

Signed-off-by: Prashant Bhutani <prbhutan@microsoft.com>
2020-08-12 00:51:37 +05:30
Boris Popovschi
49e7039a85 cpu metrics consistency
Signed-off-by: Boris Popovschi <zyqsempai@mail.ru>
2019-12-17 12:30:12 +02:00
Boris Popovschi
659c971cad task metrics fix
Signed-off-by: Boris Popovschi <zyqsempai@mail.ru>
2019-12-17 10:52:37 +02:00
bpopovschi
b98cc79184 Added memory and cpu metrics for cgroupv2
Signed-off-by: bpopovschi <zyqsempai@mail.ru>
2019-12-16 16:10:51 +02:00
Michael Crosby
5d93ece758
Merge pull request #3799 from AkihiroSuda/cgroup2
support cgroup2
2019-12-12 14:30:19 -05:00
Joakim Roubert
e0011978ff start.go: Improve help text
Change-Id: I9adfc27868b246fb85823d18c65f95668e3fbc58
Signed-off-by: Joakim Roubert <joakimr@axis.com>
2019-12-12 11:19:41 +01:00
Akihiro Suda
8f870c233f support cgroup2
* only shim v2 runc v2 ("io.containerd.runc.v2") is supported
* only PID metrics is implemented. Others should be implemented in separate PRs.
* lots of code duplication in v1 metrics and v2 metrics. Dedupe should be separate PR.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2019-12-12 02:56:51 +09:00
Justin Terry (VM)
37b56cafc6 Add ctr metrics support for Windows/LCOW containers
Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
2019-10-23 13:50:34 -07:00
Michael Crosby
8ff5827e98 Update cri and cgroup packages
This change includes a cri master bump and a cgroup bump for windows support
with cgroup stats and reusing the cgroup metric types.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-10-01 10:19:56 -04:00
Michael Crosby
f543f2fbcd Call CloseIO when stdin closes in ctr
Fixes #2439

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-07-26 19:52:03 +00:00
Phil Estes
15b59f9684
Merge pull request #3441 from YLonely/multiple-task-delete
Update ctr to support deleting multiple tasks at a time
2019-07-25 14:29:31 -04:00
BoWen Yan
392668d007 ctr:Support deleting multiple tasks at a time
Signed-off-by: BoWen Yan <loneybw@gmail.com>
2019-07-25 09:59:15 +08:00
Maksym Pavlenko
46af8ccd2d Check exec log flags compatibility
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
2019-07-02 09:53:11 -07:00
Maksym Pavlenko
6b59b425e2 Support --log-uri for exec subcommand
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
2019-07-01 13:32:37 -07: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
Justin Terry (VM)
00895670e7 Stop sending stderr with TTY on Windows
Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
2019-02-11 23:11:40 -08:00
Phil Estes
06e04bc5a9
Merge pull request #2830 from Ace-Tang/support_cr_without_image
cr: support checkpoint/restore without image
2018-12-20 13:24:37 -05:00
Michael Crosby
4a8acf54b1
Merge pull request #2793 from lifubang/runexecflag
fix container cmd args may parsed as ctr args
2018-12-04 11:05:51 -05:00
Lifubang
2d3a4f99ec should no defer when detach
Signed-off-by: Lifubang <lifubang@acmcoder.com>
2018-12-03 19:18:57 +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
461222dba8 fix: should get runtime name from container info
when use `ctr t checkpoint`, runtime name should get from container
info, but not passed by flag, since task has already running with
specified runtime

Signed-off-by: Ace-Tang <aceapril@126.com>
2018-11-23 15:39:43 +08:00
Lifubang
2101b1362e add ctr delete --exec-id to debug DeleteProcess
Signed-off-by: Lifubang <lifubang@acmcoder.com>
2018-11-20 19:53:06 +08:00
Lifubang
01f5aa3878 add flag -d for ctr t exec to run a service in container
Signed-off-by: Lifubang <lifubang@acmcoder.com>
2018-11-16 14:29:45 +08:00
Lifubang
bd2a21985c fix container cmd args may parsed as ctr args
Signed-off-by: Lifubang <lifubang@acmcoder.com>
2018-11-15 18:32:04 +08:00
Ace-Tang
c3cac72b92 ctr: fix potential panic in metric
Signed-off-by: Ace-Tang <aceapril@126.com>
2018-10-23 14:01:50 +08:00
Ace-Tang
7ea75ef4a9 ctr: add some metric item
add memory limit, pid info into metric subcommand, since moby also
show them. As blkio read/write IO need more calculation,not add them.

Signed-off-by: Ace-Tang <aceapril@126.com>
2018-10-16 16:54:06 +08:00
Samuel Karp
607888ce29 ctr: make kill use stop-signal by default
The OCI image specification includes a `StopSignal` field in the image
configuration, denoting the system call signal to be sent to the
container to exit.  This commit adds a new `WithImageStopSignal` container
option that can be used for storing the `StopSignal` field as a label on
the container.  This commit also adjusts `ctr run` to call
`WithImageStopSignal` and `ctr tasks kill` to send the signal stored in
that label by default.

Signed-off-by: Samuel Karp <skarp@amazon.com>
2018-09-27 15:53:38 -07:00
Samuel Karp
b392a3a8e4 signals: move ParseSignal to containerd package
Signed-off-by: Samuel Karp <skarp@amazon.com>
2018-09-27 15:53:38 -07:00
Lifubang
66f6dd8b3b add -detach flag for 'ctr t start'
Signed-off-by: Lifubang <lifubang@aliyun.com>
2018-08-27 18:43:56 +08:00
Michael Crosby
4f644dbfd5 Copy io into and out of console
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-08-22 14:04:17 -04:00
Justin Terry (VM)
790c3a3663 Remove extra allocation in NewTask
Reorders the code so that it doesnt overwrite the previous allocation
when creating a NewTask via ctr.exe

Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
2018-08-01 13:22:18 -07:00
Samuel Karp
9a34bb046a metrics: add optional json output
Signed-off-by: Samuel Karp <skarp@amazon.com>
2018-07-27 15:21:08 -07:00
Samuel Karp
2c87d120df ctr: add new metrics subcommand
Signed-off-by: Samuel Karp <skarp@amazon.com>
2018-07-27 09:37:57 -07:00
Andrei Vagin
fc2fcf6b2a task: WithExit() doesn't have to overwrite existing options
Signed-off-by: Andrei Vagin <avagin@openvz.org>
2018-07-20 13:19:05 -07: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
da1b5470cd Runtime v2
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-07-17 10:21:29 -04:00
Michael Crosby
fdceb13b14 Add cio.Load for loading io set
This adds a `Load` Opt for cio to load a tasks io/fifos without
attaching or starting the copy routines.

It adds the load method in `ctr` by default so that fifos or other IO
are removed from disk on delete methods inbetween command runs.  It is
not the default for all task loads for backwards compat. and a user may
want to keep io around to reuse or if log files are used.

Fixes #2421

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-06-26 11:48:26 -04:00