@@ -22,36 +22,58 @@ import (
2222 "context"
2323
2424 "github.com/containerd/containerd/runtime/linux/runctypes"
25+ "github.com/containerd/containerd/runtime/v2/runc/options"
2526 "github.com/pkg/errors"
2627)
2728
2829// WithNoNewKeyring causes tasks not to be created with a new keyring for secret storage.
2930// There is an upper limit on the number of keyrings in a linux system
3031func WithNoNewKeyring (ctx context.Context , c * Client , ti * TaskInfo ) error {
31- if ti .Options == nil {
32- ti .Options = & runctypes.CreateOptions {}
33- }
34- opts , ok := ti .Options .(* runctypes.CreateOptions )
35- if ! ok {
36- return errors .New ("could not cast TaskInfo Options to CreateOptions" )
32+ if CheckRuntime (ti .Runtime (), "io.containerd.runc" ) {
33+ if ti .Options == nil {
34+ ti .Options = & options.Options {}
35+ }
36+ opts , ok := ti .Options .(* options.Options )
37+ if ! ok {
38+ return errors .New ("invalid v2 shim create options format" )
39+ }
40+ opts .NoNewKeyring = true
41+ } else {
42+ if ti .Options == nil {
43+ ti .Options = & runctypes.CreateOptions {}
44+ }
45+ opts , ok := ti .Options .(* runctypes.CreateOptions )
46+ if ! ok {
47+ return errors .New ("could not cast TaskInfo Options to CreateOptions" )
48+ }
49+ opts .NoNewKeyring = true
3750 }
38-
39- opts .NoNewKeyring = true
4051 return nil
4152}
4253
4354// WithNoPivotRoot instructs the runtime not to you pivot_root
44- func WithNoPivotRoot (_ context.Context , _ * Client , info * TaskInfo ) error {
45- if info . Options == nil {
46- info .Options = & runctypes. CreateOptions {
47- NoPivotRoot : true ,
55+ func WithNoPivotRoot (_ context.Context , _ * Client , ti * TaskInfo ) error {
56+ if CheckRuntime ( ti . Runtime (), "io.containerd.runc" ) {
57+ if ti .Options == nil {
58+ ti . Options = & options. Options {}
4859 }
49- return nil
50- }
51- opts , ok := info .Options .(* runctypes.CreateOptions )
52- if ! ok {
53- return errors .New ("invalid options type, expected runctypes.CreateOptions" )
60+ opts , ok := ti .Options .(* options.Options )
61+ if ! ok {
62+ return errors .New ("invalid v2 shim create options format" )
63+ }
64+ opts .NoPivotRoot = true
65+ } else {
66+ if ti .Options == nil {
67+ ti .Options = & runctypes.CreateOptions {
68+ NoPivotRoot : true ,
69+ }
70+ return nil
71+ }
72+ opts , ok := ti .Options .(* runctypes.CreateOptions )
73+ if ! ok {
74+ return errors .New ("invalid options type, expected runctypes.CreateOptions" )
75+ }
76+ opts .NoPivotRoot = true
5477 }
55- opts .NoPivotRoot = true
5678 return nil
5779}
0 commit comments