Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit devices and freezer controller detection for cgroup v2 #3077

Merged
merged 3 commits into from
Oct 16, 2023

Conversation

twz123
Copy link
Member

@twz123 twz123 commented May 5, 2023

Description

The cgroup v2 freezer and device controllers are not listed in the cgroup.controllers file, Therefore, k0s sysinfo determines their presence based on the Linux kernel version. This is problematic for old kernels that have many backported features, such as RHEL and consorts.

Introduce a hopefully more reliable way of detecting them.

  • Use github.com/containerd/cgroups/v3 for cgroupv2 sysinfo. This is the same library that is used by containerd when it comes to cgroupv2 handling. k0s already links against it, and it exposes enough knobs in order to be the backend for the cgroupv2 sysinfo backend, so this seems a good choice to reduce the amount of low-level plumbing here.

  • The freezer controller still has its cgroup.freeze file, albeit this is deliberately not available in the root cgroup. Therefore, k0s sysinfo now tries to detect the controller file in its own cgroup. In the unlikely case that k0s is running in the root cgroup, it will try to create an empty, temporary cgroup for the freezer file detection. If it doesn't have sufficient permissions to do so, it issues an "unknown" warning.

  • The device controller solely available via the kernel's BPF interface. Therefore, k0s sysinfo now tries to attach a dummy device filter to an empty, temporary cgroup. In case k0s is unable to create the cgroup or attach the device filter because of missing permissions, the sysinfo probe will issue an "unknown" warning.

Fixes:

See:

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

  • Manual test
  • Auto test added

Checklist:

  • My code follows the style guidelines of this project
  • My commit messages are signed-off
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

@twz123 twz123 added bug Something isn't working backport/release-1.27 PR that needs to be backported/cherrypicked to release-1.27 branch labels May 5, 2023
@twz123 twz123 force-pushed the cgroupv2-devices-freezer-detection branch from 440b300 to b25ccba Compare May 8, 2023 12:04
@twz123 twz123 changed the title Detect devices and freezer in cgroup v2 via directory Revisit device and freezer controller detection for cgroup v2 May 8, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 7, 2023

The PR is marked as stale since no activity has been recorded in 30 days

@github-actions github-actions bot added Stale and removed Stale labels Jun 7, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 8, 2023

The PR is marked as stale since no activity has been recorded in 30 days

@github-actions github-actions bot added Stale and removed Stale labels Jul 8, 2023
@twz123 twz123 force-pushed the cgroupv2-devices-freezer-detection branch 6 times, most recently from a5b27d3 to b252379 Compare July 11, 2023 09:31
@twz123 twz123 removed the backport/release-1.27 PR that needs to be backported/cherrypicked to release-1.27 branch label Jul 11, 2023
@twz123 twz123 changed the title Revisit device and freezer controller detection for cgroup v2 Revisit devices and freezer controller detection for cgroup v2 Jul 11, 2023
@twz123 twz123 force-pushed the cgroupv2-devices-freezer-detection branch 6 times, most recently from 96c150a to 69ebba0 Compare July 13, 2023 09:03
@twz123 twz123 marked this pull request as ready for review July 13, 2023 10:35
@twz123 twz123 requested a review from a team as a code owner July 13, 2023 10:35
@twz123 twz123 force-pushed the cgroupv2-devices-freezer-detection branch from 69ebba0 to 42d0b2c Compare August 10, 2023 11:08
@twz123 twz123 force-pushed the cgroupv2-devices-freezer-detection branch from 42d0b2c to 3b4a730 Compare September 7, 2023 12:46
@twz123 twz123 force-pushed the cgroupv2-devices-freezer-detection branch from 3b4a730 to e26ad5c Compare September 11, 2023 10:12
@twz123 twz123 force-pushed the cgroupv2-devices-freezer-detection branch 3 times, most recently from 16116ac to c47aea3 Compare September 11, 2023 13:30
@twz123 twz123 force-pushed the cgroupv2-devices-freezer-detection branch from c47aea3 to 6a022d0 Compare September 21, 2023 10:35
This is the same library that is used by containerd when it comes to
cgroupv2 handling. k0s already links against it, and it exposes enought
knobs in order to be the backend for the cgroupv2 sysinfo backend, so
this seems a good choice to reduce the amount of low-level plumbing
here.

Signed-off-by: Tom Wieczorek <[email protected]>
The cgroup v2 freezer controller is not listed in the cgroup.controllers
file and is deliberately not available in the root cgroup. Therefore,
k0s sysinfo determines its presence based on the Linux kernel version.
This is problematic for old kernels that have many backported features,
such as RHEL and consorts.

However, it is still possible to detect the freezer controller via the
cgroups filesystem in cgroups other than the root group. To provide
a more reliable result for all kernels, k0s now tries to detect the
controller in its own cgroup. In the unlikely case that k0s is running
in the root cgroup, it will try to create an empty, temporary cgroup for
the freezer file detection. If it doesn't have sufficient permissions to
do so, it issues an "unknown" warning.

See: 0655941 ("Add pre-flight checks and probes module")
Signed-off-by: Tom Wieczorek <[email protected]>
The cgroup v2 device controller is not listed in the cgroup.controllers
file and is solely available via the kernel's BPF interface. Therefore,
k0s sysinfo determines its presence based on the Linux kernel version.
This is problematic for old kernels that have many backported features,
such as RHEL and consorts.

However, it is still possible to detect the device controller by trying
to attach a dummy device filter to an empty, temporary cgroup. In case
k0s is unable to create the cgroup or attach the device filter because
of missing permissions, the sysinfo probe will issue an "unknown"
warning.

See: 0655941 ("Add pre-flight checks and probes module")
Signed-off-by: Tom Wieczorek <[email protected]>
@twz123 twz123 force-pushed the cgroupv2-devices-freezer-detection branch from 6a022d0 to fba2a21 Compare October 12, 2023 06:56
@twz123 twz123 removed the request for review from mikhail-sakhnov October 12, 2023 06:57
Copy link
Member

@jnummelin jnummelin left a comment

Choose a reason for hiding this comment

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

LGTM

@twz123 twz123 merged commit ebcb172 into k0sproject:main Oct 16, 2023
74 checks passed
@twz123 twz123 deleted the cgroupv2-devices-freezer-detection branch October 16, 2023 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants