Skip to content

Commit 7648ad2

Browse files
authored
Merge pull request #5300 from adisky/fix-toml
Change the type of CRI runtime option
2 parents 1edab60 + 4d41174 commit 7648ad2

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

pkg/cri/config/config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/containerd/containerd/log"
2525
"github.com/containerd/containerd/plugin"
26-
"github.com/pelletier/go-toml"
2726
"github.com/pkg/errors"
2827
)
2928

@@ -47,9 +46,11 @@ type Runtime struct {
4746
// DEPRECATED: use Options instead. Remove when shim v1 is deprecated.
4847
// This only works for runtime type "io.containerd.runtime.v1.linux".
4948
Root string `toml:"runtime_root" json:"runtimeRoot"`
50-
// Options are config options for the runtime. If options is loaded
51-
// from toml config, it will be toml.Tree.
52-
Options *toml.Tree `toml:"options" json:"options"`
49+
// Options are config options for the runtime.
50+
// If options is loaded from toml config, it will be map[string]interface{}.
51+
// Options can be converted into toml.Tree using toml.TreeFromMap().
52+
// Using options type as map[string]interface{} helps in correctly marshaling options from Go to JSON.
53+
Options map[string]interface{} `toml:"options" json:"options"`
5354
// PrivilegedWithoutHostDevices overloads the default behaviour for adding host devices to the
5455
// runtime spec when the container is privileged. Defaults to false.
5556
PrivilegedWithoutHostDevices bool `toml:"privileged_without_host_devices" json:"privileged_without_host_devices"`

pkg/cri/server/helpers.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
3333
"github.com/containerd/typeurl"
3434
imagedigest "github.com/opencontainers/go-digest"
35+
"github.com/pelletier/go-toml"
3536
"github.com/pkg/errors"
3637
"golang.org/x/net/context"
3738
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
@@ -308,8 +309,12 @@ func generateRuntimeOptions(r criconfig.Runtime, c criconfig.Config) (interface{
308309
SystemdCgroup: c.SystemdCgroup,
309310
}, nil
310311
}
312+
optionsTree, err := toml.TreeFromMap(r.Options)
313+
if err != nil {
314+
return nil, err
315+
}
311316
options := getRuntimeOptionsType(r.Type)
312-
if err := r.Options.Unmarshal(options); err != nil {
317+
if err := optionsTree.Unmarshal(options); err != nil {
313318
return nil, err
314319
}
315320
return options, nil

0 commit comments

Comments
 (0)