summaryrefslogtreecommitdiff
path: root/libcontainerd
diff options
context:
space:
mode:
authorCory Snider <csnider@mirantis.com>2023-02-17 14:12:06 -0500
committerCory Snider <csnider@mirantis.com>2023-02-17 18:08:06 -0500
commitb0eed5ade62404ea70cad9fd86bc1a713e394acd (patch)
tree8dc2426a41154074479a109d56741bdf10dcdf3e /libcontainerd
parentc030f7f40d62ecabfedd1cf96fbb734ce051ce73 (diff)
downloaddocker-b0eed5ade62404ea70cad9fd86bc1a713e394acd.tar.gz
daemon: allow shimv2 runtimes to be configured
Kubernetes only permits RuntimeClass values which are valid lowercase RFC 1123 labels, which disallows the period character. This prevents cri-dockerd from being able to support configuring alternative shimv2 runtimes for a pod as shimv2 runtime names must contain at least one period character. Add support for configuring named shimv2 runtimes in daemon.json so that runtime names can be aliased to Kubernetes-compatible names. Allow options to be set on shimv2 runtimes in daemon.json. The names of the new daemon runtime config fields have been selected to correspond with the equivalent field names in cri-containerd's configuration so that users can more easily follow documentation from the runtime vendor written for cri-containerd and apply it to daemon.json. Signed-off-by: Cory Snider <csnider@mirantis.com>
Diffstat (limited to 'libcontainerd')
-rw-r--r--libcontainerd/shimopts/convert.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/libcontainerd/shimopts/convert.go b/libcontainerd/shimopts/convert.go
new file mode 100644
index 0000000000..b5ef8f52a9
--- /dev/null
+++ b/libcontainerd/shimopts/convert.go
@@ -0,0 +1,38 @@
+package shimopts
+
+import (
+ runhcsoptions "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
+ runtimeoptions "github.com/containerd/containerd/pkg/runtimeoptions/v1"
+ "github.com/containerd/containerd/plugin"
+ runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
+ "github.com/pelletier/go-toml"
+)
+
+// Generate converts opts into a runtime options value for the runtimeType which
+// can be passed into containerd.
+func Generate(runtimeType string, opts map[string]interface{}) (interface{}, error) {
+ // This is horrible, but we have no other choice. The containerd client
+ // can only handle options values which can be marshaled into a
+ // typeurl.Any. And we're in good company: cri-containerd handles shim
+ // options in the same way.
+ var out interface{}
+ switch runtimeType {
+ case plugin.RuntimeRuncV1, plugin.RuntimeRuncV2:
+ out = &runcoptions.Options{}
+ case "io.containerd.runhcs.v1":
+ out = &runhcsoptions.Options{}
+ default:
+ out = &runtimeoptions.Options{}
+ }
+
+ // We can't use mergo.Map as it is too strict about type-assignability
+ // with numeric types.
+ tree, err := toml.TreeFromMap(opts)
+ if err != nil {
+ return nil, err
+ }
+ if err := tree.Unmarshal(out); err != nil {
+ return nil, err
+ }
+ return out, nil
+}