Skip to content

Commit

Permalink
Add JSON encoding to server package
Browse files Browse the repository at this point in the history
Add JSON encoding of cri runtime configuration options to the server
package.

Signed-off-by: James Jenkins <[email protected]>
  • Loading branch information
Jenkins-J committed Aug 17, 2023
1 parent 98a3338 commit 0adb7c1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/cri/server/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package server

import (
"context"
"encoding/json"
"fmt"
"path"
"path/filepath"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0adb7c1

Please sign in to comment.