@@ -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.
2631func FromOCILinuxResources (o * rspec.LinuxResources , _ map [string ]string ) * LinuxResources {
2732 if o == nil {
@@ -33,7 +38,7 @@ func FromOCILinuxResources(o *rspec.LinuxResources, _ map[string]string) *LinuxR
3338 Limit : Int64 (m .Limit ),
3439 Reservation : Int64 (m .Reservation ),
3540 Swap : Int64 (m .Swap ),
36- Kernel : Int64 (m .Kernel ),
41+ Kernel : Int64 (m .Kernel ), //nolint:staticcheck // ignore SA1019: m.Kernel is deprecated
3742 KernelTcp : Int64 (m .KernelTCP ),
3843 Swappiness : UInt64 (m .Swappiness ),
3944 DisableOomKiller : Bool (m .DisableOOMKiller ),
@@ -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
0 commit comments