diff --git a/types/options.go b/types/options.go index f1a900b8d8..4aaa91c0c0 100644 --- a/types/options.go +++ b/types/options.go @@ -457,8 +457,11 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) erro if config.Storage.RootlessStoragePath != "" { storeOptions.RootlessStoragePath = config.Storage.RootlessStoragePath } - for _, s := range config.Storage.Options.AdditionalImageStores { - storeOptions.GraphDriverOptions = append(storeOptions.GraphDriverOptions, fmt.Sprintf("%s.imagestore=%s", config.Storage.Driver, s)) + if len(config.Storage.Options.AdditionalImageStores) > 0 { + imageStore := config.Storage.Options.AdditionalImageStores[0] + additionalImageStores := strings.Join(config.Storage.Options.AdditionalImageStores, ",") + storeOptions.GraphDriverOptions = append(storeOptions.GraphDriverOptions, fmt.Sprintf("%s.imagestore=%s", config.Storage.Driver, imageStore)) + storeOptions.GraphDriverOptions = append(storeOptions.GraphDriverOptions, fmt.Sprintf("%s.additionalimagestores=%s", config.Storage.Driver, additionalImageStores)) } for _, s := range config.Storage.Options.AdditionalLayerStores { storeOptions.GraphDriverOptions = append(storeOptions.GraphDriverOptions, fmt.Sprintf("%s.additionallayerstore=%s", config.Storage.Driver, s)) diff --git a/types/options_test.go b/types/options_test.go index dd0de0fc9c..01ce065ca6 100644 --- a/types/options_test.go +++ b/types/options_test.go @@ -125,13 +125,52 @@ func TestGetRootlessStorageOpts2(t *testing.T) { } func TestReloadConfigurationFile(t *testing.T) { - content := bytes.NewBufferString("") - logrus.SetOutput(content) - var storageOpts StoreOptions - err := ReloadConfigurationFile("./storage_broken.conf", &storageOpts) - require.NoError(t, err) - assert.Equal(t, storageOpts.RunRoot, "/run/containers/test") - logrus.SetOutput(os.Stderr) - - assert.Equal(t, strings.Contains(content.String(), "Failed to decode the keys [\\\"foo\\\" \\\"storage.options.graphroot\\\"] from \\\"./storage_broken.conf\\\"\""), true) + t.Run("broken", func(t *testing.T) { + content := bytes.NewBufferString("") + logrus.SetOutput(content) + var storageOpts StoreOptions + err := ReloadConfigurationFile("./storage_broken.conf", &storageOpts) + require.NoError(t, err) + assert.Equal(t, storageOpts.RunRoot, "/run/containers/test") + logrus.SetOutput(os.Stderr) + assert.Equal(t, strings.Contains(content.String(), "Failed to decode the keys [\\\"foo\\\" \\\"storage.options.graphroot\\\"] from \\\"./storage_broken.conf\\\"\""), true) + }) + t.Run("imagestore-empty", func(t *testing.T) { + expectedStore := "" + expectedAdditionalStores := "" + var storageOpts StoreOptions + err := ReloadConfigurationFile("./storage_test.conf", &storageOpts) + require.NoError(t, err) + var actualStore, actualAdditionalStores string + for _, o := range storageOpts.GraphDriverOptions { + option := strings.Split(o, "=") + switch option[0] { + case storageOpts.GraphDriverName + ".imagestore": + actualStore = option[1] + case storageOpts.GraphDriverName + ".additionalimagestores": + actualAdditionalStores = option[1] + } + } + assert.Equal(t, actualStore, expectedStore) + assert.Equal(t, actualAdditionalStores, expectedAdditionalStores) + }) + t.Run("imagestore-many", func(t *testing.T) { + expectedStore := "/var/lib/containers/storage1" + expectedAdditionalStores := "/var/lib/containers/storage1,/var/lib/containers/storage2" + var storageOpts StoreOptions + err := ReloadConfigurationFile("./storage_imagestores_test.conf", &storageOpts) + require.NoError(t, err) + var actualStore, actualAdditionalStores string + for _, o := range storageOpts.GraphDriverOptions { + option := strings.Split(o, "=") + switch option[0] { + case storageOpts.GraphDriverName + ".imagestore": + actualStore = option[1] + case storageOpts.GraphDriverName + ".additionalimagestores": + actualAdditionalStores = option[1] + } + } + assert.Equal(t, actualStore, expectedStore) + assert.Equal(t, actualAdditionalStores, expectedAdditionalStores) + }) } diff --git a/types/storage_imagestores_test.conf b/types/storage_imagestores_test.conf new file mode 100644 index 0000000000..5caad38101 --- /dev/null +++ b/types/storage_imagestores_test.conf @@ -0,0 +1,5 @@ +[storage.options] +additionalimagestores = [ + "/var/lib/containers/storage1", + "/var/lib/containers/storage2" +]