Skip to content

Commit f19118e

Browse files
authored
Merge pull request kubernetes#94111 from giuseppe/fix-cgroup-v2-cgroupfs-path
kubelet, cgroupv2: do not create /sys/fs/cgroup/sys with cgroupfs
2 parents 0c233eb + 49cbf91 commit f19118e

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

pkg/kubelet/cm/cgroup_manager_linux.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,7 @@ func (m *cgroupManagerImpl) Destroy(cgroupConfig *CgroupConfig) error {
318318
if m.adapter.cgroupManagerType == libcontainerSystemd {
319319
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
320320
} else {
321-
if libcontainercgroups.IsCgroup2UnifiedMode() {
322-
libcontainerCgroupConfig.Path = m.buildCgroupUnifiedPath(cgroupConfig.Name)
323-
} else {
324-
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
325-
}
321+
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
326322
}
327323

328324
manager, err := m.adapter.newManager(libcontainerCgroupConfig, cgroupPaths)
@@ -435,7 +431,7 @@ func getSupportedUnifiedControllers() sets.String {
435431

436432
// propagateControllers on an unified hierarchy enables all the supported controllers for the specified cgroup
437433
func propagateControllers(path string) error {
438-
if err := os.MkdirAll(path, 0755); err != nil {
434+
if err := os.MkdirAll(filepath.Join(cmutil.CgroupRoot, path), 0755); err != nil {
439435
return fmt.Errorf("failed to create cgroup %q : %v", path, err)
440436
}
441437

@@ -464,15 +460,12 @@ func propagateControllers(path string) error {
464460
}
465461

466462
current := cmutil.CgroupRoot
467-
relPath, err := filepath.Rel(cmutil.CgroupRoot, path)
468-
if err != nil {
469-
return fmt.Errorf("failed to get relative path to cgroup root from %q: %v", path, err)
470-
}
463+
471464
// Write the controllers list to each "cgroup.subtree_control" file until it reaches the parent cgroup.
472465
// For the /foo/bar/baz cgroup, controllers must be enabled sequentially in the files:
473466
// - /sys/fs/cgroup/foo/cgroup.subtree_control
474467
// - /sys/fs/cgroup/foo/bar/cgroup.subtree_control
475-
for _, p := range strings.Split(filepath.Dir(relPath), "/") {
468+
for _, p := range strings.Split(filepath.Dir(path), "/") {
476469
current = filepath.Join(current, p)
477470
if err := ioutil.WriteFile(filepath.Join(current, "cgroup.subtree_control"), []byte(controllers), 0755); err != nil {
478471
return fmt.Errorf("failed to enable controllers on %q: %v", cmutil.CgroupRoot, err)
@@ -505,7 +498,7 @@ func setResourcesV2(cgroupConfig *libcontainerconfigs.Cgroup) error {
505498
klog.V(6).Infof("Optional subsystem not supported: hugetlb")
506499
}
507500

508-
manager, err := cgroupfs2.NewManager(cgroupConfig, cgroupConfig.Path, false)
501+
manager, err := cgroupfs2.NewManager(cgroupConfig, filepath.Join(cmutil.CgroupRoot, cgroupConfig.Path), false)
509502
if err != nil {
510503
return fmt.Errorf("failed to create cgroup v2 manager: %v", err)
511504
}
@@ -597,7 +590,7 @@ func (m *cgroupManagerImpl) Update(cgroupConfig *CgroupConfig) error {
597590

598591
unified := libcontainercgroups.IsCgroup2UnifiedMode()
599592
if unified {
600-
libcontainerCgroupConfig.Path = m.buildCgroupUnifiedPath(cgroupConfig.Name)
593+
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
601594
} else {
602595
libcontainerCgroupConfig.Paths = m.buildCgroupPaths(cgroupConfig.Name)
603596
}
@@ -641,11 +634,7 @@ func (m *cgroupManagerImpl) Create(cgroupConfig *CgroupConfig) error {
641634
if m.adapter.cgroupManagerType == libcontainerSystemd {
642635
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
643636
} else {
644-
if libcontainercgroups.IsCgroup2UnifiedMode() {
645-
libcontainerCgroupConfig.Path = m.buildCgroupUnifiedPath(cgroupConfig.Name)
646-
} else {
647-
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
648-
}
637+
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
649638
}
650639

651640
if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.SupportPodPidsLimit) && cgroupConfig.ResourceParameters != nil && cgroupConfig.ResourceParameters.PidsLimit != nil {

0 commit comments

Comments
 (0)