Ensure storage options are properly initialized

If one of storage GraphRoot or RunRoot are specified, but the
other is not, c/storage will not use the default, and will throw
an error instead. Ensure that in cases where this would happen,
we populate the fields with the c/storage defaults ourselves.

Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
Matthew Heon 2018-12-10 14:12:10 -05:00
parent b6763143be
commit a044e3aa23
1 changed files with 19 additions and 0 deletions

View File

@ -29,9 +29,12 @@ func WithStorageConfig(config storage.StoreOptions) RuntimeOption {
return ErrRuntimeFinalized
}
setField := false
if config.RunRoot != "" {
rt.config.StorageConfig.RunRoot = config.RunRoot
rt.configuredFrom.storageRunRootSet = true
setField = true
}
if config.GraphRoot != "" {
@ -42,16 +45,20 @@ func WithStorageConfig(config storage.StoreOptions) RuntimeOption {
// of the c/storage store by default
rt.config.StaticDir = filepath.Join(config.GraphRoot, "libpod")
rt.configuredFrom.libpodStaticDirSet = true
setField = true
}
if config.GraphDriverName != "" {
rt.config.StorageConfig.GraphDriverName = config.GraphDriverName
rt.configuredFrom.storageGraphDriverSet = true
setField = true
}
if config.GraphDriverOptions != nil {
rt.config.StorageConfig.GraphDriverOptions = make([]string, len(config.GraphDriverOptions))
copy(rt.config.StorageConfig.GraphDriverOptions, config.GraphDriverOptions)
setField = true
}
if config.UIDMap != nil {
@ -64,6 +71,18 @@ func WithStorageConfig(config storage.StoreOptions) RuntimeOption {
copy(rt.config.StorageConfig.GIDMap, config.GIDMap)
}
// If any one of runroot, graphroot, graphdrivername,
// or graphdriveroptions are set, then GraphRoot and RunRoot
// must be set
if setField {
if rt.config.StorageConfig.GraphRoot == "" {
rt.config.StorageConfig.GraphRoot = storage.DefaultStoreOptions.GraphRoot
}
if rt.config.StorageConfig.RunRoot == "" {
rt.config.StorageConfig.RunRoot = storage.DefaultStoreOptions.RunRoot
}
}
return nil
}
}