Skip to content

Commit

Permalink
Add cpu/mem limits to podman
Browse files Browse the repository at this point in the history
  • Loading branch information
LimeHat committed Jan 6, 2022
1 parent 509ff34 commit 2dfbebf
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions runtime/podman/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/containers/podman/v3/pkg/bindings/network"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/specgen"
"github.com/dustin/go-humanize"
"github.com/google/shlex"
"github.com/opencontainers/runtime-spec/specs-go"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -106,8 +107,44 @@ func (r *PodmanRuntime) createContainerSpec(ctx context.Context, cfg *types.Node
specCgroupConfig := specgen.ContainerCgroupConfig{
CgroupNS: specgen.Namespace{},
}
// Defaults for resource limits
specResConfig := specgen.ContainerResourceConfig{}
// Resource limits
var (
resLimits specs.LinuxResources
lMem specs.LinuxMemory
lCPU specs.LinuxCPU
)
// Memory limits
if cfg.Memory != "" {
mem, err := humanize.ParseBytes(node.Memory)
if err != nil {
log.Warnf("Unable to parse memory limit %q for node %q", cfg.Memory, cfg.LongName)
}
lMem.Limit = int64(mem)
}
resLimits.Memory = lMem
// CPU resources limits
if cfg.CPU != 0 {
lCPU.Quota = int64(cfg.CPU * 100000)
lCPU.Period = 100000
}
if cfg.CPUSet != "" {
lCPU.Cpus = cfg.CPUSet
}
resLimits.CPU = lCPU

specResConfig := specgen.ContainerResourceConfig{
ResourceLimits: resLimits,
// Rlimits: nil,
// OOMScoreAdj: nil,
// WeightDevice: nil,
// ThrottleReadBpsDevice: nil,
// ThrottleWriteBpsDevice: nil,
// ThrottleReadIOPSDevice: nil,
// ThrottleWriteIOPSDevice: nil,
// CgroupConf: nil,
// CPUPeriod: 0,
// CPUQuota: 0,
}
// Defaults for health checks
specHCheckConfig := specgen.ContainerHealthCheckConfig{}
// Everything below is related to network spec of a container
Expand Down

0 comments on commit 2dfbebf

Please sign in to comment.