mirror of
https://github.com/containers/podman.git
synced 2025-05-21 17:16:22 +08:00
Move all storage configuration defaults into libpod
Instead of passing in defaults via WithStorageConfig after computing them in cmd/podman/libpodruntime, do all defaults in libpod itself. This can alleviate ordering issues which caused settings in the libpod config (most notably, volume path) to be ignored. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
|
"github.com/containers/storage"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,11 +21,8 @@ func GetRuntime(c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
|
|||||||
|
|
||||||
func getRuntime(c *cliconfig.PodmanCommand, renumber bool) (*libpod.Runtime, error) {
|
func getRuntime(c *cliconfig.PodmanCommand, renumber bool) (*libpod.Runtime, error) {
|
||||||
options := []libpod.RuntimeOption{}
|
options := []libpod.RuntimeOption{}
|
||||||
|
storageOpts := storage.StoreOptions{}
|
||||||
storageOpts, _, err := util.GetDefaultStoreOptions()
|
storageSet := false
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
uidmapFlag := c.Flags().Lookup("uidmap")
|
uidmapFlag := c.Flags().Lookup("uidmap")
|
||||||
gidmapFlag := c.Flags().Lookup("gidmap")
|
gidmapFlag := c.Flags().Lookup("gidmap")
|
||||||
@ -43,25 +41,33 @@ func getRuntime(c *cliconfig.PodmanCommand, renumber bool) (*libpod.Runtime, err
|
|||||||
storageOpts.UIDMap = mappings.UIDMap
|
storageOpts.UIDMap = mappings.UIDMap
|
||||||
storageOpts.GIDMap = mappings.GIDMap
|
storageOpts.GIDMap = mappings.GIDMap
|
||||||
|
|
||||||
|
storageSet = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Flags().Changed("root") {
|
if c.Flags().Changed("root") {
|
||||||
|
storageSet = true
|
||||||
storageOpts.GraphRoot = c.GlobalFlags.Root
|
storageOpts.GraphRoot = c.GlobalFlags.Root
|
||||||
}
|
}
|
||||||
if c.Flags().Changed("runroot") {
|
if c.Flags().Changed("runroot") {
|
||||||
|
storageSet = true
|
||||||
storageOpts.RunRoot = c.GlobalFlags.Runroot
|
storageOpts.RunRoot = c.GlobalFlags.Runroot
|
||||||
}
|
}
|
||||||
if len(storageOpts.RunRoot) > 50 {
|
if len(storageOpts.RunRoot) > 50 {
|
||||||
return nil, errors.New("the specified runroot is longer than 50 characters")
|
return nil, errors.New("the specified runroot is longer than 50 characters")
|
||||||
}
|
}
|
||||||
if c.Flags().Changed("storage-driver") {
|
if c.Flags().Changed("storage-driver") {
|
||||||
|
storageSet = true
|
||||||
storageOpts.GraphDriverName = c.GlobalFlags.StorageDriver
|
storageOpts.GraphDriverName = c.GlobalFlags.StorageDriver
|
||||||
}
|
}
|
||||||
if len(c.GlobalFlags.StorageOpts) > 0 {
|
if len(c.GlobalFlags.StorageOpts) > 0 {
|
||||||
|
storageSet = true
|
||||||
storageOpts.GraphDriverOptions = c.GlobalFlags.StorageOpts
|
storageOpts.GraphDriverOptions = c.GlobalFlags.StorageOpts
|
||||||
}
|
}
|
||||||
|
|
||||||
options = append(options, libpod.WithStorageConfig(storageOpts))
|
// Only set this if the user changes storage config on the command line
|
||||||
|
if storageSet {
|
||||||
|
options = append(options, libpod.WithStorageConfig(storageOpts))
|
||||||
|
}
|
||||||
|
|
||||||
// TODO CLI flags for image config?
|
// TODO CLI flags for image config?
|
||||||
// TODO CLI flag for signature policy?
|
// TODO CLI flag for signature policy?
|
||||||
|
@ -331,16 +331,13 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
|
|||||||
deepcopier.Copy(defaultRuntimeConfig).To(runtime.config)
|
deepcopier.Copy(defaultRuntimeConfig).To(runtime.config)
|
||||||
runtime.config.TmpDir = tmpDir
|
runtime.config.TmpDir = tmpDir
|
||||||
|
|
||||||
if rootless.IsRootless() {
|
storageConf, volumePath, err := util.GetDefaultStoreOptions()
|
||||||
// If we're rootless, override the default storage config
|
if err != nil {
|
||||||
storageConf, volumePath, err := util.GetDefaultStoreOptions()
|
return nil, errors.Wrapf(err, "error retrieving rootless storage config")
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "error retrieving rootless storage config")
|
|
||||||
}
|
|
||||||
runtime.config.StorageConfig = storageConf
|
|
||||||
runtime.config.StaticDir = filepath.Join(storageConf.GraphRoot, "libpod")
|
|
||||||
runtime.config.VolumePath = volumePath
|
|
||||||
}
|
}
|
||||||
|
runtime.config.StorageConfig = storageConf
|
||||||
|
runtime.config.StaticDir = filepath.Join(storageConf.GraphRoot, "libpod")
|
||||||
|
runtime.config.VolumePath = volumePath
|
||||||
|
|
||||||
configPath := ConfigPath
|
configPath := ConfigPath
|
||||||
foundConfig := true
|
foundConfig := true
|
||||||
|
Reference in New Issue
Block a user