Merge pull request #94111 from giuseppe/fix-cgroup-v2-cgroupfs-path

kubelet, cgroupv2: do not create /sys/fs/cgroup/sys with cgroupfs
This commit is contained in:
Kubernetes Prow Robot 2020-09-01 19:41:33 -07:00 committed by GitHub
commit f19118eea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -317,13 +317,9 @@ func (m *cgroupManagerImpl) Destroy(cgroupConfig *CgroupConfig) error {
// depending on the cgroup driver in use, so we need this conditional here.
if m.adapter.cgroupManagerType == libcontainerSystemd {
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
} else {
if libcontainercgroups.IsCgroup2UnifiedMode() {
libcontainerCgroupConfig.Path = m.buildCgroupUnifiedPath(cgroupConfig.Name)
} else {
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
}
}
manager, err := m.adapter.newManager(libcontainerCgroupConfig, cgroupPaths)
if err != nil {
@ -435,7 +431,7 @@ func getSupportedUnifiedControllers() sets.String {
// propagateControllers on an unified hierarchy enables all the supported controllers for the specified cgroup
func propagateControllers(path string) error {
if err := os.MkdirAll(path, 0755); err != nil {
if err := os.MkdirAll(filepath.Join(cmutil.CgroupRoot, path), 0755); err != nil {
return fmt.Errorf("failed to create cgroup %q : %v", path, err)
}
@ -464,15 +460,12 @@ func propagateControllers(path string) error {
}
current := cmutil.CgroupRoot
relPath, err := filepath.Rel(cmutil.CgroupRoot, path)
if err != nil {
return fmt.Errorf("failed to get relative path to cgroup root from %q: %v", path, err)
}
// Write the controllers list to each "cgroup.subtree_control" file until it reaches the parent cgroup.
// For the /foo/bar/baz cgroup, controllers must be enabled sequentially in the files:
// - /sys/fs/cgroup/foo/cgroup.subtree_control
// - /sys/fs/cgroup/foo/bar/cgroup.subtree_control
for _, p := range strings.Split(filepath.Dir(relPath), "/") {
for _, p := range strings.Split(filepath.Dir(path), "/") {
current = filepath.Join(current, p)
if err := ioutil.WriteFile(filepath.Join(current, "cgroup.subtree_control"), []byte(controllers), 0755); err != nil {
return fmt.Errorf("failed to enable controllers on %q: %v", cmutil.CgroupRoot, err)
@ -505,7 +498,7 @@ func setResourcesV2(cgroupConfig *libcontainerconfigs.Cgroup) error {
klog.V(6).Infof("Optional subsystem not supported: hugetlb")
}
manager, err := cgroupfs2.NewManager(cgroupConfig, cgroupConfig.Path, false)
manager, err := cgroupfs2.NewManager(cgroupConfig, filepath.Join(cmutil.CgroupRoot, cgroupConfig.Path), false)
if err != nil {
return fmt.Errorf("failed to create cgroup v2 manager: %v", err)
}
@ -597,7 +590,7 @@ func (m *cgroupManagerImpl) Update(cgroupConfig *CgroupConfig) error {
unified := libcontainercgroups.IsCgroup2UnifiedMode()
if unified {
libcontainerCgroupConfig.Path = m.buildCgroupUnifiedPath(cgroupConfig.Name)
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
} else {
libcontainerCgroupConfig.Paths = m.buildCgroupPaths(cgroupConfig.Name)
}
@ -640,13 +633,9 @@ func (m *cgroupManagerImpl) Create(cgroupConfig *CgroupConfig) error {
// depending on the cgroup driver in use, so we need this conditional here.
if m.adapter.cgroupManagerType == libcontainerSystemd {
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
} else {
if libcontainercgroups.IsCgroup2UnifiedMode() {
libcontainerCgroupConfig.Path = m.buildCgroupUnifiedPath(cgroupConfig.Name)
} else {
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
}
}
if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.SupportPodPidsLimit) && cgroupConfig.ResourceParameters != nil && cgroupConfig.ResourceParameters.PidsLimit != nil {
libcontainerCgroupConfig.PidsLimit = *cgroupConfig.ResourceParameters.PidsLimit