diff --git a/cmd/ocitools/generate.go b/cmd/ocitools/generate.go index e036cbf74..05e7a8dfb 100644 --- a/cmd/ocitools/generate.go +++ b/cmd/ocitools/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.IntFlag{Name: "oom-score-adj", Usage: "oom_score_adj for the container"}, } var generateCommand = cli.Command{ @@ -319,6 +320,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error { g.AddLinuxGIDMapping(hid, cid, size) } + if context.IsSet("oom-score-adj") { + g.SetLinuxResourcesOOMScoreAdj(context.Int("oom-score-adj")) + } + var sd string var sa, ss []string diff --git a/generate/generate.go b/generate/generate.go index 1cc1b51e5..10c7667ca 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -358,6 +358,12 @@ func (g *Generator) SetLinuxMountLabel(label string) { g.spec.Linux.MountLabel = label } +// SetLinuxResourcesOOMScoreAdj sets g.spec.Linux.Resources.OOMScoreAdj. +func (g *Generator) SetLinuxResourcesOOMScoreAdj(adj int) { + g.initSpecLinuxResources() + g.spec.Linux.Resources.OOMScoreAdj = &adj +} + // SetLinuxResourcesCPUShares sets g.spec.Linux.Resources.CPU.Shares. func (g *Generator) SetLinuxResourcesCPUShares(shares uint64) { g.initSpecLinuxResourcesCPU() diff --git a/man/ocitools-generate.1.md b/man/ocitools-generate.1.md index 16b7ceea1..3e7fedce4 100644 --- a/man/ocitools-generate.1.md +++ b/man/ocitools-generate.1.md @@ -117,6 +117,9 @@ inside of the container. using tools like setuid apps. It is a good idea to run unprivileged containers with this flag. +**--oom-score-adj**=adj + Specifies oom_score_adj for the container. + **--output**=PATH Instead of writing the configuration JSON to stdout, write it to a file at *PATH* (overwriting the existing content if a file already