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 Feb 5, 2024
1 parent f5e7fe0 commit 2c159f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions internal/cri/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package config

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/url"
Expand Down Expand Up @@ -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
}

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 2c159f8

Please sign in to comment.