Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In rootless + cgroupsv1, resource limits are an error #6837

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions pkg/domain/infra/abi/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os/exec"
"path/filepath"
"strconv"
"syscall"

"github.com/containers/common/pkg/config"
"github.com/containers/libpod/libpod/define"
Expand Down Expand Up @@ -146,32 +145,6 @@ func movePauseProcessToScope() error {
return utils.RunUnderSystemdScope(int(pid), "user.slice", "podman-pause.scope")
}

func setRLimits() error { // nolint:deadcode,unused
rlimits := new(syscall.Rlimit)
rlimits.Cur = 1048576
rlimits.Max = 1048576
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, rlimits); err != nil {
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, rlimits); err != nil {
return errors.Wrapf(err, "error getting rlimits")
}
rlimits.Cur = rlimits.Max
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, rlimits); err != nil {
return errors.Wrapf(err, "error setting new rlimits")
}
}
return nil
}

func setUMask() { // nolint:deadcode,unused
// Be sure we can create directories with 0755 mode.
syscall.Umask(0022)
}

// checkInput can be used to verify any of the globalopt values
func checkInput() error { // nolint:deadcode,unused
return nil
}

// SystemPrune removes unused data from the system. Pruning pods, containers, volumes and images.
func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.SystemPruneOptions) (*entities.SystemPruneReport, error) {
var systemPruneReport = new(entities.SystemPruneReport)
Expand Down
25 changes: 21 additions & 4 deletions pkg/specgen/generate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package generate
import (
"github.com/containers/common/pkg/sysinfo"
"github.com/containers/libpod/pkg/cgroups"
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/libpod/pkg/specgen"
"github.com/pkg/errors"
)
Expand All @@ -23,6 +24,25 @@ func verifyContainerResources(s *specgen.SpecGenerator) ([]string, error) {
return warnings, nil
}

if rootless.IsRootless() {
// Interpreting 0 as unset - remove any unset limits
if s.ResourceLimits.Pids != nil && s.ResourceLimits.Pids.Limit == 0 {
s.ResourceLimits.Pids = nil
}

// We are guaranteed to be cgroups v1 + rootless. Resource
// limits are not acceptable. But if everything is unset, we can
// just remove the block entirely.
if s.ResourceLimits.Memory == nil && s.ResourceLimits.Memory == nil &&
s.ResourceLimits.CPU == nil && s.ResourceLimits.BlockIO == nil &&
s.ResourceLimits.HugepageLimits == nil && s.ResourceLimits.Network == nil &&
s.ResourceLimits.Rdma == nil && s.ResourceLimits.Pids == nil {
s.ResourceLimits = nil
return warnings, nil
}
return warnings, errors.New("resource limits cannot be set for rootless containers in cgroups v1 mode")
}

// Memory checks
if s.ResourceLimits.Memory != nil {
memory := s.ResourceLimits.Memory
Expand Down Expand Up @@ -70,10 +90,7 @@ func verifyContainerResources(s *specgen.SpecGenerator) ([]string, error) {

// Pids checks
if s.ResourceLimits.Pids != nil {
pids := s.ResourceLimits.Pids
// TODO: Should this be 0, or checking that ResourceLimits.Pids
// is set at all?
if pids.Limit > 0 && !sysInfo.PidsLimit {
if !sysInfo.PidsLimit {
warnings = append(warnings, "Your kernel does not support pids limit capabilities or the cgroup is not mounted. PIDs limit discarded.")
s.ResourceLimits.Pids = nil
}
Expand Down