Skip to content

Fix: TestCgroupNamespace failure on cgroups v1 hosts - #13240

Merged
mxpv merged 1 commit into
containerd:mainfrom
coderbirju:fix-cgroup-test
May 22, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
coderbirju:fix-cgroup-test

Conversation

@coderbirju

@coderbirju coderbirju commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

TestCgroupNamespace fails on hosts running cgroups v1 (e.g., Amazon Linux 2):

 --- FAIL: TestCgroupNamespace/non-privileged_container_should_get_cgroup_namespace                                         
      Error: Not equal:                                                                                                      
          expected: true                                                                                                     
          actual  : false                                                                                                    

The test hardcoded expectCgroupNamespace: true for non-privileged containers, but the implementation only adds the cgroup namespace when isUnifiedCgroupsMode() 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 requireCgroupV2 field 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 via isUnifiedCgroupsMode()) 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.

Copilot AI review requested due to automatic review settings April 15, 2026 21:58
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Apr 15, 2026
@coderbirju coderbirju changed the title Fix TestCgroupNamespace failure on cgroups v1 hosts Fix: TestCgroupNamespace failure on cgroups v1 hosts Apr 15, 2026
@dosubot dosubot Bot added area/cri Container Runtime Interface (CRI) kind/bug labels Apr 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

desc: "non-privileged container should get cgroup namespace",
privileged: false,
expectCgroupNamespace: true,
expectCgroupNamespace: isUnifiedCgroupsMode(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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                 |

Copilot AI review requested due to automatic review settings April 16, 2026 18:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Apr 16, 2026
@samuelkarp
samuelkarp requested a review from AkihiroSuda April 16, 2026 18:47
@mxpv
mxpv added this pull request to the merge queue May 22, 2026
Merged via the queue into containerd:main with commit c16baa7 May 22, 2026
55 of 56 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cri Container Runtime Interface (CRI) kind/bug size/M

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants