Commit Graph

39 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
eaedadbed0
replace strings.Split(N) for strings.Cut() or alternatives
Go 1.18 and up now provides a strings.Cut() which is better suited for
splitting key/value pairs (and similar constructs), and performs better:

```go
func BenchmarkSplit(b *testing.B) {
        b.ReportAllocs()
        data := []string{"12hello=world", "12hello=", "12=hello", "12hello"}
        for i := 0; i < b.N; i++ {
                for _, s := range data {
                        _ = strings.SplitN(s, "=", 2)[0]
                }
        }
}

func BenchmarkCut(b *testing.B) {
        b.ReportAllocs()
        data := []string{"12hello=world", "12hello=", "12=hello", "12hello"}
        for i := 0; i < b.N; i++ {
                for _, s := range data {
                        _, _, _ = strings.Cut(s, "=")
                }
        }
}
```

    BenchmarkSplit
    BenchmarkSplit-10            8244206               128.0 ns/op           128 B/op          4 allocs/op
    BenchmarkCut
    BenchmarkCut-10             54411998                21.80 ns/op            0 B/op          0 allocs/op

While looking at occurrences of `strings.Split()`, I also updated some for alternatives,
or added some constraints; for cases where an specific number of items is expected, I used `strings.SplitN()`
with a suitable limit. This prevents (theoretical) unlimited splits.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-07 10:02:25 +01:00
Wei Fu
5f9b318e50 bin/ctr,integration: new runc-shim with failpoint
Added new runc shim binary in integration testing.

The shim is named by io.containerd.runc-fp.v1, which allows us to use
additional OCI annotation `io.containerd.runtime.v2.shim.failpoint.*` to
setup shim task API's failpoint. Since the shim can be shared with
multiple container, like what kubernetes pod does, the failpoint will be
initialized during setup the shim server. So, the following the
container's OCI failpoint's annotation will not work.

This commit also updates the ctr tool that we can use `--annotation` to
specify annotations when run container. For example:

```bash
➜  ctr run -d --runtime runc-fp.v1 \
     --annotation "io.containerd.runtime.v2.shim.failpoint.Kill=1*error(sorry)" \
     docker.io/library/alpine:latest testing sleep 1d

➜  ctr t ls
TASK       PID       STATUS
testing    147304    RUNNING

➜  ctr t kill -s SIGKILL testing
ctr: sorry: unknown

➜  ctr t kill -s SIGKILL testing

➜  sudo ctr t ls
TASK       PID       STATUS
testing    147304    STOPPED
```

The runc-fp.v1 shim is based on core runc.v2. We can use it to inject
failpoint during testing complicated or big transcation API, like
kubernetes PodRunPodsandbox.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2022-07-22 23:25:40 +08:00
Ye Sijun
f77d45e3ba
ctr: support --user for run/create
Signed-off-by: Ye Sijun <junnplus@gmail.com>
2022-07-12 11:53:03 +08:00
Samuel Karp
6e53ffb105
ctr: add --hostname flag to create, run
Signed-off-by: Samuel Karp <me@samuelkarp.com>
2022-06-20 15:11:44 -07:00
xin.li
8494f7f117 adjust format in comment
Signed-off-by: xin.li <xin.li@daocloud.io>
2022-05-19 00:24:56 +08:00
Antti Kervinen
10576c298e cri: support blockio class in pod and container annotations
This patch adds support for a container annotation and two separate
pod annotations for controlling the blockio class of containers.

The container annotation can be used by a CRI client:
  "io.kubernetes.cri.blockio-class"

Pod annotations specify the blockio class in the K8s pod spec level:
  "blockio.resources.beta.kubernetes.io/pod"
  (pod-wide default for all containers within)

  "blockio.resources.beta.kubernetes.io/container.<container_name>"
  (container-specific overrides)

Correspondingly, this patch adds support for --blockio-class and
--blockio-config-file to ctr, too.

This implementation follows the resource class annotation pattern
introduced in RDT and merged in commit 893701220.

Signed-off-by: Antti Kervinen <antti.kervinen@intel.com>
2022-04-29 11:44:09 +03:00
Kazuyoshi Kato
50ca5727b2
Merge pull request #6519 from ginglis13/ctr-runtime-path
ctr: improve error relative shim path error msg
2022-03-14 09:49:27 -07:00
Paul "TBBle" Hampson
2a425990cf Implement --device idType://id for ctr run on Windows
Also fixes the issue that `ctr run` on Windows offered help for the
non-Windows implementation, but was silently ignored.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2022-03-12 08:16:43 +11:00
Gavin Inglis
7b045ea5f0 ctr: improve error relative shim path error msg
addresses https://github.com/containerd/containerd/issues/6464

Return an error if a runtime provided is relative.

Add context to the usage for `ctr run --runtime` indicating that
absolute path to runtime binary must be provided.

Signed-off-by: Gavin Inglis <giinglis@amazon.com>
2022-03-03 23:28:03 +00:00
Markus Lehtonen
9e755d12e2 cmd: add --rdt-class command line option
A new option for setting the RDT class (or CLOS) from the command line.

Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
2022-01-04 09:27:54 +02:00
Manabu Sugimoto
95b3ab2a4a ctr: Add Linux Capabilities control flags
This allows Linux Capabilities to be modified via `ctr`.

e.g.
```
$ sudo ./bin/ctr run --cap-add "CAP_SYS_ADMIN" --cap-drop "CAP_NET_RAW" \
--rm docker.io/library/busybox:latest foo cat /proc/self/status | grep Cap
CapInh: 00000000a82405fb
CapPrm: 00000000a82405fb
CapEff: 00000000a82405fb
CapBnd: 00000000a82405fb
CapAmb: 0000000000000000
```

Signed-off-by: Manabu Sugimoto <Manabu.Sugimoto@sony.com>
2021-11-25 14:50:43 +09:00
Yifan Yuan
bda7b58666 feat: Add snapshotter label to the new snapshot for container.
add '--snapshotter-labels' in ctr run and ctr c create
which can pass labels to snappshotter on preparing new
snapshot.

Pass command label to snapshotter can help it determine
which kind of writable snapshots should be provide.

For some snapshotter, such as overlaybd:
  ( https://github.com/alibaba/accelerated-container-image ),
it can provide 2 kind of writable snapshot (overlayfs dir or
 blockdevice) by command label values.

Signed-off-by: Yifan Yuan <tuji.yyf@alibaba-inc.com>
2021-06-28 20:08:01 +08:00
Michael Crosby
09d78bb6b9 allow multi gpu to be specified via ctr
Signed-off-by: Michael Crosby <michael@thepasture.io>
2021-06-21 23:49:43 -04:00
Maksym Pavlenko
22ef69d77d Support HTTP debug in ctr
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2021-03-22 09:32:34 -07:00
Brian Goff
7776e5ef2a Support adding devices by dir
This enables cases where devices exist in a subdirectory of /dev,
particularly where those device names are not portable across machines,
which makes it problematic to specify from a runtime such as cri.

Added this to `ctr` as well so I could test that the code at least
works.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2021-03-15 16:42:23 +00:00
Iceber Gu
d3ad7f3908
cmd/ctr: use e.g. in the command usage
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2021-03-15 13:48:25 +08:00
Michael Crosby
5f74840a9a
Merge pull request #4709 from AkihiroSuda/ctr-apparmor
ctr: add AppArmor flags
2020-11-10 10:21:51 -05:00
Akihiro Suda
9d54648be3
ctr: add AppArmor flags
e.g.
```
$ sudo ./bin/ctr run --apparmor-default-profile "cri-containerd.apparmor.d" docker.io/library/alpine:latest foo cat /proc/self/attr/current
cri-containerd.apparmor.d (enforce)
```

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-11-10 14:19:35 +09:00
Evan Hazlett
ef48ef1e4c
add config path option to ctr for runtime
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
2020-10-29 15:21:37 +00:00
Shishir Mahajan
1eae524df6 ctr: CLI Flag (seccomp-profile) for setting custom seccomp profile.
Signed-off-by: Shishir Mahajan <smahajan@roblox.com>
2020-09-02 16:13:11 -07:00
John Millikin
b8ccdcb07d
Add ctr flags for configuring default TLS credentials.
Signed-off-by: John Millikin <jmillikin@stripe.com>
2020-05-27 21:59:33 +09:00
Derek McGowan
547301cb0c
Update ctr resolver to use new config package
Moved registry host configuration to the config package
and allows support of loading configurations from a
directory when the hosts are being resolved.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2020-03-31 22:52:10 -07:00
Akihiro Suda
dc131aa862
support loading certs from a directory
Add `remotes/certutil` functions for loading `ca.crt`, `client.cert`, and `client.key` into `tls.Config` from a directory like `/etc/docker/certs.d/<hostname>.

See https://docs.docker.com/engine/security/certificates/ .

Client applications including CRI plugin are expected to configure the resolver using these functions.

As an example, the `ctr` tool is extended to support `ctr images pull --certs-dir=/etc/docker/certs.d example.com/foo/bar:baz`.

Tested with Harbor 1.8.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-03-31 21:48:08 -07:00
Michael Crosby
fa11147e5f Add --env-file to ctr
Closes #3517

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-09-06 16:25:02 -04:00
Michael Crosby
779701b29c Add --seccomp flag to ctr
This enables testing of containers with the default seccomp profile

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-08-29 13:02:21 -04:00
Michael Crosby
d085d9b464 Remove encryption code from containerd core
We are separating out the encryption code and have designed a few new
interfaces and APIs for processing content streams.  This keep the core
clean of encryption code but enables not only encryption but support of
multiple content types ( custom media types ).

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-08-09 15:01:16 +00:00
Michael Crosby
f055bdb0aa Remove windows v1 runtime
Closes #3094

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-07-23 18:54:37 +00:00
Michael Crosby
725d3ad8cb Add --device flag to ctr
Closes #3066

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-07-18 18:51:05 +00:00
Stefan Berger
bf8804c743 Implemented image encryption/decryption libraries and ctr commands
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Brandon Lum <lumjjb@gmail.com>
2019-07-17 15:19:58 -04:00
Maksym Pavlenko
1918ee4d11 Respect default snapshotter label
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
2019-07-10 12:16:43 -07:00
Justin Terry (VM)
7ac221e8d7 Adding ctr memory and cpu flags
Adds ctr run --memory-limit for all platforms.
Adds ctr run --cpu-count for Windows platforms.

Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
2018-12-10 13:31:59 -08:00
Evan Hazlett
40caece8dc update tests
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
2018-11-12 11:47:17 +00:00
Phil Estes
c28ce39cea
Add flag to ctr for running with NoNewPrivileges: false
Add flag and With-helper to set NoNewPrivileges to false since it is on
by default in the default UNIX spec for containerd, but off by default
in Docker and CRI plugin use. This allows for easy testing with it off
for comparison.

Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
2018-09-14 11:03:58 -04:00
Michael Crosby
da1b5470cd Runtime v2
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-07-17 10:21:29 -04:00
Felix Abecassis
5dd22a20af Move ContainerFlags to "commands" package
Commit 05513284e7 exposed the "rootfs"
and "no-pivot" flags for the "containers" command, but it accidentally
removed them for "run" since package-level variables are initialized
before package-level init functions in golang. Hoisting these flags to
a package imported by both commands solves the problem.

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2018-06-20 18:33:59 -07:00
Michael Crosby
d3a8055e2d Add --pid-file to ctr
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-02-20 15:10:50 -05:00
Kunal Kushwaha
b12c3215a0 Licence header added
Signed-off-by: Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
2018-02-19 10:32:26 +09:00
Akihiro Suda
7f95b9f987 ctr: add EnvVar CONTAINERD_SNAPSHOTTER for --snapshotter
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2017-11-29 19:11:10 +09:00
Jess Valarezo
a19a20303a ctr: add commands package with shared utility functions
Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
2017-10-23 17:40:18 -07:00