mirror of
https://github.com/containers/podman.git
synced 2025-06-10 09:47:25 +08:00
specgen: split cgroup v1 and cgroup v2 code
refactor function into two separate ones. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -7,16 +7,10 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Verify resource limits are sanely set, removing any limits that are not
|
// Verify resource limits are sanely set when running on cgroup v1.
|
||||||
// possible with the current cgroups config.
|
func verifyContainerResourcesCgroupV1(s *specgen.SpecGenerator) ([]string, error) {
|
||||||
func verifyContainerResources(s *specgen.SpecGenerator) ([]string, error) {
|
|
||||||
warnings := []string{}
|
warnings := []string{}
|
||||||
|
|
||||||
cgroup2, err := cgroups.IsCgroup2UnifiedMode()
|
|
||||||
if err != nil || cgroup2 {
|
|
||||||
return warnings, err
|
|
||||||
}
|
|
||||||
|
|
||||||
sysInfo := sysinfo.New(true)
|
sysInfo := sysinfo.New(true)
|
||||||
|
|
||||||
if s.ResourceLimits == nil {
|
if s.ResourceLimits == nil {
|
||||||
@ -24,10 +18,8 @@ func verifyContainerResources(s *specgen.SpecGenerator) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s.ResourceLimits.Unified != nil {
|
if s.ResourceLimits.Unified != nil {
|
||||||
if !cgroup2 {
|
|
||||||
return nil, errors.New("Cannot use --cgroup-conf without cgroup v2")
|
return nil, errors.New("Cannot use --cgroup-conf without cgroup v2")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Memory checks
|
// Memory checks
|
||||||
if s.ResourceLimits.Memory != nil {
|
if s.ResourceLimits.Memory != nil {
|
||||||
@ -163,3 +155,21 @@ func verifyContainerResources(s *specgen.SpecGenerator) ([]string, error) {
|
|||||||
|
|
||||||
return warnings, nil
|
return warnings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify resource limits are sanely set when running on cgroup v2.
|
||||||
|
func verifyContainerResourcesCgroupV2(s *specgen.SpecGenerator) ([]string, error) {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify resource limits are sanely set, removing any limits that are not
|
||||||
|
// possible with the current cgroups config.
|
||||||
|
func verifyContainerResources(s *specgen.SpecGenerator) ([]string, error) {
|
||||||
|
cgroup2, err := cgroups.IsCgroup2UnifiedMode()
|
||||||
|
if err != nil {
|
||||||
|
return []string{}, err
|
||||||
|
}
|
||||||
|
if cgroup2 {
|
||||||
|
return verifyContainerResourcesCgroupV2(s)
|
||||||
|
}
|
||||||
|
return verifyContainerResourcesCgroupV1(s)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user