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

add CONFIG_CGROUP_BPF to required kernel config #41

Merged
merged 4 commits into from
Oct 17, 2024

Conversation

@k8s-ci-robot
Copy link
Contributor

@pacoxu: GitHub didn't allow me to request PR reviews from the following users: KentaTada.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

References:

Fixes #36

/cc @KentaTada @neolit123

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/node Categorizes an issue or PR as relevant to SIG Node. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 25, 2024
@pacoxu
Copy link
Member Author

pacoxu commented Sep 25, 2024

As cgroup v1 is in maintenance mode but not removed, we should not remove the cgroup v1 related kernel config out.

However, should we show different message for CONFIG_CGROUP_BPF missing?
Or should we check if the user is in cgroup v1 or v2 at this point to decide which check policy to use?

@pacoxu pacoxu force-pushed the kernel-config-cgroupv2 branch from 5f9c5bb to c4cf635 Compare September 25, 2024 06:58
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

in #36 @KentaTada mentioned that we need to read another file to verify cgroupv2.

Unlike in v1, the kernel config alone cannot determine whether the required v2 features are enabled.

@pacoxu
Copy link
Member Author

pacoxu commented Sep 26, 2024

in #36 @KentaTada mentioned that we need to read another file to verify cgroupv2.

It seems that we need to check in different ways for cgroup v1 and cgroup v2.

For instance,

  • cgroup v2: check /sys/fs/cgroup/init.scope/cgroup.freeze
  • cgroup v1: check CONFIG_CGROUP_FREEZER.

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 26, 2024
@pacoxu
Copy link
Member Author

pacoxu commented Sep 26, 2024

	// /proc/cgroups is meaningless for v2
	// https://github.com/torvalds/linux/blob/v5.3/Documentation/admin-guide/cgroup-v2.rst#deprecated-v1-core-features
	if IsCgroup2UnifiedMode() {
		// "pseudo" controllers do not appear in /sys/fs/cgroup/cgroup.controllers.
		// - devices: implemented in kernel 4.15
		// - freezer: implemented in kernel 5.2
		// We assume these are always available, as it is hard to detect availability.
		pseudo := []string{"devices", "freezer"}
		data, err := ReadFile("/sys/fs/cgroup", "cgroup.controllers")
		if err != nil {
			return nil, err
		}
		subsystems := append(pseudo, strings.Fields(data)...)
		return subsystems, nil
	}

Runc code https://github.com/kubernetes/kubernetes/blob/e404a28fae6946483c5de0e9f4b4adf6e6f63f3b/vendor/github.com/opencontainers/runc/libcontainer/cgroups/utils.go#L100-L114

@pacoxu
Copy link
Member Author

pacoxu commented Sep 26, 2024

func (c *CgroupsValidator) getCgroupV2Subsystems() ([]string, error) {
// Some controllers are implicitly enabled by the kernel.
// Those controllers do not appear in /sys/fs/cgroup/cgroup.controllers.
// https://github.com/torvalds/linux/blob/v5.3/kernel/cgroup/cgroup.c#L433-L434
// We assume these are always available, as it is hard to detect availability.
// So, we hardcode the following as "pseudo" controllers.
// - devices: implemented in kernel 4.15
// - freezer: implemented in kernel 5.2
pseudo := []string{"devices", "freezer"}
data, err := ioutil.ReadFile(filepath.Join(unifiedMountpoint, "cgroup.controllers"))
if err != nil {
return nil, err
}
subsystems := append(pseudo, strings.Fields(string(data))...)
return subsystems, nil
}

	pseudo := []string{"devices", "freezer"}

We currently use the similar logic here and add freezer as default.

Cgroups: []string{"cpu", "cpuacct", "cpuset", "devices", "freezer", "memory", "pids"},
CgroupsOptional: []string{

This checks the cgroup sub controllers.

@neolit123
Copy link
Member

neolit123 commented Sep 26, 2024

aligning with RUNC seems good to me.

what about these comments about freeze vs freezer?
#36 (comment)

@pacoxu pacoxu force-pushed the kernel-config-cgroupv2 branch from c4cf635 to e50ca40 Compare September 26, 2024 08:13
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 26, 2024
@pacoxu pacoxu force-pushed the kernel-config-cgroupv2 branch from e50ca40 to 51eb654 Compare September 26, 2024 08:22
@pacoxu
Copy link
Member Author

pacoxu commented Sep 26, 2024

/unhold
For cgroup v1 cleanup, we should not do it now.

what about these comments about freeze vs freezer?
#36 (comment)

Updated.

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 26, 2024
@pacoxu pacoxu force-pushed the kernel-config-cgroupv2 branch from 51eb654 to 5843314 Compare September 26, 2024 08:33
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve
/hold

@KentaTada could you please have a look too?

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 26, 2024
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 26, 2024
@neolit123
Copy link
Member

For cgroup v1 cleanup, we should not do it now.

could you explain why?

@pacoxu
Copy link
Member Author

pacoxu commented Sep 26, 2024

For cgroup v1 cleanup, we should not do it now.

could you explain why?

Basically two reasons IMO:

  1. Kubernetes 1.31: Moving cgroup v1 Support into Maintenance Mode, not deprecated.
  2. Most OS distrbutions keeps the cgroup v1 related kernel config as is, and I think this may be for backward compatibility.

@neolit123
Copy link
Member

For cgroup v1 cleanup, we should not do it now.

could you explain why?

Basically two reasons IMO:

  1. Kubernetes 1.31: Moving cgroup v1 Support into Maintenance Mode, not deprecated.
  2. Most OS distrbutions keeps the cgroup v1 related kernel config as is, and I think this may be for backward compatibility.

ok, got it. you mean that we should not cleanup cgroups v1 because they are still widely used.

i tried finding @KentaTada 's slack to give him a ping but couldn't.
let's wait until end of next week maybe and if he does not reply we can go merge this PR as it is.

@KentaTada
Copy link

@KentaTada could you please have a look too?

I'll take a look at this pr by the first half of the next week.

@pacoxu
Copy link
Member Author

pacoxu commented Oct 15, 2024

I updated the PR accordingly and the only unresolved comment is https://github.com/kubernetes/system-validators/pull/41/files#r1800338762.

  • I am not sure how to confirm about the default mount point if we cannot get the mount info correctly.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 15, 2024
@pacoxu pacoxu force-pushed the kernel-config-cgroupv2 branch from 95629f0 to b8d518a Compare October 15, 2024 05:54
@pacoxu pacoxu force-pushed the kernel-config-cgroupv2 branch 3 times, most recently from 4ea6136 to 26b2c98 Compare October 15, 2024 07:19
@pacoxu pacoxu force-pushed the kernel-config-cgroupv2 branch 3 times, most recently from c34f1f4 to 0e215f9 Compare October 15, 2024 08:25
@KentaTada
Copy link

@pacoxu
Thank you for improving this feature.
It looks good to me.

@pacoxu
Copy link
Member Author

pacoxu commented Oct 16, 2024

@pacoxu
Thank you for improving this feature.
It looks good to me.

Thanks for your detailed review and comments.
Wait for @neolit123 to double check if anything is missing.

@pacoxu pacoxu force-pushed the kernel-config-cgroupv2 branch from 0e215f9 to 8bf7873 Compare October 16, 2024 07:51
@pacoxu
Copy link
Member Author

pacoxu commented Oct 16, 2024

I refactor the logic to just parse /proc/mounts to get the first cgroup path.

  • and I add a simple test for getUnifiedMountpoint( ).

BTW, the /proc/self/mountinfo file format is a little complex and I removed that part.

Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

this is much better @pacoxu !
mostly requesting minor fixes for text / comments in multiple places.

and only one Q about the file parser.

Comment on lines +76 to +78
if len(cgroupV1MountPoint) == 0 {
cgroupV1MountPoint = fields[1]
}
Copy link
Member

Choose a reason for hiding this comment

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

is it ok to just do this?

Suggested change
if len(cgroupV1MountPoint) == 0 {
cgroupV1MountPoint = fields[1]
}
cgroupV1MountPoint = fields[1]

i.e. always update the var if more cgroups v1 mount points are found or should we only catch the first one?
(i don't know the format)

Copy link
Member Author

Choose a reason for hiding this comment

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

[root@10-29-14-249 ~]# cat /proc/mounts | grep cgroup
tmpfs /sys/fs/cgroup tmpfs ro,seclabel,nosuid,nodev,noexec,mode=755 0 0
cgroup /sys/fs/cgroup/systemd cgroup rw,seclabel,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0
cgroup /sys/fs/cgroup/blkio cgroup rw,seclabel,nosuid,nodev,noexec,relatime,blkio 0 0
cgroup /sys/fs/cgroup/hugetlb cgroup rw,seclabel,nosuid,nodev,noexec,relatime,hugetlb 0 0
cgroup /sys/fs/cgroup/perf_event cgroup rw,seclabel,nosuid,nodev,noexec,relatime,perf_event 0 0
cgroup /sys/fs/cgroup/memory cgroup rw,seclabel,nosuid,nodev,noexec,relatime,memory 0 0
cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,seclabel,nosuid,nodev,noexec,relatime,net_prio,net_cls 0 0
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0
cgroup /sys/fs/cgroup/devices cgroup rw,seclabel,nosuid,nodev,noexec,relatime,devices 0 0
cgroup /sys/fs/cgroup/pids cgroup rw,seclabel,nosuid,nodev,noexec,relatime,pids 0 0
cgroup /sys/fs/cgroup/cpuset cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuset 0 0
cgroup /sys/fs/cgroup/freezer cgroup rw,seclabel,nosuid,nodev,noexec,relatime,freezer 0 0

For cgroup v1, this is an example. I prefer to get the first one.

@pacoxu pacoxu force-pushed the kernel-config-cgroupv2 branch from 8bf7873 to 4a1c1a3 Compare October 17, 2024 07:50
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

should i create a new release after this?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 17, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: neolit123, pacoxu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pacoxu
Copy link
Member Author

pacoxu commented Oct 17, 2024

should i create a new release after this?

Yes, as we have no todo items for v1.32.

@neolit123
Copy link
Member

neolit123 commented Oct 17, 2024

unrelated fix, please LGTM

will cut a release after it merges and send PR for k/k.

@pacoxu
Copy link
Member Author

pacoxu commented Oct 17, 2024

/unhold
Thanks @KentaTada @neolit123 for your reviewing.

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 17, 2024
@k8s-ci-robot k8s-ci-robot merged commit c4f0414 into kubernetes:master Oct 17, 2024
3 checks passed
@neolit123
Copy link
Member

i will also rename the branch of this repo to main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/node Categorizes an issue or PR as relevant to SIG Node. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the kernel configuration for cgroup v2
4 participants