github.com/rish1988/moby@v25.0.2+incompatible/libcontainerd/shimopts/convert.go (about) 1 package shimopts 2 3 import ( 4 runhcsoptions "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options" 5 runtimeoptions "github.com/containerd/containerd/pkg/runtimeoptions/v1" 6 "github.com/containerd/containerd/plugin" 7 runcoptions "github.com/containerd/containerd/runtime/v2/runc/options" 8 "github.com/pelletier/go-toml" 9 ) 10 11 // Generate converts opts into a runtime options value for the runtimeType which 12 // can be passed into containerd. 13 func Generate(runtimeType string, opts map[string]interface{}) (interface{}, error) { 14 // This is horrible, but we have no other choice. The containerd client 15 // can only handle options values which can be marshaled into a 16 // typeurl.Any. And we're in good company: cri-containerd handles shim 17 // options in the same way. 18 var out interface{} 19 switch runtimeType { 20 case plugin.RuntimeRuncV1, plugin.RuntimeRuncV2: 21 out = &runcoptions.Options{} 22 case "io.containerd.runhcs.v1": 23 out = &runhcsoptions.Options{} 24 default: 25 out = &runtimeoptions.Options{} 26 } 27 28 // We can't use mergo.Map as it is too strict about type-assignability 29 // with numeric types. 30 tree, err := toml.TreeFromMap(opts) 31 if err != nil { 32 return nil, err 33 } 34 if err := tree.Unmarshal(out); err != nil { 35 return nil, err 36 } 37 return out, nil 38 }