Commit Graph

103 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
dd0542f7c1
cmd: don't alias context package, and use cliContext for cli.Context
Unfortunately, this is a rather large diff, but perhaps worth a one-time
"rip off the bandaid" for v2. This patch removes the use of "gocontext"
as alias for stdLib's "context", and uses "cliContext" for uses of
cli.context.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-20 02:15:13 +02:00
ChengenH
4a31bd606d chore: use errors.New to replace fmt.Errorf with no parameters will much better
Signed-off-by: ChengenH <hce19970702@gmail.com>
2024-04-21 21:49:31 +08:00
Evan Lezar
1b62224181 Bump tags.cncf.io/container-device-interface to v0.7.1
This includes migrating from cdi.GetRegistry() to cdi.Configure() and
using top-level cdi Refresh and InjectDevices functions as applicable.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-04-10 15:25:11 +02:00
Derek Nola
132485adb0
Convert CLI to urfave v2
Followed the Migration Guide at https://cli.urfave.org/migrate-v1-to-v2/
The major changes not pointed out in the migration guide are:
- context.Args() no longer produces a []slice, so context.Args().Slice()
  in substitued
- All cli.Global***** are deprecated (the migration guide is somewhat
  unclear on this)

Signed-off-by: Derek Nola <derek.nola@suse.com>

Vendor in urfave cli/v2

Signed-off-by: Derek Nola <derek.nola@suse.com>

Fix NewStringSlice calls

Signed-off-by: Derek Nola <derek.nola@suse.com>
2024-02-15 09:48:04 -08:00
Zechun Chen
5cbe92e88e Clean up repeated package import
Signed-off-by: Zechun Chen <zechun.chen@daocloud.io>
2024-02-06 11:06:33 +08:00
Akihiro Suda
22d586e515
api/services/instrospection: add PluginInfo
The new `PlunginInfo()` call can be used for instrospecting the details
of the runtime plugin.

```console
$ ctr plugins inspect-runtime --runtime=io.containerd.runc.v2 --runc-binary=runc
{
    "Name": "io.containerd.runc.v2",
    "Version": {
        "Version": "v2.0.0-beta.0-XX-gXXXXXXXXX.m",
        "Revision": "v2.0.0-beta.0-XX-gXXXXXXXXX.m"
    },
    "Options": {
        "binary_name": "runc"
    },
    "Features": {
        "ociVersionMin": "1.0.0",
        "ociVersionMax": "1.1.0-rc.2",
        ...,
    },
    "Annotations": null
}
```

The shim binary has to support `-info` flag, see `runtime/v2/README.md`

Replaces PR 8509 (`api/services/task: add RuntimeInfo()`)

Co-authored-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2024-01-25 10:00:30 +09:00
Derek McGowan
f2765617c5
Merge pull request #9662 from dmcgowan/replace-platform-package
Use github.com/containerd/platforms package
2024-01-23 19:50:25 +00:00
Derek McGowan
e79ec7a095
Remove deprecated platforms package
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-01-23 09:14:03 -08:00
Evan Lezar
9dd29b3cf7 Update container-device-interface to v0.6.2
This includes migrating from the github.com/container-orchestrated-devices
repo to tags.cncf.io.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-01-23 11:36:34 +01:00
Derek McGowan
dbc74db6a1
Move runtime to core/runtime
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-01-17 09:58:04 -08:00
Derek McGowan
e59f64792b
Move oci to pkg/oci
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-01-17 09:55:48 -08:00
Derek McGowan
fcd39ccc53
Move snapshots to core/snapshots
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-01-17 09:54:09 -08:00
Derek McGowan
9456048f46
Move containers to core/containers
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-01-17 09:50:40 -08:00
Derek McGowan
261e01c2ac
Move client to subpackage
Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-11-01 10:37:00 -07:00
Derek McGowan
5fdf55e493
Update go module to github.com/containerd/containerd/v2
Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-10-29 20:52:21 -07:00
rongfu.leng
8f3d1c9d9b add cpu-burst param to ctr command
Signed-off-by: rongfu.leng <rongfu.leng@daocloud.io>
2023-10-09 21:51:24 +08:00
Derek McGowan
508aa3a1ef
Move to use github.com/containerd/log
Add github.com/containerd/log to go.mod

Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-09-22 07:53:23 -07:00
Ilya Hanov
1555a31bf6 mount: support idmapped mount points
This patch introduces idmapped mounts support for
container rootfs.

The idmapped mounts support was merged in Linux kernel 5.12
torvalds/linux@7d6beb7.
This functionality allows to address chown overhead for containers that
use user namespace.

The changes are based on experimental patchset published by
Mauricio Vásquez #4734.
Current version reiplements support of idmapped mounts using Golang.

Performance measurement results:
Image           idmapped mount  recursive chown
BusyBox         00.135          04.964
Ubuntu          00.171          15.713
Fedora          00.143          38.799

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
Signed-off-by: Artem Kuzin <artem.kuzin@huawei.com>
Signed-off-by: Alexey Perevalov <alexey.perevalov@huawei.com>
Signed-off-by: Ilya Hanov <ilya.hanov@huawei-partners.com>
2023-09-05 01:23:30 +03:00
Akihiro Suda
0498acefb9
go.mod: github.com/.../container-device-interface v0.6.0
https://github.com/container-orchestrated-devices/container-device-interface/compare/v0.5.4...v0.6.0

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-07-23 03:07:59 +09:00
Evan Lezar
d3887b2e62 Support CDI devices in ctr --device flag
This change adds support for CDI devices to the ctr --device flag.
If a fully-qualified CDI device name is specified, this is injected
into the OCI specification before creating the container.

Note that the CDI specifications and the devices that they represent
are local and mirror the behaviour of linux devices in the ctr command.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
2023-05-31 16:14:01 +02:00
Peteris Rudzusiks
f2bc737825 Add cpuset-mems flag to 'ctr run' command
This flag allows cpuset.mems to be specified when running a container. If
provided, the container will use only the defined memory nodes.

Signed-off-by: Peteris Rudzusiks <rye@stripe.com>
2023-05-30 17:56:18 +02:00
Peteris Rudzusiks
f642c0a5f5 ctr: add cpuset-cpus flag to 'ctr run' command
This flag allows cpuset.cpus to be specified when starting a container. If
provided, the container will use only the defined CPU cores.

Signed-off-by: Peteris Rudzusiks <rye@stripe.com>
2023-05-30 17:50:33 +02:00
Danny Canter
519457e3e0 ctr: Add sandbox flag to ctr run
Add a flag to be able to run a container in a given sandbox.

Signed-off-by: Danny Canter <danny@dcantah.dev>
2023-04-19 19:40:59 -07:00
Fu Wei
e208c24256
Merge pull request #8175 from Iceber/fix_cni_metadata
adding cni metadata to the container in the `ctr run --config`
2023-03-16 23:29:48 +08:00
Iceber Gu
5fdca538d0 adding cni metadata to the container in the ctr run --config
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2023-03-16 18:01:53 +08:00
Iceber Gu
b91f42a146 ctr/tasks: support remapped UID/GID
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2023-03-02 14:02:14 +08:00
yulng
757b8f702b
keep the uppercase letter for flag info
Signed-off-by: yulng <wei.yang@daocloud.io>
2023-02-06 16:37:24 +08:00
Maksym Pavlenko
3bc8fc4d30 Cleanup build constraints
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2022-12-08 09:36:20 -08:00
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
bin liu
fdff11def3 ctr: add privileged-without-host-devices for run command
For Kata Containers, starting a privileged container will fail
if passing all host devices to container due to the permission
issue, like the `privileged_without_host_devices` for CRI service,
add a `privileged-without-host-devices` to `ctr run` command will
disable passing all host devices to containers.

Signed-off-by: bin liu <liubin0329@gmail.com>
2022-08-26 15:56:01 +08: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
Iceber Gu
92b7bc9edc ctr: fix label args used in NewContainer
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2022-05-18 16:11:30 +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
songjiang han
2a0b2ee9eb fix: ctr run --cni get failed
when   user  executes ctr run --cni to start a container,it will call cni plugin to create network .But when user kills it,the network won’t be removed. if we run a container with same namespace and name again will trigger a bug. we should remove the network when user kills task if it enables cni plugin.

Fix:#6604

Signed-off-by: SongJiang Han <songjiang.dark@gmail.com>
2022-03-15 15:46:29 +08:00
haoyun
bbe46b8c43 feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io>
Co-authored-by: zounengren <zouyee1989@gmail.com>
2022-01-07 10:27:03 +08: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
Markus Lippert
f39b3ac7ea fix(ctr): enable networking for Windows containers
Signed-off-by: Markus Lippert <lippertmarkus@gmx.de>
2021-12-21 07:13:39 +01: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
Phil Estes
f40df3d72b
Enable image config labels in ctr and CRI container creation
Signed-off-by: Phil Estes <estesp@amazon.com>
2021-09-15 15:31:19 -04: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
Michael Crosby
6f60b3016f [ctr] add HOSTNAME env for host network
Set the hostname environment var when using host networking via ctr

Signed-off-by: Michael Crosby <michael@thepasture.io>
2021-08-18 14:42:36 +00:00
Fu Wei
1c4e9d0487
Merge pull request #5846 from crosbymichael/ctr-cpu.shares 2021-08-11 09:24:00 +08:00
Michael Crosby
d2f3b71468 add cpu-shares to ctr
This allows the cpu shares to be modified via ctr.

Signed-off-by: Michael Crosby <michael@thepasture.io>
2021-08-10 04:12:15 -04: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
Fu Wei
1daea57ab5
Merge pull request #5636 from crosbymichael/multi-gpus
allow multi gpu to be specified via ctr
2021-06-23 00:08:48 +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
kh
05e51539a9 command line flags of setting container rootfs propagation
Signed-off-by: Kitt Hsu <kitt.hsu@gmail.com>
2021-06-17 10:03:37 +08: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