- 
                Notifications
    You must be signed in to change notification settings 
- Fork 83
plugin helpers: A function to get the absolute path to the CGroupsV2 #227
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
base: main
Are you sure you want to change the base?
plugin helpers: A function to get the absolute path to the CGroupsV2 #227
Conversation
Signed-off-by: Neeraj Krishna Gopalakrishna <ngopalak@redhat.com>
| @ngopalak-redhat @askervin This looks a bit off. Are you sure this really works ? I think the resolution algorithm should be different depending on whether the runtime is using the  If we decide to provide such a helper, it should not be part of  | 
| 
 Thanks @klihub for the review. Happy to move to  For the first point,  | 
Signed-off-by: Neeraj Krishna Gopalakrishna <ngopalak@redhat.com>
e8453c4    to
    5e91df8      
    Compare
  
    | @klihub I have re-opened the PR with the requested changes. Initially thought its a good-first-issue to pick up to get deep understanding of NRI plugins. But handling the path turned out to be more complex than I expected. Its a useful change for users needing access to CGroups directory. | 
| /cc @askervin PTAL | 
| 
 WDYT about this functionality as part of https://github.com/containerd/cgroups | 
| 
 @akhilerm Thanks a lot for your inputs/suggestion. | 
| Yeah I was wondering as well if there's either existing utilities in https://github.com/opencontainers/cgroups or https://github.com/containerd/cgroups that could be used (or added) and could be used for the implementation. also cc @kolyshkin - who may have a better picture on what's already available (or missing). | 
Signed-off-by: Neeraj Krishna Gopalakrishna <ngopalak@redhat.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ngopalak-redhat, thanks for picking up this task! This will definitely be helpful, and as you already saw, it's really non-trivial and easy to get wrong.
I tried it out with cri-o 1.32 systemd, containerd 1.17.27 systemd, and containerd 2.1beta cgroupfs. First two cases were fine, but in the last paths were interpreted absolute as is even if they were not:
[root@fedora-42 ~]#  ./logger -events createcontainer,runpodsandbox -enable-cgroups-log -idx 10 2>&1 | grep --color=auto -i cgroup &
[1] 8819
[root@fedora-42 ~]# kubectl create -f pod0.yaml
pod/pod0 created
[root@fedora-42 ~]# time="2025-09-03T14:44:54Z" level=info msg="RunPodSandbox:      cgroup_parent: /kubepods/besteffort/pod587e7105-0ad9-4c3c-9439-adb67738d658"
time="2025-09-03T14:44:54Z" level=info msg="RunPodSandbox:      cgroups_path: /kubepods/besteffort/pod587e7105-0ad9-4c3c-9439-adb67738d658/c816898460502f26511528dd406d00bed8397da49095f137069e7b1fefec7d57"
time="2025-09-03T14:44:54Z" level=info msg="PodSandbox CGroups" absolutePath=/kubepods/besteffort/pod587e7105-0ad9-4c3c-9439-adb67738d658/c816898460502f26511528dd406d00bed8397da49095f137069e7b1fefec7d57 relativePath=/kubepods/besteffort/pod587e7105-0ad9-4c3c-9439-adb67738d658/c816898460502f26511528dd406d00bed8397da49095f137069e7b1fefec7d57
Signed-off-by: Neeraj Krishna Gopalakrishna <ngopalak@redhat.com> Signed-off-by: Neeraj Krishna Gopalakrishna <ngopalak@redhat.com>
| 
 I have fixed the usecase with cgroupfs and containerd and updated the description. | 
| 
 @thaJeztah @ngopalak-redhat @askervin A possible (and I'd say also preferable) alternative to this would be to expose the corresponding path construction/resolution functions from either (or both) of the above packages for public consumption at a suitable pkg-subpath. Then, if we still wanted to provide a NRI plugin helper wrapper for it here, we'd import and use it here. Or alternatively we could do the same on the runtime side (where there is more explicit knowledge about the cgroup driver configuration) and pass it to NRI plugins as a new  | 
Fixes: #35
Added a function to get the absolute path for cgroups. It will fall back to /sys/fs/cgroup in case there are issues accessing /proc/mounts, where the cgroups mount is defined.
Added a flag for the nri-logger to print the Cgroup path so that it has minimal impact on the plugin. Consider it an example for developers who need this function.
Examples
Here's an example for expansion used by expandSliceHierarchy() method:
Special cases
Test Process
Repeat for cri-o and container-d
Testing with cri-o on openshift cluster:
Test result: I can see ls working for the path given in the log
Testing with containerd on kind:
Test result: I can see ls working for the path given in the log
Test with cgroupfs on containerd with kind