diff --git a/cmd/oci-runtime-tool/generate.go b/cmd/oci-runtime-tool/generate.go index c47b940c0..6c2fe5c1c 100644 --- a/cmd/oci-runtime-tool/generate.go +++ b/cmd/oci-runtime-tool/generate.go @@ -58,6 +58,7 @@ var generateFlags = []cli.Flag{ cli.StringSliceFlag{Name: "seccomp-errno", Usage: "specifies syscalls to be added to list that returns an error"}, cli.StringFlag{Name: "template", Usage: "base template to use for creating the configuration"}, cli.StringSliceFlag{Name: "label", Usage: "add annotations to the configuration e.g. key=value"}, + cli.BoolFlag{Name: "disable-oom-kill", Usage: "disable OOM Killer"}, cli.IntFlag{Name: "oom-score-adj", Usage: "oom_score_adj for the container"}, cli.Uint64Flag{Name: "linux-cpu-shares", Usage: "the relative share of CPU time available to the tasks in a cgroup"}, 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 { g.AddLinuxGIDMapping(hid, cid, size) } + if context.IsSet("disable-oom-kill") { + g.SetLinuxResourcesDisableOOMKiller(context.Bool("disable-oom-kill")) + } + if context.IsSet("oom-score-adj") { g.SetLinuxResourcesOOMScoreAdj(context.Int("oom-score-adj")) } diff --git a/completions/bash/oci-runtime-tool b/completions/bash/oci-runtime-tool index 6654bf773..815459f54 100644 --- a/completions/bash/oci-runtime-tool +++ b/completions/bash/oci-runtime-tool @@ -277,6 +277,7 @@ _oci-runtime-tool_generate() { --cgroup --cgroup-path --cwd + --disable-oom-kill --env --gid --gidmappings diff --git a/generate/generate.go b/generate/generate.go index d101799ab..7cdf3a553 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -362,6 +362,12 @@ func (g *Generator) SetLinuxMountLabel(label string) { g.spec.Linux.MountLabel = label } +// SetLinuxResourcesDisableOOMKiller sets g.spec.Linux.Resources.DisableOOMKiller. +func (g *Generator) SetLinuxResourcesDisableOOMKiller(disable bool) { + g.initSpecLinuxResources() + g.spec.Linux.Resources.DisableOOMKiller = &disable +} + // SetLinuxResourcesOOMScoreAdj sets g.spec.Linux.Resources.OOMScoreAdj. func (g *Generator) SetLinuxResourcesOOMScoreAdj(adj int) { g.initSpecLinuxResources() diff --git a/man/oci-runtime-tool-generate.1.md b/man/oci-runtime-tool-generate.1.md index 205dbbe8a..09bd61b9e 100644 --- a/man/oci-runtime-tool-generate.1.md +++ b/man/oci-runtime-tool-generate.1.md @@ -57,6 +57,9 @@ read the configuration from `config.json`. **--cwd**=PATH Current working directory for the process +**--disable-oom-kill**=true|false + Whether to disable OOM Killer for the container or not. + **--env**=[] Set environment variables e.g. key=value. This option allows you to specify arbitrary environment variables