Skip to content

Commit ec0bcde

Browse files
test(features): port cgroup resource limits to resource-limits on Docker and Podman
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent 453459a commit ec0bcde

7 files changed

Lines changed: 103 additions & 95 deletions

File tree

‎.github/workflows/e2e-suites.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ jobs:
109109
{"environment":"ubuntu-k3s","installer":"k3s","family":"features","package":"routable-host-ip","gateway":"tmachine","runner":"ubuntu-24.04"},
110110
{"environment":"ubuntu-k3s","installer":"k3s-ha","family":"features","package":"routable-host-ip","gateway":"tmachine","runner":"ubuntu-24.04"},
111111
{"environment":"ubuntu-docker-rootful","installer":"deb","family":"features","package":"connect-ssh-supervision","gateway":"openshell","runner":"ubuntu-24.04"},
112+
{"environment":"ubuntu-docker-rootful","installer":"deb","family":"features","package":"resource-limits","gateway":"openshell","runner":"ubuntu-24.04"},
113+
{"environment":"fedora-podman-rootful","installer":"rpm","family":"features","package":"resource-limits","gateway":"openshell","runner":"ubuntu-24.04"},
114+
{"environment":"fedora-podman-rootless","installer":"rpm","family":"features","package":"resource-limits","gateway":"openshell","runner":"ubuntu-24.04"},
112115
{"environment":"fedora-podman-rootful-keycloak","installer":"rpm","family":"features","package":"keycloak-provider-refresh","gateway":"openshell","runner":"ubuntu-24.04"},
113116
{"environment":"fedora-podman-rootless-keycloak","installer":"rpm","family":"features","package":"keycloak-provider-refresh","gateway":"openshell","runner":"ubuntu-24.04"},
114117
{"environment":"ubuntu-docker-rootful","installer":"deb","family":"drivers/docker","gateway":"openshell","runner":"ubuntu-24.04"},

‎e2e/rust/Cargo.toml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ name = "podman_corporate_proxy"
143143
path = "tests/podman_corporate_proxy.rs"
144144
required-features = ["e2e-podman"]
145145

146-
[[test]]
147-
name = "podman_resource_limits"
148-
path = "tests/podman_resource_limits.rs"
149-
required-features = ["e2e-podman"]
150-
151146
[[test]]
152147
name = "provider_refresh_handles"
153148
path = "tests/provider_refresh_handles.rs"

‎e2e/rust/tests/podman_resource_limits.rs‎

Lines changed: 0 additions & 89 deletions
This file was deleted.

‎tests/suites/features/Cargo.lock‎

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/suites/features/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
[workspace]
55
resolver = "2"
6-
members = ["cdi", "connect-ssh-supervision", "docker-updates", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "oci-image", "routable-host-ip"]
6+
members = ["cdi", "connect-ssh-supervision", "docker-updates", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "oci-image", "resource-limits", "routable-host-ip"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
[package]
5+
name = "resource-limits"
6+
description = "Features suite: a sandbox's CPU and memory limits are enforced by its cgroup"
7+
version = "0.0.0"
8+
edition = "2024"
9+
rust-version = "1.94"
10+
license = "Apache-2.0"
11+
repository = "https://github.com/NVIDIA/OpenShell"
12+
publish = false
13+
14+
[dependencies]
15+
openshell-testkit = { path = "../../../testkit/testkit" }
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Declared sandbox CPU and memory limits are enforced by the workload's
5+
//! cgroup, not just stored and returned by the API.
6+
//!
7+
//! Conformance checks that a template stores its resources. It can't check
8+
//! enforcement: not every driver enforces limits, and those that do report it
9+
//! in their gateway info capabilities. This test runs where the driver reports
10+
//! both limits, and reads the cgroup v2 files from inside the sandbox.
11+
12+
use testkit::{Context, Error};
13+
14+
const CGROUP_READ_POLICY: &str = "version: 1
15+
filesystem_policy:
16+
include_workdir: true
17+
read_only: [/usr, /lib, /lib64, /proc, /etc, /sys/fs/cgroup]
18+
read_write: [/sandbox, /tmp, /dev/null]
19+
landlock:
20+
compatibility: best_effort
21+
network_policies: {}
22+
";
23+
24+
const CPU_REQUEST: &str = "500m";
25+
const MEMORY_REQUEST: &str = "512Mi";
26+
/// A 50000us quota over a 100000us CFS period, what `--cpus=0.5` gives a
27+
/// container.
28+
const EXPECTED_CPU_MAX: &str = "50000 100000";
29+
/// 512 * 1024 * 1024 bytes.
30+
const EXPECTED_MEMORY_MAX: &str = "536870912";
31+
32+
/// A sandbox created with `--cpu 500m --memory 512Mi` reads those limits from
33+
/// its own `cpu.max` and `memory.max`.
34+
#[testkit::test]
35+
async fn declared_limits_are_enforced_by_the_sandbox_cgroup(cx: &mut Context) -> testkit::Result {
36+
let info = cx.gateway_info().await?;
37+
let resources = info
38+
.compute_drivers
39+
.first()
40+
.and_then(|driver| driver.capabilities.as_ref())
41+
.and_then(|capabilities| capabilities.resource_capabilities.as_ref())
42+
.ok_or_else(|| Error::msg("the gateway reports no compute driver resource capabilities"))?;
43+
let cpu = resources
44+
.cpu
45+
.as_ref()
46+
.is_some_and(|cpu| cpu.limit_supported);
47+
let memory = resources
48+
.memory
49+
.as_ref()
50+
.is_some_and(|memory| memory.limit_supported);
51+
testkit::ensure!(
52+
cpu && memory,
53+
"this suite needs a driver that enforces CPU and memory limits; the gateway reports cpu={cpu}, memory={memory}"
54+
);
55+
56+
let sandbox = cx
57+
.cli_sandbox("rl")
58+
.args(["--cpu", CPU_REQUEST, "--memory", MEMORY_REQUEST])
59+
.policy_yaml(CGROUP_READ_POLICY)
60+
.command(["sleep", "infinity"])
61+
.create_ready()
62+
.await?;
63+
64+
for (file, expected, request) in [
65+
("memory.max", EXPECTED_MEMORY_MAX, MEMORY_REQUEST),
66+
("cpu.max", EXPECTED_CPU_MAX, CPU_REQUEST),
67+
] {
68+
let path = format!("/sys/fs/cgroup/{file}");
69+
let output = sandbox.exec(["cat", path.as_str()]).await?.success()?;
70+
let value = output.stdout.trim();
71+
testkit::ensure!(
72+
value == expected,
73+
"{path} reads {value:?}; expected {expected:?} for the declared {request} limit"
74+
);
75+
}
76+
Ok(())
77+
}

0 commit comments

Comments
 (0)