From 2c159f8f48fd6f5b468fc5c22db9980410de2a61 Mon Sep 17 00:00:00 2001 From: James Jenkins Date: Fri, 12 May 2023 14:55:23 -0400 Subject: [PATCH] Encode Generic ConfigBody as JSON Enocode the runtime configuration body as JSON when the TypeURL is available and the generic configuration options are being used. Signed-off-by: James Jenkins --- internal/cri/config/config.go | 11 +++++++++++ pkg/runtimeoptions/v1/api.proto | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/cri/config/config.go b/internal/cri/config/config.go index b8bf9e162e0b..e28d3f2eddc3 100644 --- a/internal/cri/config/config.go +++ b/internal/cri/config/config.go @@ -18,6 +18,7 @@ package config import ( "context" + "encoding/json" "errors" "fmt" "net/url" @@ -773,6 +774,16 @@ func GenerateRuntimeOptions(r Runtime) (interface{}, error) { // For generic configuration, if no config path specified (preserving old behavior), pass // the whole TOML configuration section to the runtime. if runtimeOpts, ok := options.(*runtimeoptions.Options); ok && runtimeOpts.ConfigPath == "" { + if runtimeOpts.TypeUrl != "" { + body, err := json.Marshal(r.Options) + if err != nil { + return nil, fmt.Errorf("failed to marshal config body as JSON for runtime %q: %v", r.Type, err) + } + + runtimeOpts.ConfigBody = body + return options, nil + } + runtimeOpts.ConfigBody = b } diff --git a/pkg/runtimeoptions/v1/api.proto b/pkg/runtimeoptions/v1/api.proto index 2e0730ff2c86..4bc20753f54b 100644 --- a/pkg/runtimeoptions/v1/api.proto +++ b/pkg/runtimeoptions/v1/api.proto @@ -11,7 +11,9 @@ message Options { // ConfigPath specifies the filesystem location of the config file // used by the runtime. string config_path = 2; - // Blob specifies an in-memory TOML blob passed from containerd's configuration section - // for this runtime. This will be used if config_path is not specified. + // Blob specifies an in-memory blob passed from containerd's configuration section + // for this runtime. If the typeurl is specified, this will be a JSON blob which can be + // interpreted as the type represented by the typeurl. Otherwise, this will be a TOML + // blob. This will be used if config_path is not specified. bytes config_body = 3; }