summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorcdoern <cbdoer23@g.holycross.edu>2021-06-17 17:36:35 -0400
committercdoern <cbdoer23@g.holycross.edu>2021-06-23 13:47:57 -0400
commitbbd085ad1e3cf9c5b543c907ad7014ccf8a5cb34 (patch)
tree14dd2d240f32586a624f6a786d8127b8bfb95017 /pkg
parent510509bafcdd055b4a6819ed300db7292c6fb6b8 (diff)
downloadpodman-bbd085ad1e3cf9c5b543c907ad7014ccf8a5cb34.tar.gz
podman-bbd085ad1e3cf9c5b543c907ad7014ccf8a5cb34.tar.bz2
podman-bbd085ad1e3cf9c5b543c907ad7014ccf8a5cb34.zip
Podman Pod Create --cpus and --cpuset-cpus flags
Added logic and handling for two new Podman pod create Flags. --cpus specifies the total number of cores on which the pod can execute, this is a combination of the period and quota for the CPU. --cpuset-cpus is a string value which determines of these available cores, how many we will truly execute on. Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/domain/entities/pods.go41
-rw-r--r--pkg/specgen/generate/container_create.go1
-rw-r--r--pkg/specgen/generate/pod_create.go8
-rw-r--r--pkg/specgen/podspecgen.go12
-rw-r--r--pkg/specgen/specgen.go4
5 files changed, 64 insertions, 2 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 = &quota
+ 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 {
diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go
index a0f5cc7e6..b569f8390 100644
--- a/pkg/specgen/generate/container_create.go
+++ b/pkg/specgen/generate/container_create.go
@@ -346,7 +346,6 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen.
options = append(options, libpod.WithLogDriver(s.LogConfiguration.Driver))
}
}
-
// Security options
if len(s.SelinuxOpts) > 0 {
options = append(options, libpod.WithSecLabels(s.SelinuxOpts))
diff --git a/pkg/specgen/generate/pod_create.go b/pkg/specgen/generate/pod_create.go
index 07c56b799..023ebb41e 100644
--- a/pkg/specgen/generate/pod_create.go
+++ b/pkg/specgen/generate/pod_create.go
@@ -54,6 +54,14 @@ func createPodOptions(p *specgen.PodSpecGenerator, rt *libpod.Runtime) ([]libpod
if len(p.Name) > 0 {
options = append(options, libpod.WithPodName(p.Name))
}
+ if p.ResourceLimits != nil && p.ResourceLimits.CPU != nil && p.ResourceLimits.CPU.Period != nil && p.ResourceLimits.CPU.Quota != nil {
+ if *p.ResourceLimits.CPU.Period != 0 || *p.ResourceLimits.CPU.Quota != 0 {
+ options = append(options, libpod.WithPodCPUPAQ((*p.ResourceLimits.CPU.Period), (*p.ResourceLimits.CPU.Quota)))
+ }
+ }
+ if p.ResourceLimits != nil && p.ResourceLimits.CPU != nil && p.ResourceLimits.CPU.Cpus != "" {
+ options = append(options, libpod.WithPodCPUSetCPUs(p.ResourceLimits.CPU.Cpus))
+ }
if len(p.Hostname) > 0 {
options = append(options, libpod.WithPodHostname(p.Hostname))
}
diff --git a/pkg/specgen/podspecgen.go b/pkg/specgen/podspecgen.go
index 7d771f5bb..000a787ea 100644
--- a/pkg/specgen/podspecgen.go
+++ b/pkg/specgen/podspecgen.go
@@ -2,6 +2,8 @@ package specgen
import (
"net"
+
+ spec "github.com/opencontainers/runtime-spec/specs-go"
)
// PodBasicConfig contains basic configuration options for pods.
@@ -155,6 +157,16 @@ type PodSpecGenerator struct {
PodBasicConfig
PodNetworkConfig
PodCgroupConfig
+ PodResourceConfig
+}
+
+type PodResourceConfig struct {
+ // ResourceLimits contains linux specific CPU data for the pod
+ ResourceLimits *spec.LinuxResources `json:"resource_limits,omitempty"`
+ // CPU period of the cpuset, determined by --cpus
+ CPUPeriod uint64 `json:"cpu_period,omitempty"`
+ // CPU quota of the cpuset, determined by --cpus
+ CPUQuota int64 `json:"cpu_quota,omitempty"`
}
// NewPodSpecGenerator creates a new pod spec
diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go
index 2815bdebb..c5cc726d7 100644
--- a/pkg/specgen/specgen.go
+++ b/pkg/specgen/specgen.go
@@ -470,6 +470,10 @@ type ContainerResourceConfig struct {
// that are used to configure cgroup v2.
// Optional.
CgroupConf map[string]string `json:"unified,omitempty"`
+ // CPU period of the cpuset, determined by --cpus
+ CPUPeriod uint64 `json:"cpu_period,omitempty"`
+ // CPU quota of the cpuset, determined by --cpus
+ CPUQuota int64 `json:"cpu_quota,omitempty"`
}
// ContainerHealthCheckConfig describes a container healthcheck with attributes