@@ -20,33 +20,24 @@ package client
2020
2121import (
2222 "context"
23- "errors"
24-
25- "github.com/containerd/containerd/api/types/runc/options"
2623)
2724
2825// WithNoNewKeyring causes tasks not to be created with a new keyring for secret storage.
2926// There is an upper limit on the number of keyrings in a linux system
3027func WithNoNewKeyring (ctx context.Context , c * Client , ti * TaskInfo ) error {
31- if ti .Options == nil {
32- ti .Options = & options.Options {}
33- }
34- opts , ok := ti .Options .(* options.Options )
35- if ! ok {
36- return errors .New ("invalid v2 shim create options format" )
28+ opts , err := ti .getRuncOptions ()
29+ if err != nil {
30+ return err
3731 }
3832 opts .NoNewKeyring = true
3933 return nil
4034}
4135
4236// WithNoPivotRoot instructs the runtime not to you pivot_root
4337func WithNoPivotRoot (_ context.Context , _ * Client , ti * TaskInfo ) error {
44- if ti .Options == nil {
45- ti .Options = & options.Options {}
46- }
47- opts , ok := ti .Options .(* options.Options )
48- if ! ok {
49- return errors .New ("invalid v2 shim create options format" )
38+ opts , err := ti .getRuncOptions ()
39+ if err != nil {
40+ return err
5041 }
5142 opts .NoPivotRoot = true
5243 return nil
@@ -55,12 +46,9 @@ func WithNoPivotRoot(_ context.Context, _ *Client, ti *TaskInfo) error {
5546// WithShimCgroup sets the existing cgroup for the shim
5647func WithShimCgroup (path string ) NewTaskOpts {
5748 return func (ctx context.Context , c * Client , ti * TaskInfo ) error {
58- if ti .Options == nil {
59- ti .Options = & options.Options {}
60- }
61- opts , ok := ti .Options .(* options.Options )
62- if ! ok {
63- return errors .New ("invalid v2 shim create options format" )
49+ opts , err := ti .getRuncOptions ()
50+ if err != nil {
51+ return err
6452 }
6553 opts .ShimCgroup = path
6654 return nil
@@ -70,12 +58,9 @@ func WithShimCgroup(path string) NewTaskOpts {
7058// WithUIDOwner allows console I/O to work with the remapped UID in user namespace
7159func WithUIDOwner (uid uint32 ) NewTaskOpts {
7260 return func (ctx context.Context , c * Client , ti * TaskInfo ) error {
73- if ti .Options == nil {
74- ti .Options = & options.Options {}
75- }
76- opts , ok := ti .Options .(* options.Options )
77- if ! ok {
78- return errors .New ("invalid v2 shim create options format" )
61+ opts , err := ti .getRuncOptions ()
62+ if err != nil {
63+ return err
7964 }
8065 opts .IoUid = uid
8166 return nil
@@ -85,12 +70,9 @@ func WithUIDOwner(uid uint32) NewTaskOpts {
8570// WithGIDOwner allows console I/O to work with the remapped GID in user namespace
8671func WithGIDOwner (gid uint32 ) NewTaskOpts {
8772 return func (ctx context.Context , c * Client , ti * TaskInfo ) error {
88- if ti .Options == nil {
89- ti .Options = & options.Options {}
90- }
91- opts , ok := ti .Options .(* options.Options )
92- if ! ok {
93- return errors .New ("invalid v2 shim create options format" )
73+ opts , err := ti .getRuncOptions ()
74+ if err != nil {
75+ return err
9476 }
9577 opts .IoGid = gid
9678 return nil
0 commit comments