Files
youki/tests/rootless-tests/run.sh
Theodore-Liu 1855f879fb fix(libcontainer): derive default cgroupfs path from current cgroup (#3706)
* fix(libcontainer): derive default cgroupfs path from current cgroup

When the OCI spec omits linux.cgroupsPath, youki always generates a
systemd-style default. With rootless Podman using cgroupfs, this does not
place the container payload in a dedicated cgroup, so Podman's cgroup
contains multiple processes.

Choose the default path based on the active cgroup manager. Preserve the
existing systemd path, and for cgroupfs derive a sibling cgroup named after
the container ID from youki's current cgroup. Use the same path for
container setup, saved configuration, and cleanup, and add regression tests
for the cgroupfs path resolution.

Fixes #3690

Signed-off-by: Jingze Liu <110184138+Theodore-Liu@users.noreply.github.com>

* fix(libcontainer): read /proc/self/cgroup via ProcfsHandle and let exec use the saved cgroup path

Address review on #3706:
- get_cgroup_path_for_manager reads /proc/self/cgroup through pathrs'
  ProcfsHandle (as rootfs/mount.rs does) instead of procfs::Process::myself(),
  with a CgroupPathError covering the open and parse errors.
- ContainerBuilderImpl takes the base cgroup path from its caller: the init
  builder passes the path it saved in YoukiConfig, and the tenant builder loads
  that saved path, so exec joins the cgroup the container was created in instead
  of deriving it again from the calling process's cgroup.

Signed-off-by: Jingze Liu <110184138+Theodore-Liu@users.noreply.github.com>

* test(rootless): drop the --cgroup-manager systemd workaround now that cgroupfs derives its default path

#3691 pinned the exec test to the systemd cgroup manager because, with cgroupfs in
rootless mode, youki's default cgroup path (":youki:<id>") did not match what podman
expected (#3690). The default is now derived from the current cgroup, so the test
runs under podman's default cgroup manager again.

Signed-off-by: Jingze Liu <110184138+Theodore-Liu@users.noreply.github.com>

---------

Signed-off-by: Jingze Liu <110184138+Theodore-Liu@users.noreply.github.com>
2026-10-10 13:36:01 +09:00

49 lines
1.6 KiB
Bash
Executable File

# This is a temporary test-collection for validating youki runs correctly with podman in rootless mode
# This will be moved to a proper rust based test crate, similar to rust-integration tests soon
set -ex
runtime=$1
# log the podman version and cgroup manager
podman --version
podman info --format '{{.Host.CgroupManager}}'
podman rm --force --ignore create-test # remove if existing
podman create --runtime $runtime --name create-test hello-world
log=$(podman start -a create-test)
echo $log | grep "This message shows that your installation appears to be working correctly"
podman rm --force --ignore create-test
rand=$(head -c 10 /dev/random | base64)
log=$(podman run --runtime $runtime fedora echo "$rand")
echo $log | grep $rand
podman kill exec-test || true # ignore failure for killing
podman rm --force --ignore exec-test
podman run -d --runtime $runtime --name exec-test busybox sleep 10m
rand=$(head -c 10 /dev/random | base64)
log=$(podman exec --runtime $runtime exec-test echo "$rand")
echo $log | grep $rand
CGROUP_SUB_PATH=$(podman inspect exec-test | jq .[0].State.CgroupPath | tr -d "\"")
CGROUP_PATH="/sys/fs/cgroup$CGROUP_SUB_PATH/cgroup.procs"
# assert we have exactly one process in the cgroup
test $(cat $CGROUP_PATH | wc -l) -eq 1
# assert pid match
test $(cat $CGROUP_PATH) -eq $(podman inspect exec-test | jq .[0].State.Pid)
podman exec -d --runtime $runtime exec-test sleep 5m
# we cannot exactly check the pid of tenant here, instead just check that there are
# two processes in the same cgroup now
test $(cat $CGROUP_PATH | wc -l) -eq 2
podman kill exec-test
podman rm --force --ignore exec-test