Skip to content

Commit 5caf782

Browse files
author
Ma Shimiao
committed
generate: add OOM Killer disable support
Signed-off-by: Ma Shimiao <[email protected]>
1 parent 96609ba commit 5caf782

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

cmd/oci-runtime-tool/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.BoolFlag{Name: "disable-oom-kill", Usage: "disable OOM Killer"},
6162
cli.IntFlag{Name: "oom-score-adj", Usage: "oom_score_adj for the container"},
6263
cli.Uint64Flag{Name: "linux-cpu-shares", Usage: "the relative share of CPU time available to the tasks in a cgroup"},
6364
cli.Uint64Flag{Name: "linux-cpu-period", Usage: "the CPU period to be used for hardcapping (in usecs)"},
@@ -333,6 +334,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
333334
g.AddLinuxGIDMapping(hid, cid, size)
334335
}
335336

337+
if context.IsSet("disable-oom-kill") {
338+
g.SetLinuxResourcesDisableOOMKiller(context.Bool("disable-oom-kill"))
339+
}
340+
336341
if context.IsSet("oom-score-adj") {
337342
g.SetLinuxResourcesOOMScoreAdj(context.Int("oom-score-adj"))
338343
}

completions/bash/oci-runtime-tool

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ _oci-runtime-tool_generate() {
277277
--cgroup
278278
--cgroup-path
279279
--cwd
280+
--disable-oom-kill
280281
--env
281282
--gid
282283
--gidmappings

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+
// SetLinuxResourcesDisableOOMKiller sets g.spec.Linux.Resources.DisableOOMKiller.
366+
func (g *Generator) SetLinuxResourcesDisableOOMKiller(disable bool) {
367+
g.initSpecLinuxResources()
368+
g.spec.Linux.Resources.DisableOOMKiller = &disable
369+
}
370+
365371
// SetLinuxResourcesOOMScoreAdj sets g.spec.Linux.Resources.OOMScoreAdj.
366372
func (g *Generator) SetLinuxResourcesOOMScoreAdj(adj int) {
367373
g.initSpecLinuxResources()

man/oci-runtime-tool-generate.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ read the configuration from `config.json`.
5757
**--cwd**=PATH
5858
Current working directory for the process
5959

60+
**--disable-oom-kill**=true|false
61+
Whether to disable OOM Killer for the container or not.
62+
6063
**--env**=[]
6164
Set environment variables e.g. key=value.
6265
This option allows you to specify arbitrary environment variables

0 commit comments

Comments
 (0)