1615 Commits
Author SHA1 Message Date
Derek McGowan d154e234b2 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-19 00:13:56 +00: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
Adrien Delorme 88116b1911 remove max_dl_operations setting
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
2025-04-24 11:39:42 +02:00
Adrien DelormeandCorentin REGAL f9af08820b perf(pull): multipart layer fetch
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
Co-Authored-By: Corentin REGAL <143578+co42@users.noreply.github.com>
2025-04-24 11:39:42 +02:00
Maksym Pavlenko 17b6e1ef85 Allow streaming to client
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2025-04-23 18:03:29 -07:00
Maksym Pavlenko bd8e6c727d Enable http debug and tracing for non local puller
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2025-04-23 17:39:57 -07:00
Maksym Pavlenko 27e6c117d9 Move HTTP debug code to pkg
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2025-04-23 17:38:47 -07:00
Vinayak Goyal d16ad8f5c5 fix: update containerd config dump to reflect plugin config migrations.
Signed-off-by: Vinayak Goyal <vinaygo@google.com>
2025-04-23 22:08:13 +00:00
Samuel Karp f512e31743 ctr shim: allow override to computed shim address
The default computed address follows the format used by the
io.containerd.runc.v2 shim, but there is no requirement that third-party
shims follow the same format.  The new --shim-address option allows
debugging of third-party shims with a different address format.

Signed-off-by: Samuel Karp <samuelkarp@google.com>
2025-04-22 11:25:23 -07:00
Akihiro Suda 499238a52a Remove deprecated dynamic library plugins
Dynamic library plugins have been deprecated since v2.0 (PR 9238)

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-04-17 09:12:46 +09:00
Akihiro Suda d9c889568e Remove the support for Schema 1 images
Schema 1 (`application/vnd.docker.distribution.manifest.v1+prettyjws`) has been
officially deprecated since containerd v1.7 (PR 6884), and disabled since v2.0 (PR 9765).

Users who have been seeing warnings like `conversion from schema 1 images is deprecated`
now have to rebuild the image with Schema 2 or OCI.

Schema 2 was introduced in Docker 1.10 (Feb 2016), so most users should have been already
using Schema 2 or OCI.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-04-11 09:03:26 +09:00
ningmingxiao 531adbf065 config:fix config migrate lost timeout config
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2025-03-12 23:34:58 +08:00
Derek McGowan 59c8cf6ea5 Merge pull request #10705 from erofs/erofs-snapshotter
[Feat] erofs snapshotter and differ
2025-02-05 15:21:33 +00:00
Phil Estes 98af40b752 Merge pull request #10722 from henry118/uidmap2
Support multiple uid/gid mappings [2/2]
2025-01-17 18:34:40 +00:00