Skip to content

Commit 2c159f8

Browse files
committed
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 <James.Jenkins@ibm.com>
1 parent f5e7fe0 commit 2c159f8

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

internal/cri/config/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package config
1818

1919
import (
2020
"context"
21+
"encoding/json"
2122
"errors"
2223
"fmt"
2324
"net/url"
@@ -773,6 +774,16 @@ func GenerateRuntimeOptions(r Runtime) (interface{}, error) {
773774
// For generic configuration, if no config path specified (preserving old behavior), pass
774775
// the whole TOML configuration section to the runtime.
775776
if runtimeOpts, ok := options.(*runtimeoptions.Options); ok && runtimeOpts.ConfigPath == "" {
777+
if runtimeOpts.TypeUrl != "" {
778+
body, err := json.Marshal(r.Options)
779+
if err != nil {
780+
return nil, fmt.Errorf("failed to marshal config body as JSON for runtime %q: %v", r.Type, err)
781+
}
782+
783+
runtimeOpts.ConfigBody = body
784+
return options, nil
785+
}
786+
776787
runtimeOpts.ConfigBody = b
777788
}
778789

pkg/runtimeoptions/v1/api.proto

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ message Options {
1111
// ConfigPath specifies the filesystem location of the config file
1212
// used by the runtime.
1313
string config_path = 2;
14-
// Blob specifies an in-memory TOML blob passed from containerd's configuration section
15-
// for this runtime. This will be used if config_path is not specified.
14+
// Blob specifies an in-memory blob passed from containerd's configuration section
15+
// for this runtime. If the typeurl is specified, this will be a JSON blob which can be
16+
// interpreted as the type represented by the typeurl. Otherwise, this will be a TOML
17+
// blob. This will be used if config_path is not specified.
1618
bytes config_body = 3;
1719
}

0 commit comments

Comments
 (0)