mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #108568 from stevekuznetsov/skuznets/verbose-error
kubelet: cgroups: be verbose about validation
This commit is contained in:
commit
c227403973
@ -253,21 +253,20 @@ func updateSystemdCgroupInfo(cgroupConfig *libcontainerconfigs.Cgroup, cgroupNam
|
|||||||
cgroupConfig.Name = base
|
cgroupConfig.Name = base
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exists checks if all subsystem cgroups already exist
|
// Validate checks if all subsystem cgroups already exist
|
||||||
func (m *cgroupManagerImpl) Exists(name CgroupName) bool {
|
func (m *cgroupManagerImpl) Validate(name CgroupName) error {
|
||||||
if libcontainercgroups.IsCgroup2UnifiedMode() {
|
if libcontainercgroups.IsCgroup2UnifiedMode() {
|
||||||
cgroupPath := m.buildCgroupUnifiedPath(name)
|
cgroupPath := m.buildCgroupUnifiedPath(name)
|
||||||
neededControllers := getSupportedUnifiedControllers()
|
neededControllers := getSupportedUnifiedControllers()
|
||||||
enabledControllers, err := readUnifiedControllers(cgroupPath)
|
enabledControllers, err := readUnifiedControllers(cgroupPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return fmt.Errorf("could not read controllers for cgroup %q: %w", name, err)
|
||||||
}
|
}
|
||||||
difference := neededControllers.Difference(enabledControllers)
|
difference := neededControllers.Difference(enabledControllers)
|
||||||
if difference.Len() > 0 {
|
if difference.Len() > 0 {
|
||||||
klog.V(4).InfoS("The cgroup has some missing controllers", "cgroupName", name, "controllers", difference)
|
return fmt.Errorf("cgroup %q has some missing controllers: %v", name, strings.Join(difference.List(), ", "))
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
return true
|
return nil // valid V2 cgroup
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get map of all cgroup paths on the system for the particular cgroup
|
// Get map of all cgroup paths on the system for the particular cgroup
|
||||||
@ -297,11 +296,15 @@ func (m *cgroupManagerImpl) Exists(name CgroupName) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(missingPaths) > 0 {
|
if len(missingPaths) > 0 {
|
||||||
klog.V(4).InfoS("The cgroup has some missing paths", "cgroupName", name, "paths", missingPaths)
|
return fmt.Errorf("cgroup %q has some missing paths: %v", name, strings.Join(missingPaths, ", "))
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return nil // valid V1 cgroup
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exists checks if all subsystem cgroups already exist
|
||||||
|
func (m *cgroupManagerImpl) Exists(name CgroupName) bool {
|
||||||
|
return m.Validate(name) == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy destroys the specified cgroup
|
// Destroy destroys the specified cgroup
|
||||||
|
@ -41,6 +41,10 @@ func (m *unsupportedCgroupManager) Name(_ CgroupName) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *unsupportedCgroupManager) Validate(_ CgroupName) error {
|
||||||
|
return errNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
func (m *unsupportedCgroupManager) Exists(_ CgroupName) bool {
|
func (m *unsupportedCgroupManager) Exists(_ CgroupName) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -257,8 +257,8 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
|
|||||||
// of note, we always use the cgroupfs driver when performing this check since
|
// of note, we always use the cgroupfs driver when performing this check since
|
||||||
// the input is provided in that format.
|
// the input is provided in that format.
|
||||||
// this is important because we do not want any name conversion to occur.
|
// this is important because we do not want any name conversion to occur.
|
||||||
if !cgroupManager.Exists(cgroupRoot) {
|
if err := cgroupManager.Validate(cgroupRoot); err != nil {
|
||||||
return nil, fmt.Errorf("invalid configuration: cgroup-root %q doesn't exist", cgroupRoot)
|
return nil, fmt.Errorf("invalid configuration: %w", err)
|
||||||
}
|
}
|
||||||
klog.InfoS("Container manager verified user specified cgroup-root exists", "cgroupRoot", cgroupRoot)
|
klog.InfoS("Container manager verified user specified cgroup-root exists", "cgroupRoot", cgroupRoot)
|
||||||
// Include the top level cgroup for enforcing node allocatable into cgroup-root.
|
// Include the top level cgroup for enforcing node allocatable into cgroup-root.
|
||||||
|
@ -156,8 +156,8 @@ func enforceExistingCgroup(cgroupManager CgroupManager, cName CgroupName, rl v1.
|
|||||||
return fmt.Errorf("%q cgroup is not config properly", cgroupConfig.Name)
|
return fmt.Errorf("%q cgroup is not config properly", cgroupConfig.Name)
|
||||||
}
|
}
|
||||||
klog.V(4).InfoS("Enforcing limits on cgroup", "cgroupName", cName, "cpuShares", cgroupConfig.ResourceParameters.CpuShares, "memory", cgroupConfig.ResourceParameters.Memory, "pidsLimit", cgroupConfig.ResourceParameters.PidsLimit)
|
klog.V(4).InfoS("Enforcing limits on cgroup", "cgroupName", cName, "cpuShares", cgroupConfig.ResourceParameters.CpuShares, "memory", cgroupConfig.ResourceParameters.Memory, "pidsLimit", cgroupConfig.ResourceParameters.PidsLimit)
|
||||||
if !cgroupManager.Exists(cgroupConfig.Name) {
|
if err := cgroupManager.Validate(cgroupConfig.Name); err != nil {
|
||||||
return fmt.Errorf("%q cgroup does not exist", cgroupConfig.Name)
|
return err
|
||||||
}
|
}
|
||||||
if err := cgroupManager.Update(cgroupConfig); err != nil {
|
if err := cgroupManager.Update(cgroupConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -66,6 +66,8 @@ type CgroupManager interface {
|
|||||||
Destroy(*CgroupConfig) error
|
Destroy(*CgroupConfig) error
|
||||||
// Update cgroup configuration.
|
// Update cgroup configuration.
|
||||||
Update(*CgroupConfig) error
|
Update(*CgroupConfig) error
|
||||||
|
// Validate checks if the cgroup is valid
|
||||||
|
Validate(name CgroupName) error
|
||||||
// Exists checks if the cgroup already exists
|
// Exists checks if the cgroup already exists
|
||||||
Exists(name CgroupName) bool
|
Exists(name CgroupName) bool
|
||||||
// Name returns the literal cgroupfs name on the host after any driver specific conversions.
|
// Name returns the literal cgroupfs name on the host after any driver specific conversions.
|
||||||
|
Loading…
Reference in New Issue
Block a user