diff --git a/pkg/config/config.go b/pkg/config/config.go index f300cd0798e..6f954bf9c2d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -645,17 +645,11 @@ func (c *Config) UpdateFromDropInFile(path string) error { t := new(tomlConfig) t.fromConfig(c) - metadata, err := toml.Decode(string(data), t) + _, err = toml.Decode(string(data), t) if err != nil { return fmt.Errorf("unable to decode configuration %v: %w", path, err) } - runtimesKey := []string{"crio", "runtime", "default_runtime"} - if metadata.IsDefined(runtimesKey...) && - t.Crio.Runtime.RuntimeConfig.DefaultRuntime != defaultRuntime { - delete(c.Runtimes, defaultRuntime) - } - storageOpts = append(storageOpts, t.Crio.RootConfig.StorageOptions...) storageOpts = removeDupStorageOpts(storageOpts) t.Crio.RootConfig.StorageOptions = storageOpts diff --git a/pkg/config/template.go b/pkg/config/template.go index 6c82a070534..9c2be158126 100644 --- a/pkg/config/template.go +++ b/pkg/config/template.go @@ -1064,8 +1064,7 @@ const templateStringCrioRuntimeEnableCriuSupport = `# Globally enable/disable CR const templateStringCrioRuntimeDefaultRuntime = `# default_runtime is the _name_ of the OCI runtime to be used as the default. # default_runtime is the _name_ of the OCI runtime to be used as the default. -# The name is matched against the runtimes map below. If this value is changed, -# the corresponding existing entry from the runtimes map below will be ignored. +# The name is matched against the runtimes map below. {{ $.Comment }}default_runtime = "{{ .DefaultRuntime }}" ` diff --git a/test/config.bats b/test/config.bats index 52c36984ad4..b22eb60add2 100644 --- a/test/config.bats +++ b/test/config.bats @@ -45,14 +45,33 @@ function teardown() { [[ "$output" == *"not a valid logrus"*"wrong-level"* ]] } -@test "replace default runtime should succeed" { +@test "choose different default runtime should succeed" { # when unset CONTAINER_RUNTIMES RES=$("$CRIO_BINARY_PATH" -c "$TESTDATA"/50-crun-default.conf -d "" config 2>&1) # then [[ "$RES" == *"default_runtime = \"crun\""* ]] - [[ "$RES" != *"crio.runtime.runtimes.runc"* ]] + [[ "$RES" == *"crio.runtime.runtimes.runc"* ]] + [[ "$RES" == *"crio.runtime.runtimes.crun"* ]] +} + +@test "runc not existing when default_runtime changed should succeed" { + # when + unset CONTAINER_RUNTIMES + cat << EOF > "$TESTDIR"/50-runc-new-path.conf +[crio.runtime] +default_runtime = "crun" +[crio.runtime.runtimes.runc] +runtime_path = "/not/there" +[crio.runtime.runtimes.crun] +runtime_path="/usr/bin/crun" +EOF + RES=$("$CRIO_BINARY_PATH" -c "$TESTDIR"/50-runc-new-path.conf -d "" config 2>&1) + + # then + [[ "$RES" == *"default_runtime = \"crun\""* ]] + [[ "$RES" == *"crio.runtime.runtimes.runc"* ]] [[ "$RES" == *"crio.runtime.runtimes.crun"* ]] }