Repository navigation
Fix: TestCgroupNamespace failure on cgroups v1 hosts - #13240
Conversation
c021123 to
01240c6
Compare
There was a problem hiding this comment.
Pull request overview
Adjusts TestCgroupNamespace to align its expectation with the implementation behavior on both cgroups v1 and cgroups v2 hosts, preventing failures on cgroups v1 systems (e.g., Amazon Linux 2).
Changes:
- Updates the non-privileged test case to expect a cgroup namespace only when running in unified cgroups mode (cgroups v2).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
01240c6 to
c2ab47c
Compare
| desc: "non-privileged container should get cgroup namespace", | ||
| privileged: false, | ||
| expectCgroupNamespace: true, | ||
| expectCgroupNamespace: isUnifiedCgroupsMode(), |
There was a problem hiding this comment.
I think it'd be better to have test cases specific to each cgroup version and skip the case when the host doesn't match the expected version. IOW there should be a cgroup v1 test and a group v2 test. Changing the expectation based on the host makes the tests harder to reason about.
There was a problem hiding this comment.
Agreed, added cgroup version specific tests
| Test Case | isUnifiedCgroupsMode() | privileged | expectCgroupNamespace |
|----------------------------|------------------------|------------|-----------------------|
| cgroupv2: non-privileged | true | false | true |
| cgroupv2: privileged | true | true | false |
| cgroupv1: non-privileged | false | false | false |
| cgroupv1: privileged | false | true | false |
c2ab47c to
1caaf97
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Arjun Yogidas <[email protected]>
1caaf97 to
970b5d4
Compare
TestCgroupNamespace fails on hosts running cgroups v1 (e.g., Amazon Linux 2):
The test hardcoded
expectCgroupNamespace: truefor non-privileged containers, but the implementation only adds the cgroup namespace whenisUnifiedCgroupsMode()returns true (cgroups v2). On cgroups v1 hosts, the namespace is never added, causing the assertion to fail.Root Cause
The test assumed all non-privileged containers run on hosts with cgroups v2. This is not the case for Amazon Linux 2, which uses cgroups v1.
Fix
Added a
requireCgroupV2field to each test case to explicitly declare which cgroup version the case is valid for. Each subtest skips itself at runtime if the host's actual cgroup mode (detected viaisUnifiedCgroupsMode()) does not match what the test case requires. This ensures the correct subset of tests runs on both cgroups v1 and v2 hosts without any hardcoded assumptions about the environment.