From 0adb7c13239e675da3f3003deedf48ef388f4862 Mon Sep 17 00:00:00 2001 From: James Jenkins Date: Thu, 17 Aug 2023 09:20:24 -0400 Subject: [PATCH] Add JSON encoding to server package Add JSON encoding of cri runtime configuration options to the server package. Signed-off-by: James Jenkins --- pkg/cri/server/helpers.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/cri/server/helpers.go b/pkg/cri/server/helpers.go index 2b42538d4a75..dd82caad1185 100644 --- a/pkg/cri/server/helpers.go +++ b/pkg/cri/server/helpers.go @@ -18,6 +18,7 @@ package server import ( "context" + "encoding/json" "fmt" "path" "path/filepath" @@ -348,6 +349,16 @@ func generateRuntimeOptions(r criconfig.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, err = optionsTree.Marshal() if err != nil { return nil, fmt.Errorf("failed to marshal TOML blob for runtime %q: %v", r.Type, err)