Skip to content

Commit

Permalink
specgen/generate: Factor out setting resource limits from CompleteSpec
Browse files Browse the repository at this point in the history
This avoids setting values in the spec which are not supported on
FreeBSD - including these values causes warning messages for the
unsupported features.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <[email protected]>
  • Loading branch information
dfr committed Sep 8, 2022
1 parent ac8c1e1 commit 911e4a1
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 911e4a1

Please sign in to comment.