Skip to content

Commit

Permalink
Added support for CONTAINERS_STORAGE_CONF override
Browse files Browse the repository at this point in the history
Signed-off-by: Morten Larsen <[email protected]>
  • Loading branch information
molar committed Jun 9, 2021
1 parent 39e7061 commit 74a6167
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/containers-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
11 changes: 11 additions & 0 deletions types/default_override_test.conf
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 8 additions & 1 deletion types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
22 changes: 22 additions & 0 deletions types/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 74a6167

Please sign in to comment.