Skip to content

Commit 5e5c2be

Browse files
committed
Drop dependency on opencontainers/runtime-tools
pkg/runtime-tools/generate no longer depends on `*github.com/opencontainers/runtime-tools/generate.Generator`, which has no release since 2019. The underlying generator can be replaced with a custom implementation of the `UnderlyingGenerator` interface. Signed-off-by: Akihiro Suda <[email protected]>
1 parent 3827d9d commit 5e5c2be

1 file changed

Lines changed: 42 additions & 4 deletions

File tree

pkg/runtime-tools/generate/generate.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"strings"
2525

2626
rspec "github.com/opencontainers/runtime-spec/specs-go"
27-
"github.com/opencontainers/runtime-tools/generate"
2827

2928
nri "github.com/containerd/nri/pkg/api"
3029
)
@@ -34,13 +33,51 @@ const (
3433
UnlimitedPidsLimit = -1
3534
)
3635

36+
// UnderlyingGenerator is the interface for
37+
// [github.com/opencontainers/runtime-tools/generate.Generator].
38+
type UnderlyingGenerator interface {
39+
AddAnnotation(key, value string)
40+
AddDevice(device rspec.LinuxDevice)
41+
AddOrReplaceLinuxNamespace(ns string, path string) error
42+
AddPostStartHook(postStartHook rspec.Hook)
43+
AddPostStopHook(postStopHook rspec.Hook)
44+
AddPreStartHook(preStartHook rspec.Hook)
45+
AddProcessEnv(name, value string)
46+
AddLinuxResourcesDevice(allow bool, devType string, major, minor *int64, access string)
47+
AddLinuxResourcesHugepageLimit(pageSize string, limit uint64)
48+
AddLinuxResourcesUnified(key, val string)
49+
AddMount(mnt rspec.Mount)
50+
ClearMounts()
51+
ClearProcessEnv()
52+
Mounts() []rspec.Mount
53+
RemoveAnnotation(key string)
54+
RemoveDevice(path string)
55+
RemoveLinuxNamespace(ns string) error
56+
RemoveMount(dest string)
57+
SetProcessArgs(args []string)
58+
SetLinuxCgroupsPath(path string)
59+
SetLinuxResourcesCPUCpus(cpus string)
60+
SetLinuxResourcesCPUMems(mems string)
61+
SetLinuxResourcesCPUPeriod(period uint64)
62+
SetLinuxResourcesCPUQuota(quota int64)
63+
SetLinuxResourcesCPURealtimePeriod(period uint64)
64+
SetLinuxResourcesCPURealtimeRuntime(time int64)
65+
SetLinuxResourcesCPUShares(shares uint64)
66+
SetLinuxResourcesMemoryLimit(limit int64)
67+
SetLinuxResourcesMemorySwap(swap int64)
68+
SetLinuxRootPropagation(rp string) error
69+
SetProcessOOMScoreAdj(adj int)
70+
Spec() *rspec.Spec
71+
}
72+
3773
// GeneratorOption is an option for Generator().
3874
type GeneratorOption func(*Generator)
3975

4076
// Generator extends a stock runtime-tools Generator and extends it with
4177
// a few functions for handling NRI container adjustment.
4278
type Generator struct {
43-
*generate.Generator
79+
UnderlyingGenerator
80+
Config *rspec.Spec
4481
filterLabels func(map[string]string) (map[string]string, error)
4582
filterAnnotations func(map[string]string) (map[string]string, error)
4683
resolveBlockIO func(string) (*rspec.LinuxBlockIO, error)
@@ -50,9 +87,10 @@ type Generator struct {
5087
}
5188

5289
// SpecGenerator returns a wrapped OCI Spec Generator.
53-
func SpecGenerator(gg *generate.Generator, opts ...GeneratorOption) *Generator {
90+
func SpecGenerator(gg UnderlyingGenerator, opts ...GeneratorOption) *Generator {
5491
g := &Generator{
55-
Generator: gg,
92+
UnderlyingGenerator: gg,
93+
Config: gg.Spec(),
5694
}
5795
g.filterLabels = nopFilter
5896
g.filterAnnotations = nopFilter

0 commit comments

Comments
 (0)