summaryrefslogtreecommitdiff
path: root/pkg/specgen/generate/pod_create.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-07-21 23:01:03 +0200
committerGitHub <noreply@github.com>2022-07-21 23:01:03 +0200
commitee937c518e7efb9c47d21a4e1050b966ca02d005 (patch)
tree2cd2dfd0bcd1332a187f9cb66eff51a9591c4069 /pkg/specgen/generate/pod_create.go
parent34b2018cfc75772e89367614852c382ac47d3ec1 (diff)
parentc00ea686fef5a382849307d393226971fb1da1f3 (diff)
downloadpodman-ee937c518e7efb9c47d21a4e1050b966ca02d005.tar.gz
podman-ee937c518e7efb9c47d21a4e1050b966ca02d005.tar.bz2
podman-ee937c518e7efb9c47d21a4e1050b966ca02d005.zip
Merge pull request #14876 from cdoern/cgroup
resource limits for pods
Diffstat (limited to 'pkg/specgen/generate/pod_create.go')
-rw-r--r--pkg/specgen/generate/pod_create.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/pkg/specgen/generate/pod_create.go b/pkg/specgen/generate/pod_create.go
index 212d613fe..4e6362c9b 100644
--- a/pkg/specgen/generate/pod_create.go
+++ b/pkg/specgen/generate/pod_create.go
@@ -13,6 +13,7 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/specgen"
"github.com/containers/podman/v4/pkg/specgenutil"
+ "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)
@@ -21,6 +22,10 @@ func MakePod(p *entities.PodSpec, rt *libpod.Runtime) (*libpod.Pod, error) {
return nil, err
}
+ if p.PodSpecGen.ResourceLimits == nil {
+ p.PodSpecGen.ResourceLimits = &specs.LinuxResources{}
+ }
+
if !p.PodSpecGen.NoInfra {
imageName, err := PullOrBuildInfraImage(rt, p.PodSpecGen.InfraImage)
if err != nil {
@@ -38,10 +43,33 @@ func MakePod(p *entities.PodSpec, rt *libpod.Runtime) (*libpod.Pod, error) {
}
}
+ if !p.PodSpecGen.NoInfra {
+ err := FinishThrottleDevices(p.PodSpecGen.InfraContainerSpec)
+ if err != nil {
+ return nil, err
+ }
+ if p.PodSpecGen.InfraContainerSpec.ResourceLimits.BlockIO != nil {
+ p.PodSpecGen.ResourceLimits.BlockIO = p.PodSpecGen.InfraContainerSpec.ResourceLimits.BlockIO
+ }
+
+ weightDevices, err := WeightDevices(p.PodSpecGen.InfraContainerSpec.WeightDevice)
+ if err != nil {
+ return nil, err
+ }
+
+ if p.PodSpecGen.ResourceLimits != nil && len(weightDevices) > 0 {
+ if p.PodSpecGen.ResourceLimits.BlockIO == nil {
+ p.PodSpecGen.ResourceLimits.BlockIO = &specs.LinuxBlockIO{}
+ }
+ p.PodSpecGen.ResourceLimits.BlockIO.WeightDevice = weightDevices
+ }
+ }
+
options, err := createPodOptions(&p.PodSpecGen)
if err != nil {
return nil, err
}
+
pod, err := rt.NewPod(context.Background(), p.PodSpecGen, options...)
if err != nil {
return nil, err
@@ -55,6 +83,11 @@ func MakePod(p *entities.PodSpec, rt *libpod.Runtime) (*libpod.Pod, error) {
return nil, err
}
p.PodSpecGen.InfraContainerSpec.User = "" // infraSpec user will get incorrectly assigned via the container creation process, overwrite here
+ // infra's resource limits are used as a parsing tool,
+ // we do not want infra to get these resources in its cgroup
+ // make sure of that here.
+ p.PodSpecGen.InfraContainerSpec.ResourceLimits = nil
+ p.PodSpecGen.InfraContainerSpec.WeightDevice = nil
rtSpec, spec, opts, err := MakeContainer(context.Background(), rt, p.PodSpecGen.InfraContainerSpec, false, nil)
if err != nil {
return nil, err
@@ -122,6 +155,10 @@ func createPodOptions(p *specgen.PodSpecGenerator) ([]libpod.PodCreateOption, er
options = append(options, libpod.WithPodHostname(p.Hostname))
}
+ if p.ResourceLimits != nil {
+ options = append(options, libpod.WithPodResources(*p.ResourceLimits))
+ }
+
options = append(options, libpod.WithPodExitPolicy(p.ExitPolicy))
return options, nil