Merge pull request #5300 from adisky/fix-toml

Change the type of CRI runtime option
This commit is contained in:
Mike Brown 2021-04-08 10:14:45 -05:00 committed by GitHub
commit 7648ad289b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -23,7 +23,6 @@ import (
"github.com/containerd/containerd/log" "github.com/containerd/containerd/log"
"github.com/containerd/containerd/plugin" "github.com/containerd/containerd/plugin"
"github.com/pelletier/go-toml"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -47,9 +46,11 @@ type Runtime struct {
// DEPRECATED: use Options instead. Remove when shim v1 is deprecated. // DEPRECATED: use Options instead. Remove when shim v1 is deprecated.
// This only works for runtime type "io.containerd.runtime.v1.linux". // This only works for runtime type "io.containerd.runtime.v1.linux".
Root string `toml:"runtime_root" json:"runtimeRoot"` Root string `toml:"runtime_root" json:"runtimeRoot"`
// Options are config options for the runtime. If options is loaded // Options are config options for the runtime.
// from toml config, it will be toml.Tree. // If options is loaded from toml config, it will be map[string]interface{}.
Options *toml.Tree `toml:"options" json:"options"` // Options can be converted into toml.Tree using toml.TreeFromMap().
// Using options type as map[string]interface{} helps in correctly marshaling options from Go to JSON.
Options map[string]interface{} `toml:"options" json:"options"`
// PrivilegedWithoutHostDevices overloads the default behaviour for adding host devices to the // PrivilegedWithoutHostDevices overloads the default behaviour for adding host devices to the
// runtime spec when the container is privileged. Defaults to false. // runtime spec when the container is privileged. Defaults to false.
PrivilegedWithoutHostDevices bool `toml:"privileged_without_host_devices" json:"privileged_without_host_devices"` PrivilegedWithoutHostDevices bool `toml:"privileged_without_host_devices" json:"privileged_without_host_devices"`

View File

@ -32,6 +32,7 @@ import (
runcoptions "github.com/containerd/containerd/runtime/v2/runc/options" runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
imagedigest "github.com/opencontainers/go-digest" imagedigest "github.com/opencontainers/go-digest"
"github.com/pelletier/go-toml"
"github.com/pkg/errors" "github.com/pkg/errors"
"golang.org/x/net/context" "golang.org/x/net/context"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
@ -308,8 +309,12 @@ func generateRuntimeOptions(r criconfig.Runtime, c criconfig.Config) (interface{
SystemdCgroup: c.SystemdCgroup, SystemdCgroup: c.SystemdCgroup,
}, nil }, nil
} }
optionsTree, err := toml.TreeFromMap(r.Options)
if err != nil {
return nil, err
}
options := getRuntimeOptionsType(r.Type) options := getRuntimeOptionsType(r.Type)
if err := r.Options.Unmarshal(options); err != nil { if err := optionsTree.Unmarshal(options); err != nil {
return nil, err return nil, err
} }
return options, nil return options, nil