mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
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:
commit
f19118eea8
@ -317,13 +317,9 @@ func (m *cgroupManagerImpl) Destroy(cgroupConfig *CgroupConfig) error {
|
|||||||
// depending on the cgroup driver in use, so we need this conditional here.
|
// depending on the cgroup driver in use, so we need this conditional here.
|
||||||
if m.adapter.cgroupManagerType == libcontainerSystemd {
|
if m.adapter.cgroupManagerType == libcontainerSystemd {
|
||||||
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
|
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
|
||||||
} else {
|
|
||||||
if libcontainercgroups.IsCgroup2UnifiedMode() {
|
|
||||||
libcontainerCgroupConfig.Path = m.buildCgroupUnifiedPath(cgroupConfig.Name)
|
|
||||||
} else {
|
} else {
|
||||||
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
|
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
manager, err := m.adapter.newManager(libcontainerCgroupConfig, cgroupPaths)
|
manager, err := m.adapter.newManager(libcontainerCgroupConfig, cgroupPaths)
|
||||||
if err != nil {
|
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
|
// propagateControllers on an unified hierarchy enables all the supported controllers for the specified cgroup
|
||||||
func propagateControllers(path string) error {
|
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)
|
return fmt.Errorf("failed to create cgroup %q : %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -464,15 +460,12 @@ func propagateControllers(path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
current := cmutil.CgroupRoot
|
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.
|
// 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:
|
// 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/cgroup.subtree_control
|
||||||
// - /sys/fs/cgroup/foo/bar/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)
|
current = filepath.Join(current, p)
|
||||||
if err := ioutil.WriteFile(filepath.Join(current, "cgroup.subtree_control"), []byte(controllers), 0755); err != nil {
|
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)
|
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")
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create cgroup v2 manager: %v", err)
|
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()
|
unified := libcontainercgroups.IsCgroup2UnifiedMode()
|
||||||
if unified {
|
if unified {
|
||||||
libcontainerCgroupConfig.Path = m.buildCgroupUnifiedPath(cgroupConfig.Name)
|
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
|
||||||
} else {
|
} else {
|
||||||
libcontainerCgroupConfig.Paths = m.buildCgroupPaths(cgroupConfig.Name)
|
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.
|
// depending on the cgroup driver in use, so we need this conditional here.
|
||||||
if m.adapter.cgroupManagerType == libcontainerSystemd {
|
if m.adapter.cgroupManagerType == libcontainerSystemd {
|
||||||
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
|
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
|
||||||
} else {
|
|
||||||
if libcontainercgroups.IsCgroup2UnifiedMode() {
|
|
||||||
libcontainerCgroupConfig.Path = m.buildCgroupUnifiedPath(cgroupConfig.Name)
|
|
||||||
} else {
|
} else {
|
||||||
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
|
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.SupportPodPidsLimit) && cgroupConfig.ResourceParameters != nil && cgroupConfig.ResourceParameters.PidsLimit != nil {
|
if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.SupportPodPidsLimit) && cgroupConfig.ResourceParameters != nil && cgroupConfig.ResourceParameters.PidsLimit != nil {
|
||||||
libcontainerCgroupConfig.PidsLimit = *cgroupConfig.ResourceParameters.PidsLimit
|
libcontainerCgroupConfig.PidsLimit = *cgroupConfig.ResourceParameters.PidsLimit
|
||||||
|
Loading…
Reference in New Issue
Block a user