Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/config/engine/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c *Config) AddRuntime(name string, path string, setAsDefault bool) error {

// Read the existing runtimes
runtimes := make(map[string]any)
if _, exists := config["runtimes"]; exists {
if config["runtimes"] != nil {
runtimes = config["runtimes"].(map[string]any)
}

Expand Down Expand Up @@ -135,7 +135,7 @@ func (c *Config) RemoveRuntime(name string) error {
}
}

if _, exists := config["runtimes"]; exists {
if config["runtimes"] != nil {
runtimes := config["runtimes"].(map[string]any)

delete(runtimes, name)
Expand Down Expand Up @@ -203,7 +203,7 @@ func (c *Config) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) {
cfg := *c

var runtimes map[string]any
if _, ok := cfg["runtimes"]; ok {
if cfg["runtimes"] != nil {
runtimes = cfg["runtimes"].(map[string]any)
if r, ok := runtimes[name]; ok {
dr := dockerRuntime(r.(map[string]any))
Expand Down
33 changes: 33 additions & 0 deletions pkg/config/engine/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,39 @@ func TestGetRuntimeConfig(t *testing.T) {
}
}

func TestNullRuntimesFromFile(t *testing.T) {
for _, action := range []string{"add", "remove", "get"} {
t.Run(action, func(t *testing.T) {
configPath := filepath.Join(t.TempDir(), "daemon.json")
require.NoError(t, os.WriteFile(configPath, []byte(`{"runtimes":null,"log-driver":"json-file"}`), 0600))
config, err := New(WithPath(configPath))
require.NoError(t, err)

switch action {
case "add":
require.NoError(t, config.AddRuntime("nvidia", "/usr/bin/nvidia-container-runtime", false))
runtime, err := config.GetRuntimeConfig("nvidia")
require.NoError(t, err)
require.Equal(t, "/usr/bin/nvidia-container-runtime", runtime.GetBinaryPath())
case "remove":
require.NoError(t, config.RemoveRuntime("nvidia"))
case "get":
runtime, err := config.GetRuntimeConfig("nvidia")
require.NoError(t, err)
require.Empty(t, runtime.GetBinaryPath())
}

_, err = config.Save(configPath)
require.NoError(t, err)
contents, err := os.ReadFile(configPath)
require.NoError(t, err)
var saved map[string]any
require.NoError(t, json.Unmarshal(contents, &saved))
require.Equal(t, "json-file", saved["log-driver"])
})
}
}

func TestEnableCDIPreservesFeaturesFromFile(t *testing.T) {
tests := []struct {
name string
Expand Down