Skip to content

Commit edf4cb3

Browse files
authored
Merge pull request #795 from klihub/fixes/spec-linux-pids-limit-is-ptr
runtime-spec: bump to v1.3.0, fixup for backward incompatible linux PIDs limit type change .
2 parents e5b4542 + 3c27840 commit edf4cb3

File tree

9 files changed

+244
-45
lines changed

9 files changed

+244
-45
lines changed

cgroups/cgroups_v1.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ func (cg *CgroupV1) GetMemoryData(pid int, cgPath string) (*rspec.LinuxMemory, e
539539
return nil, err
540540
}
541541
kernelLimit := res
542-
lm.Kernel = &kernelLimit
542+
lm.Kernel = &kernelLimit //nolint:staticcheck // Ignore SA1019: lm.Kernel is deprecated
543543
case 4:
544544
res, err := strconv.ParseInt(strings.TrimSpace(string(contents)), 10, 64)
545545
if err != nil {
@@ -671,6 +671,11 @@ func (cg *CgroupV1) GetPidsData(pid int, cgPath string) (*rspec.LinuxPids, error
671671
if err != nil {
672672
return nil, err
673673
}
674+
if strings.TrimSpace(string(contents)) == "max" {
675+
res := int64(-1)
676+
lp.Limit = &res
677+
return lp, nil
678+
}
674679
res, err := strconv.ParseInt(strings.TrimSpace(string(contents)), 10, 64)
675680
if err != nil {
676681
if os.IsNotExist(err) {
@@ -679,7 +684,7 @@ func (cg *CgroupV1) GetPidsData(pid int, cgPath string) (*rspec.LinuxPids, error
679684

680685
return nil, err
681686
}
682-
lp.Limit = res
687+
lp.Limit = &res
683688

684689
return lp, nil
685690
}

generate/generate.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ var (
2626
}
2727
)
2828

29+
const (
30+
// UnlimitedPidsLimit can be passed to SetLinuxResourcesPidsLimit to
31+
// request unlimited PIDs.
32+
UnlimitedPidsLimit int64 = -1
33+
)
34+
2935
// Generator represents a generator for a container config.
3036
type Generator struct {
3137
Config *rspec.Spec
@@ -911,7 +917,7 @@ func (g *Generator) SetLinuxResourcesMemorySwap(swap int64) {
911917
// SetLinuxResourcesMemoryKernel sets g.Config.Linux.Resources.Memory.Kernel.
912918
func (g *Generator) SetLinuxResourcesMemoryKernel(kernel int64) {
913919
g.initConfigLinuxResourcesMemory()
914-
g.Config.Linux.Resources.Memory.Kernel = &kernel
920+
g.Config.Linux.Resources.Memory.Kernel = &kernel //nolint:staticcheck // Ignore SA1019: g.Config.Linux.Resources.Memory.Kernel is deprecated
915921
}
916922

917923
// SetLinuxResourcesMemoryKernelTCP sets g.Config.Linux.Resources.Memory.KernelTCP.
@@ -970,7 +976,7 @@ func (g *Generator) DropLinuxResourcesNetworkPriorities(name string) {
970976
// SetLinuxResourcesPidsLimit sets g.Config.Linux.Resources.Pids.Limit.
971977
func (g *Generator) SetLinuxResourcesPidsLimit(limit int64) {
972978
g.initConfigLinuxResourcesPids()
973-
g.Config.Linux.Resources.Pids.Limit = limit
979+
g.Config.Linux.Resources.Pids.Limit = &limit
974980
}
975981

976982
// ClearLinuxSysctl clears g.Config.Linux.Sysctl.
@@ -1060,13 +1066,13 @@ func (g *Generator) ClearPreStartHooks() {
10601066
if g.Config == nil || g.Config.Hooks == nil {
10611067
return
10621068
}
1063-
g.Config.Hooks.Prestart = []rspec.Hook{}
1069+
g.Config.Hooks.Prestart = []rspec.Hook{} //nolint:staticcheck // Ignore SA1019: g.Config.Hooks.Prestart is deprecated
10641070
}
10651071

10661072
// AddPreStartHook add a prestart hook into g.Config.Hooks.Prestart.
10671073
func (g *Generator) AddPreStartHook(preStartHook rspec.Hook) {
10681074
g.initConfigHooks()
1069-
g.Config.Hooks.Prestart = append(g.Config.Hooks.Prestart, preStartHook)
1075+
g.Config.Hooks.Prestart = append(g.Config.Hooks.Prestart, preStartHook) //nolint:staticcheck // Ignore SA1019: g.Config.Hooks.Prestart is deprecated
10701076
}
10711077

10721078
// ClearPostStopHooks clear g.Config.Hooks.Poststop.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/moby/sys/capability v0.4.0
1111
github.com/moby/sys/mountinfo v0.7.2
1212
github.com/mrunalp/fileutils v0.5.0
13-
github.com/opencontainers/runtime-spec v1.1.0
13+
github.com/opencontainers/runtime-spec v1.3.0
1414
github.com/opencontainers/selinux v1.9.1
1515
github.com/sirupsen/logrus v1.8.1
1616
github.com/stretchr/testify v1.3.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
1111
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
1212
github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b h1:Ga1nclDSe8gOw37MVLMhfu2QKWtD6gvtQ298zsKVh8g=
1313
github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b/go.mod h1:pzzDgJWZ34fGzaAZGFW22KVZDfyrYW+QABMrWnJBnSs=
14-
github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
15-
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
1614
github.com/moby/sys/capability v0.4.0 h1:4D4mI6KlNtWMCM1Z/K0i7RV1FkX+DBDHKVJpCndZoHk=
1715
github.com/moby/sys/capability v0.4.0/go.mod h1:4g9IK291rVkms3LKCDOoYlnV8xKwoDTpIrNEE35Wq0I=
16+
github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
17+
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
1818
github.com/mrunalp/fileutils v0.5.0 h1:NKzVxiH7eSk+OQ4M+ZYW1K6h27RUV3MI6NUTsHhU6Z4=
1919
github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
20-
github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg=
21-
github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
20+
github.com/opencontainers/runtime-spec v1.3.0 h1:YZupQUdctfhpZy3TM39nN9Ika5CBWT5diQ8ibYCRkxg=
21+
github.com/opencontainers/runtime-spec v1.3.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
2222
github.com/opencontainers/selinux v1.9.1 h1:b4VPEF3O5JLZgdTDBmGepaaIbAo0GqoF6EBRq5f/g3Y=
2323
github.com/opencontainers/selinux v1.9.1/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
2424
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

validate/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func (v *Validator) CheckHooks() (errs error) {
275275
}
276276

277277
if v.spec.Hooks != nil {
278-
errs = multierror.Append(errs, v.checkEventHooks("prestart", v.spec.Hooks.Prestart, v.HostSpecific))
278+
errs = multierror.Append(errs, v.checkEventHooks("prestart", v.spec.Hooks.Prestart, v.HostSpecific)) //nolint:staticcheck // Ignore SA1019: v.Spec.Hooks.Prestart is deprecated
279279
errs = multierror.Append(errs, v.checkEventHooks("poststart", v.spec.Hooks.Poststart, v.HostSpecific))
280280
errs = multierror.Append(errs, v.checkEventHooks("poststop", v.spec.Hooks.Poststop, v.HostSpecific))
281281
}

validation/util/linux_resources_memory.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ func ValidateLinuxResourcesMemory(config *rspec.Spec, t *tap.T, state *rspec.Sta
3131
t.Ok(*lm.Swap == *config.Linux.Resources.Memory.Swap, "memory swap is set correctly")
3232
t.Diagnosticf("expect: %d, actual: %d", *config.Linux.Resources.Memory.Swap, *lm.Reservation)
3333

34-
t.Ok(*lm.Kernel == *config.Linux.Resources.Memory.Kernel, "memory kernel is set correctly")
35-
t.Diagnosticf("expect: %d, actual: %d", *config.Linux.Resources.Memory.Kernel, *lm.Kernel)
34+
t.Ok(*lm.Kernel == *config.Linux.Resources.Memory.Kernel, "memory kernel is set correctly") //nolint:staticcheck // Ignore SA1019: lm.Kernel is deprecated
35+
t.Diagnosticf("expect: %d, actual: %d", *config.Linux.Resources.Memory.Kernel, *lm.Kernel) //nolint:staticcheck // Ignore SA1019: config.Linux.Resources.Memory.Kernel is deprecated
3636

3737
t.Ok(*lm.KernelTCP == *config.Linux.Resources.Memory.KernelTCP, "memory kernelTCP is set correctly")
38-
t.Diagnosticf("expect: %d, actual: %d", *config.Linux.Resources.Memory.KernelTCP, *lm.Kernel)
38+
t.Diagnosticf("expect: %d, actual: %d", *config.Linux.Resources.Memory.KernelTCP, *lm.Kernel) //nolint:staticcheck // Ignore SA1019: lm.Kernel is deprecated
3939

4040
t.Ok(*lm.Swappiness == *config.Linux.Resources.Memory.Swappiness, "memory swappiness is set correctly")
4141
t.Diagnosticf("expect: %d, actual: %d", *config.Linux.Resources.Memory.Swappiness, *lm.Swappiness)

0 commit comments

Comments
 (0)