diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-06-23 15:51:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-23 15:51:29 -0400 |
commit | 3f3feaa015af6e0831daf039f1cd5a0cba3de6c2 (patch) | |
tree | 0bc3c003a0546e89006159030f35031931a832fd /pkg/domain | |
parent | b0a3ac35785fca1a054d236937c86cce85631585 (diff) | |
parent | bbd085ad1e3cf9c5b543c907ad7014ccf8a5cb34 (diff) | |
download | podman-3f3feaa015af6e0831daf039f1cd5a0cba3de6c2.tar.gz podman-3f3feaa015af6e0831daf039f1cd5a0cba3de6c2.tar.bz2 podman-3f3feaa015af6e0831daf039f1cd5a0cba3de6c2.zip |
Merge pull request #10716 from cdoern/podFlags
Podman Pod Create --cpus and --cpuset-cpus flags
Diffstat (limited to 'pkg/domain')
-rw-r--r-- | pkg/domain/entities/pods.go | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go index 88055454f..35f940bca 100644 --- a/pkg/domain/entities/pods.go +++ b/pkg/domain/entities/pods.go @@ -7,6 +7,8 @@ import ( "github.com/containers/podman/v3/libpod/define" "github.com/containers/podman/v3/pkg/specgen" + "github.com/containers/podman/v3/pkg/util" + "github.com/opencontainers/runtime-spec/specs-go" ) type PodKillOptions struct { @@ -116,13 +118,35 @@ type PodCreateOptions struct { Name string Net *NetOptions Share []string + Cpus float64 + CpusetCpus string } type PodCreateReport struct { Id string //nolint } -func (p PodCreateOptions) ToPodSpecGen(s *specgen.PodSpecGenerator) { +func (p *PodCreateOptions) CPULimits() *specs.LinuxCPU { + cpu := &specs.LinuxCPU{} + hasLimits := false + + if p.Cpus != 0 { + period, quota := util.CoresToPeriodAndQuota(p.Cpus) + cpu.Period = &period + cpu.Quota = "a + hasLimits = true + } + if p.CpusetCpus != "" { + cpu.Cpus = p.CpusetCpus + hasLimits = true + } + if !hasLimits { + return cpu + } + return cpu +} + +func (p *PodCreateOptions) ToPodSpecGen(s *specgen.PodSpecGenerator) error { // Basic Config s.Name = p.Name s.Hostname = p.Hostname @@ -156,6 +180,21 @@ func (p PodCreateOptions) ToPodSpecGen(s *specgen.PodSpecGenerator) { // Cgroup s.CgroupParent = p.CGroupParent + + // Resource config + cpuDat := p.CPULimits() + if s.ResourceLimits == nil { + s.ResourceLimits = &specs.LinuxResources{} + s.ResourceLimits.CPU = &specs.LinuxCPU{} + } + if cpuDat != nil { + s.ResourceLimits.CPU = cpuDat + if p.Cpus != 0 { + s.CPUPeriod = *cpuDat.Period + s.CPUQuota = *cpuDat.Quota + } + } + return nil } type PodPruneOptions struct { |