Change CRI config runtime options type
Changing Runtime.Options type to map[string]interface{}
to correctly marshal it from go to JSON.
See issue: https://github.com/kubernetes-sigs/cri-tools/issues/728
Signed-off-by: Aditi Sharma <adi.sky17@gmail.com>
			
			
This commit is contained in:
		| @@ -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"` | ||||||
|   | |||||||
| @@ -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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Aditi Sharma
					Aditi Sharma