Skip to content

Commit

Permalink
Returns more than one additional image store
Browse files Browse the repository at this point in the history
Closes containers#2094

Signed-off-by: Mario Loriedo <[email protected]>
  • Loading branch information
l0rd committed Sep 17, 2024
1 parent 10981ab commit 1b58e68
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 11 deletions.
7 changes: 5 additions & 2 deletions types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
additionalStores := 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, additionalStores))
}
for _, s := range config.Storage.Options.AdditionalLayerStores {
storeOptions.GraphDriverOptions = append(storeOptions.GraphDriverOptions, fmt.Sprintf("%s.additionallayerstore=%s", config.Storage.Driver, s))
Expand Down
57 changes: 48 additions & 9 deletions types/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
5 changes: 5 additions & 0 deletions types/storage_imagestores_test.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[storage.options]
additionalimagestores = [
"/var/lib/containers/storage1",
"/var/lib/containers/storage2"
]

0 comments on commit 1b58e68

Please sign in to comment.