Skip to content

Commit

Permalink
virtcontainers: inherit parent's CPU constraint
Browse files Browse the repository at this point in the history
Don't set a default CPU constraint if period and quota are not specified, that
way the container will inherit the CPU constraint from its parent. Container
creation won't fail if the parent CPU constraint is smaller than the default
number of vCPUs.

fixes kata-containers#1521

Signed-off-by: Julio Montes <[email protected]>
(cherry picked from commit 59e3956)
Signed-off-by: Ganesh Maharaj Mahalingam <[email protected]>
  • Loading branch information
Julio Montes authored and Ganesh Maharaj Mahalingam committed Apr 30, 2019
1 parent 14214a4 commit 1ece800
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions virtcontainers/cgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ func (s *Sandbox) resources() (specs.LinuxResources, error) {
}

func (s *Sandbox) cpuResources() *specs.LinuxCPU {
// Use default period and quota if they are not specified.
// Container will inherit the constraints from its parent.
quota := int64(0)
period := uint64(0)
shares := uint64(0)
Expand Down Expand Up @@ -322,13 +324,6 @@ func (s *Sandbox) cpuResources() *specs.LinuxCPU {

cpu.Cpus = strings.Trim(cpu.Cpus, " \n\t,")

// use a default constraint for sandboxes without cpu constraints
if period == uint64(0) && quota == int64(0) {
// set a quota and period equal to the default number of vcpus
quota = int64(s.config.HypervisorConfig.NumVCPUs) * 100000
period = 100000
}

return validCPUResources(cpu)
}

Expand Down

0 comments on commit 1ece800

Please sign in to comment.