Commit Graph

1627 Commits

Author SHA1 Message Date
Maksym Pavlenko
f496ee86e4 Merge pull request #12789 from mxpv/replace
Fix go mod replace and sync with latest api changes
2026-01-23 20:45:45 +00:00
Yohei Yamamoto
e066861ac7 fix: typo in comment
Signed-off-by: Yohei Yamamoto <yhymmt123@gmail.com>
2026-01-18 01:27:51 +09:00
Maksym Pavlenko
992597bfe9 Fix TTRPC prefix
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-01-15 13:06:50 -08:00
ningmingxiao
677e991bb5 command: show help and exit on unknown positional arguments
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2026-01-13 18:50:07 +08:00
Wei Fu
016f4a6360 *: move new oom package into internal
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2026-01-06 20:44:04 -05:00
Wei Fu
8ac7e3c06d cmd/containerd-shim-runc-v2: use experimental OOM package
We should always send oom event before exit event.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2026-01-06 20:44:04 -05:00
Wei Fu
21707e6c3b cmd/containerd-shim-runc-v2: add experimental OOM package
The OOM handling code is intended to live under pkg/oom/v2. However, the
cgroupv2 package still needs further refinement, such as exporting the
cgroup path and allowing callers to query specific stats instead of
returning all of them.

Until that work is complete, introduce the OOM package as experimental
and place it under containerd-shim-runc-v2.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2026-01-06 20:44:04 -05:00
Evan Lezar
f5cd8d56f4 Map ctr --gpus requests to NVIDIA CDI device requests
This change maps ctr --gpus requests to CDI device requests.
This is done by mapping --gpus ID to a nvidia.com/gpu=ID device
request.

This removes the dependence on the nvidia-container-cli and instead
uses existing CDI specifications for nvidia devices if available on
the system.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
2025-11-25 11:22:22 +01:00
Maksym Pavlenko
4c32f5f73b Merge pull request #12531 from samuelkarp/ctr-dump-config
ctr run: dump OCI config to a file
2025-11-18 18:43:48 +00:00
Maksym Pavlenko
a1a6229699 Merge pull request #12532 from samuelkarp/ctr-rlimit-nofile
ctr: allow rlimit-nofile override
2025-11-18 18:41:13 +00:00
Derek McGowan
c2b22d6bd6 Update the ctr pull defaults when using the transfer service
Match the defaults set by the transfer service which will configure
linux by default on darwin hosts.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-11-18 08:51:51 -08:00
Samuel Karp
ee1f94e4d1 ctr: allow rlimit-nofile override
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2025-11-17 21:50:12 -08:00
Samuel Karp
3b899aa111 ctr run: dump OCI config to a file
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2025-11-17 15:39:21 -08:00
Akihiro Suda
910171e90e Fix directory permissions
- Create /var/lib/containerd with 0o700 (was: 0o711).
- Create config.TempDir with 0o700 (was: 0o711).
- Create /run/containerd/io.containerd.grpc.v1.cri with 0o700 (was: 0o755).
- Create /run/containerd/io.containerd.sandbox.controller.v1.shim with 0o700 (was: 0o711).
- Leave /run/containerd and /run/containerd/io.containerd.runtime.v2.task created with 0o711,
  as required by userns-remapped containers.
  /run/containerd/io.containerd.runtime.v2.task/<NS>/<ID> is created with:
  - 0o700 for non-userns-remapped containers
  - 0o710 for userns-remapped containers with the remapped root group as the owner group.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-11-04 16:04:30 +09:00
Wei Fu
842cb99a5e containerd-shim-runc-v2: monitor OOM event after creation
After runc.Create(init), the container’s cgroup contains a paused init process.
Therefore, we should start monitoring OOM events immediately after creation, in
case the process goes OOM very quickly. Otherwise, we may encounter flaky cases
such as:

```bash
Link https://github.com/containerd/containerd/actions/runs/18787603490/job/53609925150?pr=12399

[k8s.io] Container OOM runtime should output OOMKilled reason [It] should terminate with exitCode 137 and reason OOMKilled
    default: sigs.k8s.io/cri-tools/pkg/validate/container_linux.go:147
    default:
    default:   Timeline >>
    default:   STEP: create Privileged podSandbox @ 10/24/25 18:11:50.889
    default:   STEP: create container @ 10/24/25 18:11:51.691
    default:   STEP: create a container that will be killed by OOMKiller @ 10/24/25 18:11:51.691
    default:   STEP: Get image status for image: registry.k8s.io/e2e-test-images/busybox:1.29-2 @ 10/24/25 18:11:51.691
    default:   STEP: Create container. @ 10/24/25 18:11:51.691
    default:   Oct 24 18:11:51.718: INFO: Created container "384bb1538123650106d43dd1fb86fa2c13ae32fb1594b0e70d50cc47eddccbe8"
    default:
    default:   STEP: verifying container status @ 10/24/25 18:11:51.718
    default:   STEP: start container @ 10/24/25 18:11:51.72
    default:   STEP: Start container for containerID: 384bb1538123650106d43dd1fb86fa2c13ae32fb1594b0e70d50cc47eddccbe8 @ 10/24/25 18:11:51.72
    default:   Oct 24 18:11:52.007: INFO: Started container "384bb1538123650106d43dd1fb86fa2c13ae32fb1594b0e70d50cc47eddccbe8"
    default:
    default:   STEP: container is stopped because of OOM @ 10/24/25 18:11:52.007
    default:   STEP: Get container status for containerID: 384bb1538123650106d43dd1fb86fa2c13ae32fb1594b0e70d50cc47eddccbe8 @ 10/24/25 18:11:52.007
    default:   STEP: Get container status for containerID: 384bb1538123650106d43dd1fb86fa2c13ae32fb1594b0e70d50cc47eddccbe8 @ 10/24/25 18:11:56.018
    default:   STEP: Get container status for containerID: 384bb1538123650106d43dd1fb86fa2c13ae32fb1594b0e70d50cc47eddccbe8 @ 10/24/25 18:11:56.022
    default:   STEP: exit code is 137 @ 10/24/25 18:11:56.023
    default:   STEP: reason is OOMKilled @ 10/24/25 18:11:56.023
    default:   [FAILED] in [It] - sigs.k8s.io/cri-tools/pkg/validate/container_linux.go:165 @ 10/24/25 18:11:56.024
    default:   STEP: stop PodSandbox @ 10/24/25 18:11:56.024
    default:   STEP: delete PodSandbox @ 10/24/25 18:11:56.932
    default:   << Timeline
    default:
    default:   [FAILED] Expected
    default:       <string>: Error
    default:   to equal
    default:       <string>: OOMKilled
    default:   In [It] at: sigs.k8s.io/cri-tools/pkg/validate/container_linux.go:165 @ 10/24/25 18:11:56.024
```

NOTE: We have an EventMonitor goroutine that monitors all containers’ OOMKilled
events, and a dedicated goroutine that monitors container exit events. There is
a race condition where the exit-event goroutine may clean up the task and update
its status faster than the OOM event updater. I don’t have a better idea to
fully resolve this race condition, but this patch aims to minimize the chance
of missing OOM events.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2025-10-27 20:39:45 -04:00
Wei Fu
2042e805b8 cri/server/podsandbox: disable event subscriber
We have individual goroutine for each sandbox container. If there is any
error in handler, that goroutine will put event in that backoff queue.
So we don't need event subscriber for podsandbox. Otherwise, there will
be two goroutines to cleanup sandbox container.

```
>>>> From EventMonitor
  time="2025-10-23T19:30:59.626254404Z" level=debug msg="Received containerd event timestamp - 2025-10-23 19:30:59.624494674 +0000 UTC, namespace - \"k8s.io\", topic - \"/tasks/exit\""
  time="2025-10-23T19:30:59.626301912Z" level=debug msg="TaskExit event in podsandbox handler container_id:\"22e15114133e4d461ab380654fb76f3e73d3e0323989c422fa17882762979ccf\" id:\"22e15114133e4d461ab380654fb76f3e73d3e0323989c422fa17882762979ccf\" pid:203121 exit_status:137 exited_at:{seconds:1761247859 nanos:624467824}"

>>> If EventMonitor handles task exit well, it will close ttrpc
connection and then waitSandboxExit could encounter ttrpc-closed error

  time="2025-10-23T19:30:59.688031150Z" level=error msg="failed to delete task" error="ttrpc: closed" id=22e15114133e4d461ab380654fb76f3e73d3e0323989c422fa17882762979ccf
```

If both task.Delete calls fail but the shim has already been shut down, it
could trigger a new task.Exit event sent by cleanupAfterDeadShim. This would
result in three events in the EventMonitor's backoff queue, which is unnecessary
and could cause confusion due to duplicate events.

The worst-case scenario caused by two concurrent task.Delete calls is a shim
leak. The timeline for this scenario is as follows:

| Timestamp | Component       | Action                        | Result                                                                                           |
| ------    | -----------     | --------                      | --------                                                                                         |
| T1        | EventMonitor    | Sends `task.Delete`           | Marked as Req-1                                                                                  |
| T2        | waitSandboxExit | Sends `task.Delete`           | Marked as Req-2                                                                                  |
| T3        | containerd-shim | Handles Req-2                 | Container transitions from stopped to deleted                                                    |
| T4        | containerd-shim | Handles Req-1                 | Fails - container already deleted<br>Returns error: `cannot delete a deleted process: not found` |
| T5        | EventMonitor    | Receives `not found` error    | -                                                                                                |
| T6        | EventMonitor    | Sends `shim.Shutdown` request | No-op (active container record still exists)                                                     |
| T7        | EventMonitor    | Closes ttrpc connection       | Clean container state dir                                                                        |
| T8        | containerd-shim | Handles Req-2                 | Removes container record from memory                                                             |
| T9        | waitSandboxExit | Receives error                | Error: `ttrpc: closed`                                                                           |
| T10       | waitSandboxExit | Sends `shim.Shutdown` request | Fails (connection already closed)                                                                |
| T11       | waitSandboxExit | Closes ttrpc connection       | No-op (already closed)                                                                           |

The containerd-shim is still running because shim.Shutdown was sent at T6
before T8. Because container's state dir is deleted at T7, it's unable to clean
it up after containerd restarted.

We should avoid concurrent task.Delete calls here.

I also add subcommand - shutdown - in `ctr shim` for debug.

Fixed: #12344

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2025-10-24 12:19:52 -04:00
Fu Wei
0034ae955d Merge pull request #12395 from erofs/erofs-mount-handler
Add EROFS mount handler plugin
2025-10-22 17:35:29 +00:00
Gao Xiang
5b9d871fea Add EROFS mount handler plugin
Commit ee8ae9d569 ("Update erofs snapshotter to use mount manager")
temporarily removed the file-backed mount feature to adapt to the new
mount manager infrastructure as a quick start.

After the mount manager was introduced, a specific mount type can be
handled with a mount handler plugin to provide a dedicated mount
process (e.g. setup loopback devices in advance or calling external
mount helpers).

This commit adds a default EROFS mount handler for the Linux hosts
to set up loop devices for mount sources and "device=" external file
blobs if necessary (i.e. when file-backed mounts are unavailable),
allowing common runtimes such as runC to work directly, e.g.
 ``` sh
 mount -t erofs /var/lib/containerd/io.containerd.snapshotter.v1.erofs/snapshots/1/layer.erofs \
  /run/containerd/io.containerd.mount-manager.v1.bolt/t/346/1
 ```
 will be handled as
 ``` sh
 mount -t erofs /dev/loop1 /run/containerd/io.containerd.mount-manager.v1.bolt/t/346/1
 ```
and
 ``` sh
 mount -t erofs /var/lib/containerd/io.containerd.snapshotter.v1.erofs/snapshots/7/fsmeta.erofs \
   -odevice=/var/lib/containerd/io.containerd.snapshotter.v1.erofs/snapshots/1/layer.erofs,\
     device=/var/lib/containerd/io.containerd.snapshotter.v1.erofs/snapshots/2/layer.erofs,\
     ...
     device=/var/lib/containerd/io.containerd.snapshotter.v1.erofs/snapshots/7/layer.erofs
   /run/containerd/io.containerd.mount-manager.v1.bolt/t/335/1
 ```
 will be handled as
 ``` sh
 mount -t erofs /dev/loop1 -odevice=/dev/loop2,device=/dev/loop3,... \
   /run/containerd/io.containerd.mount-manager.v1.bolt/t/335/1
 ```
if file-backed mounts are unavailable.

For other host platforms (e.g. Darwin hosts) or specific runtimes
that require EROFS raw mounts instead of parsed mounts, this plugin
can be explicitly masked off by users.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2025-10-22 22:57:42 +08:00
Derek McGowan
62845f4a9e Simplify oom event handling for cgroups v2 in shim
Directly send events for oom rather than starting another go routine as
an event dispatcher. This saves a go routine and needing a map to track
the different oomkill values. The original oom watcher was designed to
match the interface of the much more complicated cgroup v1 oom watcher.
The oom watcher interface is not needed with cgroups v2 manager.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-10-20 15:22:07 -07:00
Fu Wei
e95415b723 Merge pull request #12333 from dmcgowan/erofs-block-files
Update erofs snapshotter to use mount manager
2025-10-20 02:43:50 +00:00
Akihiro Suda
c7c7271921 Merge pull request #12371 from dmcgowan/ctr-run-platform
Set default run platform in ctr
2025-10-17 07:54:18 +00:00
Derek McGowan
2a8d301177 Set default run platform in ctr
Currently run will generate invalid specifications on non-Linux Unix
platforms. Linux should be the default container platform for run when
the platform is not explicitly provided.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-10-15 17:06:39 -07:00
Derek McGowan
1adaf27c1e Update erofs to compile on Darwin
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-10-13 19:33:44 -07:00
ningmingxiao
71f5d16aaf bugfix:fix container logs lost because io close too quickly
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2025-10-10 21:33:48 +08:00
Fu Wei
61ddcd5372 Merge pull request #12063 from dmcgowan/mount-manager
Add mount manager
2025-10-03 14:01:38 +00:00
Derek McGowan
49634889f8 Update ctr image mounts to use mount manager
Updates the image mounts to use temporary mounts and no longer require
passing in a target directory.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:33 -07:00
Derek McGowan
62062902f5 Add support for mount manager to ctr snapshots mount
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:33 -07:00
Derek McGowan
8db3010865 Add mounts api service
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:31 -07:00
Maksym Pavlenko
9ca659a530 Add conf.d include in the default config
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2025-09-24 14:03:23 -07:00
Apurv Barve
7e74801b76 Move wintls as internal pkg
Signed-off-by: Apurv Barve <apurvbarve@microsoft.com>
2025-09-22 15:25:31 +05:30
Apurv Barve
d2adfd820c Add support to retrieve certificate and key from windows cert store
Signed-off-by: Apurv Barve <apurvbarve@microsoft.com>
2025-09-22 15:25:31 +05:30
Derek McGowan
ed03f3a710 Add mount manager plugin and types
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-18 17:08:43 -07:00
Derek McGowan
479cf42ca2 Add extraction progress to transfer service
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-10 20:07:40 -07:00
Maksym Pavlenko
a29b24f02a Merge pull request #12100 from twz123/windows-signal
Make signal notifications work on Windows
2025-08-21 00:39:12 +00:00
Chenyang Yan
bd9e577c26 Fix ctr snapshot mount produce invalid mount command for empty option
snapshotter.Mounts() maybe get empty Options for different snapshot service.

Empty Options will produce invalid mount command from printMounts:
```
$ ctr -n flintlock snapshot --snapshotter devmapper mount /mnt flintlock/flintlock/demo-2/01K24ZRN9EFAVQVNGXQS26BYVG/root
mount -t ext4 /dev/mapper/fc-dev-thinpool-snap-19 /mnt -o
$ cmd=$(ctr -n flintlock snapshot --snapshotter devmapper mount /mnt flintlock/flintlock/demo-2/01K24ZRN9EFAVQVNGXQS26BYVG/root)
$ $cmd
mount: option requires an argument -- 'o'
Try 'mount --help' for more information.
```

Signed-off-by: Chenyang Yan <memory.yancy@gmail.com>
2025-08-09 15:06:07 +08:00
Sebastiaan van Stijn
ed174c9145 cmd/ctr: rename vars that shadowed builtin
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-21 09:36:22 +02:00
Tom Wieczorek
0eaa09e35a Make signal notifications work on Windows
On Windows, the Go runtime will only ever notify os.Interrupt or
syscall.SIGINT. Using windows.SIGINT, even if it wraps the same integer
value as syscall.SIGINT, will have no effect.

Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
2025-07-15 13:41:21 +02:00
Akihiro Suda
d455980d36 Merge pull request #12017 from caoruidong/sandbox_info_com
ctr:add sandbox info command to print sandbox info
2025-07-09 10:15:49 +00:00
Derek McGowan
4d89721f23 Merge pull request #11623 from yashsingh74/update-golangci-v2
ci: bump golangci from 6.5.2 to 7.0.0
2025-07-01 18:06:14 +00:00
Ruidong Cao
b671a97213 ctr:add sandbox info command to print sandbox info
Signed-off-by: Ruidong Cao <caoruidong.crd@alibaba-inc.com>
2025-06-24 15:53:04 +08:00
Akihiro Suda
9300d03899 Merge pull request #11885 from ningmingxiao/fix_nerdctl_unknown
bugfix:close container io when runtime create failed
2025-06-22 01:00:09 +00:00
yashsingh74
b3eec6d8e9 fix: ST1005: error strings should not end with punctuation or newlines
Signed-off-by: yashsingh74 <yashsingh1774@gmail.com>
2025-06-18 14:16:41 +05:30
ningmingxiao
e6708bddfb bugfix:close container io when runtime create failed
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2025-06-15 11:35:25 +08:00
yylt
49664dab53 Add context in Process Wait interface
Signed-off-by: yang yang <yang8518296@163.com>
2025-06-10 23:05:29 +08:00
ningmingxiao
9ae54175dd ctr:make sure containerd socket exist before create client
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2025-05-07 14:17:00 +08:00
Danny Canter
33ee060a35 Use Go 1.19 atomic wrappers everywhere
We've long been able to use these and they have a couple
great benefits:

1. Forces you to always access them atomically. With the pointer
variants it's completely valid to access the regular ol' int64/uint32
etc. without using the atomic.* methods. These wrappers don't provide
access to the underlying value so it forces correct usage always.

2. Conveys intent much better. Seeing the type be atomic.Int32 immediately
lets the reader know that this var will be used in a concurrent context,
and we no longer need comments like "this MUST be accessed atomically"
or similar.

Signed-off-by: Danny Canter <danny@dcantah.dev>
2025-05-03 03:46:20 -07:00
Samuel Karp
20fc2cf8ec Merge pull request #11748 from vinayakankugoyal/dump
fix: update containerd config dump to reflect plugin config migrations.
2025-04-29 18:05:40 +00:00
Samuel Karp
6d4c30b2ce Merge pull request #11728 from samuelkarp/ctr-shim-address
ctr shim: allow override to computed shim address
2025-04-28 20:48:55 +00:00
Fu Wei
ef7bdf18a1 Merge pull request #10177 from azr/azr/parallel-layer-fetch
Multipart layer fetch
2025-04-24 20:35:00 +00:00
Adrien Delorme
024775dab1 set dl options on resolver
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
2025-04-24 11:41:33 +02:00