Skip to content

Commit

Permalink
Merge pull request containers#15667 from dfr/freebsd-specgen
Browse files Browse the repository at this point in the history
specgen/generate: Factor out setting resource limits from CompleteSpec
  • Loading branch information
openshift-merge-robot authored Sep 8, 2022
2 parents d117d08 + 911e4a1 commit 95eff1a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
15 changes: 1 addition & 14 deletions pkg/specgen/generate/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
envLib "github.com/containers/podman/v4/pkg/env"
"github.com/containers/podman/v4/pkg/signal"
"github.com/containers/podman/v4/pkg/specgen"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/openshift/imagebuilder"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -272,19 +271,7 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
}

// If caller did not specify Pids Limits load default
if s.ResourceLimits == nil || s.ResourceLimits.Pids == nil {
if s.CgroupsMode != "disabled" {
limit := rtc.PidsLimit()
if limit != 0 {
if s.ResourceLimits == nil {
s.ResourceLimits = &spec.LinuxResources{}
}
s.ResourceLimits.Pids = &spec.LinuxPids{
Limit: limit,
}
}
}
}
s.InitResourceLimits(rtc)

if s.LogConfiguration == nil {
s.LogConfiguration = &specgen.LogConfig{}
Expand Down
8 changes: 8 additions & 0 deletions pkg/specgen/resources_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package specgen

import (
"github.com/containers/common/pkg/config"
)

func (s *SpecGenerator) InitResourceLimits(rtc *config.Config) {
}
22 changes: 22 additions & 0 deletions pkg/specgen/resources_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package specgen

import (
"github.com/containers/common/pkg/config"
spec "github.com/opencontainers/runtime-spec/specs-go"
)

func (s *SpecGenerator) InitResourceLimits(rtc *config.Config) {
if s.ResourceLimits == nil || s.ResourceLimits.Pids == nil {
if s.CgroupsMode != "disabled" {
limit := rtc.PidsLimit()
if limit != 0 {
if s.ResourceLimits == nil {
s.ResourceLimits = &spec.LinuxResources{}
}
s.ResourceLimits.Pids = &spec.LinuxPids{
Limit: limit,
}
}
}
}
}

0 comments on commit 95eff1a

Please sign in to comment.