diff options
author | Matthew Heon <mheon@redhat.com> | 2018-12-02 14:21:22 -0500 |
---|---|---|
committer | Matthew Heon <mheon@redhat.com> | 2018-12-02 14:21:22 -0500 |
commit | 92ff83f5b9dd00ff91dc8c3d6b48f1e0b5c5f3e2 (patch) | |
tree | e87c5909794f1b64c85b88420cb1d6d2a322edc9 /libpod | |
parent | aa7ce33b7a7698d220f258bf9b29068be6fdb531 (diff) | |
download | podman-92ff83f5b9dd00ff91dc8c3d6b48f1e0b5c5f3e2.tar.gz podman-92ff83f5b9dd00ff91dc8c3d6b48f1e0b5c5f3e2.tar.bz2 podman-92ff83f5b9dd00ff91dc8c3d6b48f1e0b5c5f3e2.zip |
Set default paths from DB if not explicitly overridden
If the DB contains default paths, and the user has not explicitly
overridden them, use the paths in the DB over our own defaults.
The DB validates these paths, so it would error and prevent
operation if they did not match. As such, instead of erroring, we
can use the DB's paths instead of our own.
Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/in_memory_state.go | 5 | ||||
-rw-r--r-- | libpod/runtime.go | 26 |
2 files changed, 28 insertions, 3 deletions
diff --git a/libpod/in_memory_state.go b/libpod/in_memory_state.go index 8cd2f47b9..77eba0cc6 100644 --- a/libpod/in_memory_state.go +++ b/libpod/in_memory_state.go @@ -73,9 +73,10 @@ func (s *InMemoryState) Refresh() error { return nil } -// GetDBConfig is not implemented for the in-memory state +// GetDBConfig is not implemented for in-memory state. +// As we do not store a config, return an empty one. func (s *InMemoryState) GetDBConfig() (*DBConfig, error) { - return nil, ErrNotImplemented + return &DBConfig{}, nil } // ValidateDBConfig is not implemented for the in-memory state. diff --git a/libpod/runtime.go b/libpod/runtime.go index 1e05810fb..e01fa781b 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -484,7 +484,31 @@ func makeRuntime(runtime *Runtime) (err error) { return errors.Wrapf(ErrInvalidArg, "unrecognized state type passed") } - // Validate our config against the database + // Grab config from the database so we can reset some defaults + dbConfig, err := runtime.state.GetDBConfig() + if err != nil { + return errors.Wrapf(err, "error retrieving runtime configuration from database") + } + + // Reset defaults if they were not explicitly set + if !runtime.configuredFrom.storageGraphDriverSet && dbConfig.GraphDriver != "" { + runtime.config.StorageConfig.GraphDriverName = dbConfig.GraphDriver + } + if !runtime.configuredFrom.storageGraphRootSet && dbConfig.StorageRoot != "" { + runtime.config.StorageConfig.GraphRoot = dbConfig.StorageRoot + } + if !runtime.configuredFrom.storageRunRootSet && dbConfig.StorageTmp != "" { + runtime.config.StorageConfig.RunRoot = dbConfig.StorageTmp + } + if !runtime.configuredFrom.libpodStaticDirSet && dbConfig.LibpodRoot != "" { + runtime.config.StaticDir = dbConfig.LibpodRoot + } + if !runtime.configuredFrom.libpodTmpDirSet && dbConfig.LibpodTmp != "" { + runtime.config.TmpDir = dbConfig.LibpodTmp + } + + // Validate our config against the database, now that we've set our + // final storage configuration if err := runtime.state.ValidateDBConfig(runtime); err != nil { return err } |