Skip to content

Commit 03e8b89

Browse files
author
Mrunal Patel
authored
Merge pull request #176 from hmeng-19/set_oom_score_adj
support setting oom_score_adj
2 parents 40d0f78 + 1915407 commit 03e8b89

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
@@ -362,6 +362,12 @@ func (g *Generator) SetLinuxMountLabel(label string) {
362362
g.spec.Linux.MountLabel = label
363363
}
364364

365+
// SetLinuxResourcesOOMScoreAdj sets g.spec.Linux.Resources.OOMScoreAdj.
366+
func (g *Generator) SetLinuxResourcesOOMScoreAdj(adj int) {
367+
g.initSpecLinuxResources()
368+
g.spec.Linux.Resources.OOMScoreAdj = &adj
369+
}
370+
365371
// SetLinuxResourcesCPUShares sets g.spec.Linux.Resources.CPU.Shares.
366372
func (g *Generator) SetLinuxResourcesCPUShares(shares uint64) {
367373
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)