Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/runtime-tools/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ func (g *Generator) AdjustSeccompPolicy(policy *nri.LinuxSeccomp) error {
return nil
}

g.initConfigLinux()

// Note: we explicitly do not use the SetDefaultSeccompAction() and
// SetSeccompArchitecture() helpers from generate here, because they
// expect a "humanized" version of the action (e.g. "allow" or "x86").
Expand Down Expand Up @@ -586,6 +588,12 @@ func (g *Generator) InjectCDIDevices(devices []*nri.CDIDevice) error {

// AdjustRlimits adjusts the (Linux) POSIX resource limits in the OCI Spec.
func (g *Generator) AdjustRlimits(rlimits []*nri.POSIXRlimit) error {
if len(rlimits) == 0 {
return nil
}

g.initConfigProcess()

for _, l := range rlimits {
if l == nil {
continue
Expand Down
45 changes: 45 additions & 0 deletions pkg/runtime-tools/generate/generate_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,51 @@ func TestAdjustment(t *testing.T) {
require.NoError(t, xg.Adjust(adjust))
require.Nil(t, spec.Linux.IntelRdt)
})

t.Run("seccomp policy without Linux section", func(t *testing.T) {
spec := makeSpec()
spec.Linux = nil
seccomp := rspec.LinuxSeccomp{
DefaultAction: rspec.ActErrno,
Architectures: []rspec.Arch{},
Flags: []rspec.LinuxSeccompFlag{},
Syscalls: []rspec.LinuxSyscall{},
}
adjust := &api.ContainerAdjustment{
Linux: &api.LinuxContainerAdjustment{
SeccompPolicy: api.FromOCILinuxSeccomp(&seccomp),
},
}

xg := xgen.SpecGenerator(ocigen.New(spec))
require.NotNil(t, xg)
require.NoError(t, xg.Adjust(adjust))
require.NotNil(t, spec.Linux)
require.Equal(t, seccomp, *spec.Linux.Seccomp)
})

t.Run("rlimits without Process section", func(t *testing.T) {
spec := makeSpec()
spec.Process = nil
rlimits := []rspec.POSIXRlimit{{
Type: "nofile",
Hard: 456,
Soft: 123,
}}
adjust := &api.ContainerAdjustment{
Rlimits: []*api.POSIXRlimit{{
Type: "nofile",
Hard: 456,
Soft: 123,
}},
}

xg := xgen.SpecGenerator(ocigen.New(spec))
require.NotNil(t, xg)
require.NoError(t, xg.Adjust(adjust))
require.NotNil(t, spec.Process)
require.Equal(t, rlimits, spec.Process.Rlimits)
})
}

type specOption func(*rspec.Spec)
Expand Down
Loading