Skip to content

Commit 79aad89

Browse files
committed
api,runtime-tools: adjust for runtime-spec v1.3.0.
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
1 parent 4194a5d commit 79aad89

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

pkg/api/resources.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import (
2222
rspec "github.com/opencontainers/runtime-spec/specs-go"
2323
)
2424

25+
const (
26+
// UnlimitedPidsLimit indicates unlimited Linux PIDs limit.
27+
UnlimitedPidsLimit = -1
28+
)
29+
2530
// FromOCILinuxResources returns resources from an OCI runtime Spec.
2631
func FromOCILinuxResources(o *rspec.LinuxResources, _ map[string]string) *LinuxResources {
2732
if o == nil {
@@ -67,8 +72,9 @@ func FromOCILinuxResources(o *rspec.LinuxResources, _ map[string]string) *LinuxR
6772
})
6873
}
6974
if p := o.Pids; p != nil {
70-
l.Pids = &LinuxPids{
71-
Limit: p.Limit,
75+
l.Pids = &LinuxPids{}
76+
if p.Limit != nil && *p.Limit != 0 {
77+
l.Pids.Limit = *p.Limit
7278
}
7379
}
7480
if len(o.Unified) != 0 {
@@ -134,8 +140,10 @@ func (r *LinuxResources) ToOCI() *rspec.LinuxResources {
134140
})
135141
}
136142
if r.Pids != nil {
137-
o.Pids = &rspec.LinuxPids{
138-
Limit: r.Pids.Limit,
143+
o.Pids = &rspec.LinuxPids{}
144+
if r.Pids.Limit > UnlimitedPidsLimit {
145+
limit := r.Pids.Limit
146+
o.Pids.Limit = &limit
139147
}
140148
}
141149
return o

pkg/runtime-tools/generate/generate.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ import (
2929
nri "github.com/containerd/nri/pkg/api"
3030
)
3131

32+
const (
33+
UnlimitedPidsLimit = 0
34+
)
35+
3236
// GeneratorOption is an option for Generator().
3337
type GeneratorOption func(*Generator)
3438

@@ -611,6 +615,22 @@ func (g *Generator) SetProcessIOPriority(ioprio *rspec.LinuxIOPriority) {
611615
g.Config.Process.IOPriority = ioprio
612616
}
613617

618+
// SetLinuxResourcesPidsLimit sets Linux PID limit. Starting with
619+
// v1.3.0 opencontainers/runtime-spec switched the PID limit to
620+
// *int64 from int64 with nil meaning "unlimited". We don't want
621+
// to change our API types though, so instead we use a dedicated
622+
// value for unlimited.
623+
func (g *Generator) SetLinuxResourcesPidsLimit(limit int64) {
624+
g.initConfigLinuxResources()
625+
if g.Config.Linux.Resources.Pids == nil {
626+
g.Config.Linux.Resources.Pids = &rspec.LinuxPids{}
627+
}
628+
if limit > UnlimitedPidsLimit {
629+
g.Config.Linux.Resources.Pids.Limit = &limit
630+
}
631+
}
632+
633+
614634
func (g *Generator) initConfig() {
615635
if g.Config == nil {
616636
g.Config = &rspec.Spec{}

0 commit comments

Comments
 (0)