Skip to content

Commit

Permalink
Encode Generic ConfigBody as JSON
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Jenkins-J committed May 19, 2023
1 parent 8781329 commit f9293bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions pkg/cri/sbserver/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package sbserver

import (
"context"
"encoding/json"
"fmt"
"path"
"path/filepath"
Expand Down Expand Up @@ -281,6 +282,16 @@ func generateRuntimeOptions(r criconfig.Runtime, c criconfig.Config) (interface{
// 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)
Expand Down
6 changes: 4 additions & 2 deletions pkg/runtimeoptions/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit f9293bb

Please sign in to comment.