Skip to content

Commit ea1d5dd

Browse files
author
Mrunal Patel
authored
Merge pull request opencontainers#185 from wking/set-oom_score_adj
[1.0.0.rc1] support setting oom_score_adj
2 parents 52c9e15 + de97cc8 commit ea1d5dd

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

cmd/ocitools/generate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var generateFlags = []cli.Flag{
5858
cli.StringSliceFlag{Name: "seccomp-errno", Usage: "specifies syscalls to be added to list that returns an error"},
5959
cli.StringFlag{Name: "template", Usage: "base template to use for creating the configuration"},
6060
cli.StringSliceFlag{Name: "label", Usage: "add annotations to the configuration e.g. key=value"},
61+
cli.IntFlag{Name: "oom-score-adj", Usage: "oom_score_adj for the container"},
6162
}
6263

6364
var generateCommand = cli.Command{
@@ -319,6 +320,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
319320
g.AddLinuxGIDMapping(hid, cid, size)
320321
}
321322

323+
if context.IsSet("oom-score-adj") {
324+
g.SetLinuxResourcesOOMScoreAdj(context.Int("oom-score-adj"))
325+
}
326+
322327
var sd string
323328
var sa, ss []string
324329

generate/generate.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ func (g *Generator) SetLinuxMountLabel(label string) {
358358
g.spec.Linux.MountLabel = label
359359
}
360360

361+
// SetLinuxResourcesOOMScoreAdj sets g.spec.Linux.Resources.OOMScoreAdj.
362+
func (g *Generator) SetLinuxResourcesOOMScoreAdj(adj int) {
363+
g.initSpecLinuxResources()
364+
g.spec.Linux.Resources.OOMScoreAdj = &adj
365+
}
366+
361367
// SetLinuxResourcesCPUShares sets g.spec.Linux.Resources.CPU.Shares.
362368
func (g *Generator) SetLinuxResourcesCPUShares(shares uint64) {
363369
g.initSpecLinuxResourcesCPU()

man/ocitools-generate.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ inside of the container.
117117
using tools like setuid apps. It is a good idea to run unprivileged
118118
containers with this flag.
119119

120+
**--oom-score-adj**=adj
121+
Specifies oom_score_adj for the container.
122+
120123
**--output**=PATH
121124
Instead of writing the configuration JSON to stdout, write it to a
122125
file at *PATH* (overwriting the existing content if a file already

0 commit comments

Comments
 (0)