mirror of
https://github.com/containers/podman.git
synced 2025-06-22 18:08:11 +08:00
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>
This commit is contained in:
@ -348,8 +348,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
|
|||||||
)
|
)
|
||||||
|
|
||||||
oomScoreAdjFlagName := "oom-score-adj"
|
oomScoreAdjFlagName := "oom-score-adj"
|
||||||
createFlags.IntVar(
|
createFlags.Int(
|
||||||
&cf.OOMScoreAdj,
|
|
||||||
oomScoreAdjFlagName, 0,
|
oomScoreAdjFlagName, 0,
|
||||||
"Tune the host's OOM preferences (-1000 to 1000)",
|
"Tune the host's OOM preferences (-1000 to 1000)",
|
||||||
)
|
)
|
||||||
|
@ -286,7 +286,7 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c
|
|||||||
LogDriver: cc.HostConfig.LogConfig.Type,
|
LogDriver: cc.HostConfig.LogConfig.Type,
|
||||||
LogOptions: stringMaptoArray(cc.HostConfig.LogConfig.Config),
|
LogOptions: stringMaptoArray(cc.HostConfig.LogConfig.Config),
|
||||||
Name: cc.Name,
|
Name: cc.Name,
|
||||||
OOMScoreAdj: cc.HostConfig.OomScoreAdj,
|
OOMScoreAdj: &cc.HostConfig.OomScoreAdj,
|
||||||
Arch: "",
|
Arch: "",
|
||||||
OS: "",
|
OS: "",
|
||||||
Variant: "",
|
Variant: "",
|
||||||
|
@ -238,6 +238,13 @@ func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra
|
|||||||
vals.GroupAdd = groups
|
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") {
|
if c.Flags().Changed("pids-limit") {
|
||||||
val := c.Flag("pids-limit").Value.String()
|
val := c.Flag("pids-limit").Value.String()
|
||||||
// Convert -1 to 0, so that -1 maps to unlimited pids limit
|
// Convert -1 to 0, so that -1 maps to unlimited pids limit
|
||||||
|
@ -210,7 +210,7 @@ type ContainerCreateOptions struct {
|
|||||||
Name string `json:"container_name"`
|
Name string `json:"container_name"`
|
||||||
NoHealthCheck bool
|
NoHealthCheck bool
|
||||||
OOMKillDisable bool
|
OOMKillDisable bool
|
||||||
OOMScoreAdj int
|
OOMScoreAdj *int
|
||||||
Arch string
|
Arch string
|
||||||
OS string
|
OS string
|
||||||
Variant string
|
Variant string
|
||||||
|
@ -753,8 +753,8 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions
|
|||||||
s.PreserveFDs = c.PreserveFDs
|
s.PreserveFDs = c.PreserveFDs
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.OOMScoreAdj == nil || c.OOMScoreAdj != 0 {
|
if s.OOMScoreAdj == nil || c.OOMScoreAdj != nil {
|
||||||
s.OOMScoreAdj = &c.OOMScoreAdj
|
s.OOMScoreAdj = c.OOMScoreAdj
|
||||||
}
|
}
|
||||||
if c.Restart != "" {
|
if c.Restart != "" {
|
||||||
splitRestart := strings.Split(c.Restart, ":")
|
splitRestart := strings.Split(c.Restart, ":")
|
||||||
|
@ -609,6 +609,13 @@ USER bin`, BB)
|
|||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
Expect(session.OutputToString()).To(Equal("111"))
|
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() {
|
It("podman run limits host test", func() {
|
||||||
|
@ -815,4 +815,10 @@ EOF
|
|||||||
run_podman run --uidmap 0:10001:10002 --rm --hostname ${HOST} $IMAGE grep ${HOST} /etc/hosts
|
run_podman run --uidmap 0:10001:10002 --rm --hostname ${HOST} $IMAGE grep ${HOST} /etc/hosts
|
||||||
is "${lines[0]}" ".*${HOST}.*"
|
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
|
# vim: filetype=sh
|
||||||
|
Reference in New Issue
Block a user