118a72cb93
OBS-URL: https://build.opensuse.org/request/show/967493 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/podman?expand=0&rev=92
130 lines
4.8 KiB
Diff
130 lines
4.8 KiB
Diff
From a8d92cf8540d4983934ba8f258a403de81af930d Mon Sep 17 00:00:00 2001
|
|
From: Giuseppe Scrivano <gscrivan@redhat.com>
|
|
Date: Mon, 4 Apr 2022 13:14:35 +0200
|
|
Subject: [PATCH 2/2] specgen: do not set OOMScoreAdj by default
|
|
|
|
do not force a value of OOMScoreAdj=0 if it is wasn't specified by the
|
|
user.
|
|
|
|
Closes: https://github.com/containers/podman/issues/13731
|
|
|
|
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
|
|
(cherry picked from commit 164b64ea3baa8502a23fc0c7674f4a7e60507aa0)
|
|
---
|
|
cmd/podman/common/create.go | 3 +--
|
|
cmd/podman/common/create_opts.go | 2 +-
|
|
cmd/podman/containers/create.go | 7 +++++++
|
|
pkg/domain/entities/pods.go | 2 +-
|
|
pkg/specgenutil/specgen.go | 2 +-
|
|
test/e2e/run_test.go | 7 +++++++
|
|
test/system/030-run.bats | 6 ++++++
|
|
7 files changed, 24 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go
|
|
index 1121806d5..e7d073226 100644
|
|
--- a/cmd/podman/common/create.go
|
|
+++ b/cmd/podman/common/create.go
|
|
@@ -402,8 +402,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
|
|
)
|
|
|
|
oomScoreAdjFlagName := "oom-score-adj"
|
|
- createFlags.IntVar(
|
|
- &cf.OOMScoreAdj,
|
|
+ createFlags.Int(
|
|
oomScoreAdjFlagName, 0,
|
|
"Tune the host's OOM preferences (-1000 to 1000)",
|
|
)
|
|
diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go
|
|
index b110b3d85..6c985cb60 100644
|
|
--- a/cmd/podman/common/create_opts.go
|
|
+++ b/cmd/podman/common/create_opts.go
|
|
@@ -277,7 +277,7 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c
|
|
LogDriver: cc.HostConfig.LogConfig.Type,
|
|
LogOptions: stringMaptoArray(cc.HostConfig.LogConfig.Config),
|
|
Name: cc.Name,
|
|
- OOMScoreAdj: cc.HostConfig.OomScoreAdj,
|
|
+ OOMScoreAdj: &cc.HostConfig.OomScoreAdj,
|
|
Arch: "",
|
|
OS: "",
|
|
Variant: "",
|
|
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go
|
|
index 89d2e5515..1f3331272 100644
|
|
--- a/cmd/podman/containers/create.go
|
|
+++ b/cmd/podman/containers/create.go
|
|
@@ -238,6 +238,13 @@ func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra
|
|
vals.GroupAdd = groups
|
|
}
|
|
|
|
+ if c.Flags().Changed("oom-score-adj") {
|
|
+ val, err := c.Flags().GetInt("oom-score-adj")
|
|
+ if err != nil {
|
|
+ return vals, err
|
|
+ }
|
|
+ vals.OOMScoreAdj = &val
|
|
+ }
|
|
if c.Flags().Changed("pids-limit") {
|
|
val := c.Flag("pids-limit").Value.String()
|
|
// Convert -1 to 0, so that -1 maps to unlimited pids limit
|
|
diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go
|
|
index 7922db4e6..cb6132e26 100644
|
|
--- a/pkg/domain/entities/pods.go
|
|
+++ b/pkg/domain/entities/pods.go
|
|
@@ -210,7 +210,7 @@ type ContainerCreateOptions struct {
|
|
Name string `json:"container_name"`
|
|
NoHealthCheck bool
|
|
OOMKillDisable bool
|
|
- OOMScoreAdj int
|
|
+ OOMScoreAdj *int
|
|
Arch string
|
|
OS string
|
|
Variant string
|
|
diff --git a/pkg/specgenutil/specgen.go b/pkg/specgenutil/specgen.go
|
|
index 17699a038..260d78913 100644
|
|
--- a/pkg/specgenutil/specgen.go
|
|
+++ b/pkg/specgenutil/specgen.go
|
|
@@ -660,7 +660,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions
|
|
s.Name = c.Name
|
|
s.PreserveFDs = c.PreserveFDs
|
|
|
|
- s.OOMScoreAdj = &c.OOMScoreAdj
|
|
+ s.OOMScoreAdj = c.OOMScoreAdj
|
|
if c.Restart != "" {
|
|
splitRestart := strings.Split(c.Restart, ":")
|
|
switch len(splitRestart) {
|
|
diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go
|
|
index 81dcc4342..d772cbc21 100644
|
|
--- a/test/e2e/run_test.go
|
|
+++ b/test/e2e/run_test.go
|
|
@@ -609,6 +609,13 @@ USER bin`, BB)
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(Exit(0))
|
|
Expect(session.OutputToString()).To(Equal("111"))
|
|
+
|
|
+ currentOOMScoreAdj, err := ioutil.ReadFile("/proc/self/oom_score_adj")
|
|
+ Expect(err).To(BeNil())
|
|
+ session = podmanTest.Podman([]string{"run", "--rm", fedoraMinimal, "cat", "/proc/self/oom_score_adj"})
|
|
+ session.WaitWithDefaultTimeout()
|
|
+ Expect(session).Should(Exit(0))
|
|
+ Expect(session.OutputToString()).To(Equal(strings.TrimRight(string(currentOOMScoreAdj), "\n")))
|
|
})
|
|
|
|
It("podman run limits host test", func() {
|
|
diff --git a/test/system/030-run.bats b/test/system/030-run.bats
|
|
index ec85ef166..72e4a2bc8 100644
|
|
--- a/test/system/030-run.bats
|
|
+++ b/test/system/030-run.bats
|
|
@@ -815,4 +815,10 @@ EOF
|
|
run_podman run --uidmap 0:10001:10002 --rm --hostname ${HOST} $IMAGE grep ${HOST} /etc/hosts
|
|
is "${lines[0]}" ".*${HOST}.*"
|
|
}
|
|
+
|
|
+@test "podman run doesn't override oom-score-adj" {
|
|
+ current_oom_score_adj=$(cat /proc/self/oom_score_adj)
|
|
+ run_podman run --rm $IMAGE cat /proc/self/oom_score_adj
|
|
+ is "$output" "$current_oom_score_adj" "different oom_score_adj in the container"
|
|
+}
|
|
# vim: filetype=sh
|
|
--
|
|
2.35.1
|
|
|