Skip to content

Commit

Permalink
specgen: do not set OOMScoreAdj by default
Browse files Browse the repository at this point in the history
do not force a value of OOMScoreAdj=0 if it is wasn't specified by the
user.

It is a breaking change in the API, but it makes clearer that
OOMScoreAdj is an optional attribute and it is treated as such in the
backend.

Closes: containers#13731

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Apr 4, 2022
1 parent d1f3a2d commit 7955a64
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cmd/podman/common/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
)

oomScoreAdjFlagName := "oom-score-adj"
createFlags.IntVar(
&cf.OOMScoreAdj,
createFlags.Int64(
oomScoreAdjFlagName, 0,
"Tune the host's OOM preferences (-1000 to 1000)",
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/common/create_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,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: nil,
Arch: "",
OS: "",
Variant: "",
Expand Down
9 changes: 9 additions & 0 deletions cmd/podman/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra
vals.GroupAdd = groups
}

if c.Flags().Changed("oom-score-adj") {
val := c.Flag("oom-score-adj").Value.String()
v, err := strconv.ParseInt(val, 10, 32)
if err != nil {
return vals, err
}
oomScoreAdj := int(v)
vals.OOMScoreAdj = &oomScoreAdj
}
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
Expand Down
3 changes: 0 additions & 3 deletions hack/libsubid_tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ int main() {
return 0;
}
EOF
if test $? -eq 0 ; then
echo libsubid
fi
2 changes: 1 addition & 1 deletion pkg/domain/entities/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/specgenutil/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions
s.PreserveFDs = c.PreserveFDs
}

if s.OOMScoreAdj == nil || c.OOMScoreAdj != 0 {
s.OOMScoreAdj = &c.OOMScoreAdj
if s.OOMScoreAdj == nil || c.OOMScoreAdj != nil {
s.OOMScoreAdj = c.OOMScoreAdj
}
if c.Restart != "" {
splitRestart := strings.Split(c.Restart, ":")
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(currentOOMScoreAdj, "\n")))
})

It("podman run limits host test", func() {
Expand Down

0 comments on commit 7955a64

Please sign in to comment.