summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-04-20 15:50:02 -0400
committerGitHub <noreply@github.com>2020-04-20 15:50:02 -0400
commit5928e8fe80e1f013049f1a980a4c945ee35570c3 (patch)
tree0c3d81925317bb879d3240fcf3e4df39091c4838 /cmd
parent80355b168c0754fd5dba3c8ac371fc614d23dc2f (diff)
parent4e09c5ebb456e739530344f82d51f3db4b1dfd1c (diff)
downloadpodman-5928e8fe80e1f013049f1a980a4c945ee35570c3.tar.gz
podman-5928e8fe80e1f013049f1a980a4c945ee35570c3.tar.bz2
podman-5928e8fe80e1f013049f1a980a4c945ee35570c3.zip
Merge pull request #5896 from giuseppe/fix-cgroup-set
common: setting cgroup resources correctly
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common/specgen.go51
1 files changed, 37 insertions, 14 deletions
diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go
index 85b344b3c..b8526993c 100644
--- a/cmd/podman/common/specgen.go
+++ b/cmd/podman/common/specgen.go
@@ -47,6 +47,12 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
if err != nil {
return err
}
+ if s.ResourceLimits == nil {
+ s.ResourceLimits = &specs.LinuxResources{}
+ }
+ if s.ResourceLimits.Memory == nil {
+ s.ResourceLimits.Memory = &specs.LinuxMemory{}
+ }
if m := c.Memory; len(m) > 0 {
ml, err := units.RAMInBytes(m)
if err != nil {
@@ -81,6 +87,9 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
}
s.ResourceLimits.Memory.Kernel = &mk
}
+ if s.ResourceLimits.BlockIO == nil {
+ s.ResourceLimits.BlockIO = &specs.LinuxBlockIO{}
+ }
if b := c.BlkIOWeight; len(b) > 0 {
u, err := strconv.ParseUint(b, 10, 16)
if err != nil {
@@ -313,14 +322,16 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
s.StopSignal = &stopSignal
}
}
- swappiness := uint64(c.MemorySwappiness)
if s.ResourceLimits == nil {
s.ResourceLimits = &specs.LinuxResources{}
}
if s.ResourceLimits.Memory == nil {
s.ResourceLimits.Memory = &specs.LinuxMemory{}
}
- s.ResourceLimits.Memory.Swappiness = &swappiness
+ if c.MemorySwappiness >= 0 {
+ swappiness := uint64(c.MemorySwappiness)
+ s.ResourceLimits.Memory.Swappiness = &swappiness
+ }
if s.LogConfiguration == nil {
s.LogConfiguration = &specgen.LogConfig{}
@@ -332,7 +343,9 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
if s.ResourceLimits.Pids == nil {
s.ResourceLimits.Pids = &specs.LinuxPids{}
}
- s.ResourceLimits.Pids.Limit = c.PIDsLimit
+ if c.PIDsLimit > 0 {
+ s.ResourceLimits.Pids.Limit = c.PIDsLimit
+ }
if c.CGroups == "disabled" && c.PIDsLimit > 0 {
s.ResourceLimits.Pids.Limit = -1
}
@@ -507,18 +520,28 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
if s.ResourceLimits.CPU == nil {
s.ResourceLimits.CPU = &specs.LinuxCPU{}
}
- s.ResourceLimits.CPU.Shares = &c.CPUShares
- s.ResourceLimits.CPU.Period = &c.CPUPeriod
-
- // TODO research these
- //s.ResourceLimits.CPU.Cpus = c.CPUS
- //s.ResourceLimits.CPU.Cpus = c.CPUSetCPUs
+ if c.CPUShares > 0 {
+ s.ResourceLimits.CPU.Shares = &c.CPUShares
+ }
+ if c.CPUPeriod > 0 {
+ s.ResourceLimits.CPU.Period = &c.CPUPeriod
+ }
- //s.ResourceLimits.CPU. = c.CPUSetCPUs
- s.ResourceLimits.CPU.Mems = c.CPUSetMems
- s.ResourceLimits.CPU.Quota = &c.CPUQuota
- s.ResourceLimits.CPU.RealtimePeriod = &c.CPURTPeriod
- s.ResourceLimits.CPU.RealtimeRuntime = &c.CPURTRuntime
+ if c.CPUSetCPUs != "" {
+ s.ResourceLimits.CPU.Cpus = c.CPUSetCPUs
+ }
+ if c.CPUSetMems != "" {
+ s.ResourceLimits.CPU.Mems = c.CPUSetMems
+ }
+ if c.CPUQuota > 0 {
+ s.ResourceLimits.CPU.Quota = &c.CPUQuota
+ }
+ if c.CPURTPeriod > 0 {
+ s.ResourceLimits.CPU.RealtimePeriod = &c.CPURTPeriod
+ }
+ if c.CPURTRuntime > 0 {
+ s.ResourceLimits.CPU.RealtimeRuntime = &c.CPURTRuntime
+ }
s.OOMScoreAdj = &c.OOMScoreAdj
s.RestartPolicy = c.Restart
s.Remove = c.Rm