Added support for CONTAINERS_STORAGE_CONF override

Signed-off-by: Morten Larsen <mortenlarsens@gmail.com>
This commit is contained in:
mla 2021-05-05 21:28:00 +02:00
parent 39e7061ea7
commit 74a61676d2
4 changed files with 45 additions and 1 deletions

View File

@ -155,6 +155,10 @@ Set options which will be passed to the storage driver. If not set, but
comma-separated list and used instead. If the storage tree has previously been
initialized, these need not be provided.
## ENVIRONMENT OVERRIDES
**CONTAINERS_STORAGE_CONF**
If set will use the configuration file path provided in *$CONTAINERS_STORAGE_CONF* instead of the default `/etc/containers/storage.conf`.
## EXAMPLES
**containers-storage layers -t**

View File

@ -0,0 +1,11 @@
[storage]
# Default Storage Driver
driver = ""
# Primary Read/Write location of container storage
graphroot = "environment_override_graphroot"
# Storage path for rootless users
#
rootless_storage_path = "environment_override_rootless_storage_path"

View File

@ -160,7 +160,14 @@ func expandEnvPath(path string, rootlessUID int) (string, error) {
}
func DefaultConfigFile(rootless bool) (string, error) {
if defaultConfigFileSet || !rootless {
if defaultConfigFileSet {
return defaultConfigFile, nil
}
if path, ok := os.LookupEnv("CONTAINERS_STORAGE_CONF"); ok {
return path, nil
}
if !rootless {
return defaultConfigFile, nil
}

View File

@ -272,3 +272,25 @@ func TestDefaultStoreOpts(t *testing.T) {
assert.Equal(t, storageOpts.GraphRoot, expectedPath)
assert.Equal(t, storageOpts.RootlessStoragePath, expectedPath)
}
func TestStorageConfOverrideEnvironmentDefaultConfigFileRootless(t *testing.T) {
os.Setenv("CONTAINERS_STORAGE_CONF", "default_override_test.conf")
defer os.Unsetenv("CONTAINERS_STORAGE_CONF")
defaultFile, err := DefaultConfigFile(true)
expectedPath := "default_override_test.conf"
assert.NilError(t, err)
assert.Equal(t, defaultFile, expectedPath)
}
func TestStorageConfOverrideEnvironmentDefaultConfigFileRoot(t *testing.T) {
os.Setenv("CONTAINERS_STORAGE_CONF", "default_override_test.conf")
defer os.Unsetenv("CONTAINERS_STORAGE_CONF")
defaultFile, err := DefaultConfigFile(false)
expectedPath := "default_override_test.conf"
assert.NilError(t, err)
assert.Equal(t, defaultFile, expectedPath)
}