Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
8 changes: 1 addition & 7 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"

`
Expand Down
23 changes: 21 additions & 2 deletions test/config.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"* ]]
}

Expand Down