Skip to content

Commit

Permalink
Bug 2012838: fix override storage options from storage.conf
Browse files Browse the repository at this point in the history
Fix https://bugzilla.redhat.com/show_bug.cgi?id=2012838

Merge in the storage_option from drop-in crio.conf to the storage.conf, do not override the configs from storage.conf.
The override leads to configuration of containerruntimeconfig not working.

Signed-off-by: Qi Wang <qiwan@redhat.com>
  • Loading branch information
QiWang19 committed Oct 27, 2021
1 parent b026482 commit cdb1a92
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ func (c *Config) UpdateFromFile(path string) error {
// Returns errors encountered when reading or parsing the files, or nil
// otherwise.
func (c *Config) UpdateFromDropInFile(path string) error {
// keeps the storage options from storage.conf and merge it to crio config
var storageOpts []string
storageOpts = append(storageOpts, c.StorageOptions...)

data, err := ioutil.ReadFile(path)
if err != nil {
return err
Expand All @@ -592,14 +596,16 @@ func (c *Config) UpdateFromDropInFile(path string) error {
delete(c.Runtimes, defaultRuntime)
}

storageOpts = append(storageOpts, t.Crio.RootConfig.StorageOptions...)
t.Crio.RootConfig.StorageOptions = storageOpts
t.toConfig(c)

// Registries are deprecated in cri-o.conf and turned into a NOP.
// Users should use registries.conf instead, so let's log it.
if len(t.Crio.Image.Registries) > 0 {
t.Crio.Image.Registries = nil
logrus.Warnf("Support for the 'registries' option has been dropped but it is referenced in %q. Please use containers-registries.conf(5) for configuring unqualified-search registries instead.", path)
}

t.toConfig(c)
return nil
}

Expand Down
22 changes: 22 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,28 @@ var _ = t.Describe("Config", func() {
Expect(sut.PidsLimit).To(BeEquivalentTo(2048))
})

It("should inherit storage_options from storage.conf", func() {
// Given
f := t.MustTempFile("config")
Expect(ioutil.WriteFile(f,
[]byte(`
[crio]
storage_option = [
"overlay.override_kernel_check=1",
]`,
), 0),
).To(BeNil())
defaultcfg := defaultConfig()
defaultcfg.StorageOptions = []string{"ignore_chown_errors=false"}

// When
err := defaultcfg.UpdateFromFile(f)

// Then
Expect(err).To(BeNil())
Expect(defaultcfg.RootConfig.StorageOptions).To(ContainElements("ignore_chown_errors=false", "overlay.override_kernel_check=1"))
})

It("should succeed with custom runtime", func() {
// Given
f := t.MustTempFile("config")
Expand Down
15 changes: 15 additions & 0 deletions test/config.bats
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,18 @@ function teardown() {
[[ "$RES" == *"crio.runtime.runtimes.runc"* ]]
[[ "$RES" == *"crio.runtime.runtimes.crun"* ]]
}

@test "crio config inherites from storage.conf" {
# given
setup_crio

sed -i '/^\[storage.options\].*/a ignore_chown_errors = "false"' /etc/containers/storage.conf
printf '[crio]\nstorage_option = [\n"overlay.override_kernel_check=1",\n]\n' > "$CRIO_CONFIG_DIR"/00-default

# when
start_crio_no_setup
output=$("${CRIO_STATUS_BINARY_PATH}" --socket="${CRIO_SOCKET}" config)

[[ "$output" == *"overlay.ignore_chown_errors=false"* ]]
sed -i '/ignore_chown_errors = "false"/d' /etc/containers/storage.conf
}

0 comments on commit cdb1a92

Please sign in to comment.