diff --git a/cmd/oci-runtime-tool/generate.go b/cmd/oci-runtime-tool/generate.go index c47b940c0..282b7b22e 100644 --- a/cmd/oci-runtime-tool/generate.go +++ b/cmd/oci-runtime-tool/generate.go @@ -72,6 +72,7 @@ var generateFlags = []cli.Flag{ cli.Uint64Flag{Name: "linux-mem-kernel-limit", Usage: "kernel memory limit (in bytes)"}, cli.Uint64Flag{Name: "linux-mem-kernel-tcp", Usage: "kernel memory limit for tcp (in bytes)"}, cli.Uint64Flag{Name: "linux-mem-swappiness", Usage: "how aggressive the kernel will swap memory pages (Range from 0 to 100)"}, + cli.Int64Flag{Name: "linux-pids-limit", Usage: "maximum number of PIDs"}, } var generateCommand = cli.Command{ @@ -389,6 +390,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error { g.SetLinuxResourcesMemorySwappiness(context.Uint64("linux-mem-swappiness")) } + if context.IsSet("linux-pids-limit") { + g.SetLinuxResourcesPidsLimit(context.Int64("linux-pids-limit")) + } + var sd string var sa, ss []string diff --git a/completions/bash/oci-runtime-tool b/completions/bash/oci-runtime-tool index 6654bf773..94638f307 100644 --- a/completions/bash/oci-runtime-tool +++ b/completions/bash/oci-runtime-tool @@ -285,6 +285,7 @@ _oci-runtime-tool_generate() { --help --ipc --label + --linux-pids-limit --mount --mount-cgroups --mount-label diff --git a/generate/generate.go b/generate/generate.go index d101799ab..e08edffb5 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -446,6 +446,12 @@ func (g *Generator) SetLinuxResourcesMemorySwappiness(swappiness uint64) { g.spec.Linux.Resources.Memory.Swappiness = &swappiness } +// SetLinuxResourcesPidsLimit sets g.spec.Linux.Resources.Pids.Limit. +func (g *Generator) SetLinuxResourcesPidsLimit(limit int64) { + g.initSpecLinuxResourcesPids() + g.spec.Linux.Resources.Pids.Limit = &limit +} + // ClearLinuxSysctl clears g.spec.Linux.Sysctl. func (g *Generator) ClearLinuxSysctl() { if g.spec == nil || g.spec.Linux == nil { diff --git a/generate/spec.go b/generate/spec.go index 4833ffd17..5711699c5 100644 --- a/generate/spec.go +++ b/generate/spec.go @@ -58,3 +58,10 @@ func (g *Generator) initSpecLinuxResourcesMemory() { g.spec.Linux.Resources.Memory = &rspec.Memory{} } } + +func (g *Generator) initSpecLinuxResourcesPids() { + g.initSpecLinuxResources() + if g.spec.Linux.Resources.Pids == nil { + g.spec.Linux.Resources.Pids = &rspec.Pids{} + } +} diff --git a/man/oci-runtime-tool-generate.1.md b/man/oci-runtime-tool-generate.1.md index 205dbbe8a..75a8c113d 100644 --- a/man/oci-runtime-tool-generate.1.md +++ b/man/oci-runtime-tool-generate.1.md @@ -126,6 +126,9 @@ read the configuration from `config.json`. **--linux-mem-swappiness**=MEMSWAPPINESS Sets the swappiness of how the kernel will swap memory pages (Range from 0 to 100). +**--linux-pids-limit**=PIDSLIMIT + Set maximum number of PIDs. + **--mount**=*PATH* Use a mount namespace where *PATH* is an existing mount namespace file to join. The special *PATH* empty-string creates a new namespace.