Skip to content

Commit 1709409

Browse files
author
Mrunal Patel
authored
Merge pull request #206 from Mashimiao/generate-add-pids-limit-support
generate: add pids limit support
2 parents d6a13bd + beb6478 commit 1709409

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

cmd/oci-runtime-tool/generate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var generateFlags = []cli.Flag{
7272
cli.Uint64Flag{Name: "linux-mem-kernel-limit", Usage: "kernel memory limit (in bytes)"},
7373
cli.Uint64Flag{Name: "linux-mem-kernel-tcp", Usage: "kernel memory limit for tcp (in bytes)"},
7474
cli.Uint64Flag{Name: "linux-mem-swappiness", Usage: "how aggressive the kernel will swap memory pages (Range from 0 to 100)"},
75+
cli.Int64Flag{Name: "linux-pids-limit", Usage: "maximum number of PIDs"},
7576
}
7677

7778
var generateCommand = cli.Command{
@@ -389,6 +390,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
389390
g.SetLinuxResourcesMemorySwappiness(context.Uint64("linux-mem-swappiness"))
390391
}
391392

393+
if context.IsSet("linux-pids-limit") {
394+
g.SetLinuxResourcesPidsLimit(context.Int64("linux-pids-limit"))
395+
}
396+
392397
var sd string
393398
var sa, ss []string
394399

completions/bash/oci-runtime-tool

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ _oci-runtime-tool_generate() {
285285
--help
286286
--ipc
287287
--label
288+
--linux-pids-limit
288289
--mount
289290
--mount-cgroups
290291
--mount-label

generate/generate.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@ func (g *Generator) SetLinuxResourcesMemorySwappiness(swappiness uint64) {
446446
g.spec.Linux.Resources.Memory.Swappiness = &swappiness
447447
}
448448

449+
// SetLinuxResourcesPidsLimit sets g.spec.Linux.Resources.Pids.Limit.
450+
func (g *Generator) SetLinuxResourcesPidsLimit(limit int64) {
451+
g.initSpecLinuxResourcesPids()
452+
g.spec.Linux.Resources.Pids.Limit = &limit
453+
}
454+
449455
// ClearLinuxSysctl clears g.spec.Linux.Sysctl.
450456
func (g *Generator) ClearLinuxSysctl() {
451457
if g.spec == nil || g.spec.Linux == nil {

generate/spec.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,10 @@ func (g *Generator) initSpecLinuxResourcesMemory() {
5858
g.spec.Linux.Resources.Memory = &rspec.Memory{}
5959
}
6060
}
61+
62+
func (g *Generator) initSpecLinuxResourcesPids() {
63+
g.initSpecLinuxResources()
64+
if g.spec.Linux.Resources.Pids == nil {
65+
g.spec.Linux.Resources.Pids = &rspec.Pids{}
66+
}
67+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ read the configuration from `config.json`.
126126
**--linux-mem-swappiness**=MEMSWAPPINESS
127127
Sets the swappiness of how the kernel will swap memory pages (Range from 0 to 100).
128128

129+
**--linux-pids-limit**=PIDSLIMIT
130+
Set maximum number of PIDs.
131+
129132
**--mount**=*PATH*
130133
Use a mount namespace where *PATH* is an existing mount namespace file
131134
to join. The special *PATH* empty-string creates a new namespace.

0 commit comments

Comments
 (0)