@@ -89,7 +89,7 @@ func (m *SystemdManager) ContainerCgroupAbsolutePath(sbParent, containerID strin
8989 return "" , errors .Wrapf (err , "error expanding systemd slice to get container %s stats" , containerID )
9090 }
9191
92- return filepath .Join (cgroup , crioPrefix + "-" + containerID + ".scope" ), nil
92+ return filepath .Join (cgroup , containerCgroupPath ( containerID ) + ".scope" ), nil
9393}
9494
9595// MoveConmonToCgroup takes the container ID, cgroup parent, conmon's cgroup (from the config) and conmon's PID
@@ -200,8 +200,37 @@ func convertCgroupFsNameToSystemd(cgroupfsName string) string {
200200}
201201
202202// CreateSandboxCgroup calls the helper function createSandboxCgroup for this manager.
203+ // Note: createSandboxCgroup will create a cgroupfs cgroup for the infra container underneath the pod slice.
204+ // It will not use dbus to create this cgroup, but instead call libcontainer's cgroupfs manager directly.
205+ // This is because a scope created here will not have a process within it (as it's usually for a dropped infra container),
206+ // and a slice cannot have the required `crio` prefix (while still being within the pod slice).
207+ // Ultimately, this cgroup is required for cAdvisor to be able to register the pod and collect network metrics for it.
208+ // This work will not be relevant when CRI-O is responsible for gathering pod metrics (KEP-2371), but is required until that's done.
203209func (m * SystemdManager ) CreateSandboxCgroup (sbParent , containerID string ) error {
204- // If we are running systemd as cgroup driver then we would rely on
205- // systemd to create cgroups for us, there's nothing to do here in this case
206- return nil
210+ // sbParent should always be specified by kubelet, but sometimes not by critest/crictl.
211+ // Skip creation in this case.
212+ if sbParent == "" {
213+ logrus .Infof ("Not creating sandbox cgroup: sbParent is empty" )
214+ return nil
215+ }
216+ expandedParent , err := systemd .ExpandSlice (sbParent )
217+ if err != nil {
218+ return err
219+ }
220+ return createSandboxCgroup (expandedParent , containerCgroupPath (containerID ))
221+ }
222+
223+ // RemoveSandboxCgroup calls the helper function removeSandboxCgroup for this manager.
224+ func (m * SystemdManager ) RemoveSandboxCgroup (sbParent , containerID string ) error {
225+ // sbParent should always be specified by kubelet, but sometimes not by critest/crictl.
226+ // Skip creation in this case.
227+ if sbParent == "" {
228+ logrus .Infof ("Not creating sandbox cgroup: sbParent is empty" )
229+ return nil
230+ }
231+ expandedParent , err := systemd .ExpandSlice (sbParent )
232+ if err != nil {
233+ return err
234+ }
235+ return removeSandboxCgroup (expandedParent , containerCgroupPath (containerID ))
207236}
0 commit comments