Merge pull request #2454 from mheon/all_your_defaults_belong_to_libpod

Move all storage configuration defaults into libpod
This commit is contained in:
OpenShift Merge Robot 2019-02-27 14:25:16 +01:00 committed by GitHub
commit 70d3cc2e73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 36 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/rootless"
"github.com/containers/libpod/pkg/util"
"github.com/containers/storage"
"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) {
options := []libpod.RuntimeOption{}
storageOpts, _, err := util.GetDefaultStoreOptions()
if err != nil {
return nil, err
}
storageOpts := storage.StoreOptions{}
storageSet := false
uidmapFlag := c.Flags().Lookup("uidmap")
gidmapFlag := c.Flags().Lookup("gidmap")
@ -43,25 +41,33 @@ func getRuntime(c *cliconfig.PodmanCommand, renumber bool) (*libpod.Runtime, err
storageOpts.UIDMap = mappings.UIDMap
storageOpts.GIDMap = mappings.GIDMap
storageSet = true
}
if c.Flags().Changed("root") {
storageSet = true
storageOpts.GraphRoot = c.GlobalFlags.Root
}
if c.Flags().Changed("runroot") {
storageSet = true
storageOpts.RunRoot = c.GlobalFlags.Runroot
}
if len(storageOpts.RunRoot) > 50 {
return nil, errors.New("the specified runroot is longer than 50 characters")
}
if c.Flags().Changed("storage-driver") {
storageSet = true
storageOpts.GraphDriverName = c.GlobalFlags.StorageDriver
}
if len(c.GlobalFlags.StorageOpts) > 0 {
storageSet = true
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 flag for signature policy?

View File

@ -331,16 +331,13 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
deepcopier.Copy(defaultRuntimeConfig).To(runtime.config)
runtime.config.TmpDir = tmpDir
if rootless.IsRootless() {
// If we're rootless, override the default storage config
storageConf, volumePath, err := util.GetDefaultStoreOptions()
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
storageConf, err := util.GetDefaultStoreOptions()
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 = filepath.Join(storageConf.GraphRoot, "volumes")
configPath := ConfigPath
foundConfig := true

View File

@ -259,15 +259,6 @@ func GetRootlessStorageOpts() (storage.StoreOptions, error) {
return opts, nil
}
// GetRootlessVolumePath returns where all the name volumes will be created in rootless mode
func GetRootlessVolumePath() (string, error) {
dataDir, _, err := GetRootlessDirInfo()
if err != nil {
return "", err
}
return filepath.Join(dataDir, "containers", "storage", "volumes"), nil
}
type tomlOptionsConfig struct {
MountProgram string `toml:"mount_program"`
}
@ -297,25 +288,18 @@ func getTomlStorage(storeOptions *storage.StoreOptions) *tomlConfig {
return config
}
// GetDefaultStoreOptions returns the storage ops for containers and the volume path
// for the volume API
// It also returns the path where all named volumes will be created using the volume API
func GetDefaultStoreOptions() (storage.StoreOptions, string, error) {
// GetDefaultStoreOptions returns the default storage ops for containers
func GetDefaultStoreOptions() (storage.StoreOptions, error) {
var (
defaultRootlessRunRoot string
defaultRootlessGraphRoot string
err error
)
storageOpts := storage.DefaultStoreOptions
volumePath := filepath.Join(storageOpts.GraphRoot, "volumes")
if rootless.IsRootless() {
storageOpts, err = GetRootlessStorageOpts()
if err != nil {
return storageOpts, volumePath, err
}
volumePath, err = GetRootlessVolumePath()
if err != nil {
return storageOpts, volumePath, err
return storageOpts, err
}
}
@ -332,7 +316,7 @@ func GetDefaultStoreOptions() (storage.StoreOptions, string, error) {
os.MkdirAll(filepath.Dir(storageConf), 0755)
file, err := os.OpenFile(storageConf, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
if err != nil {
return storageOpts, volumePath, errors.Wrapf(err, "cannot open %s", storageConf)
return storageOpts, errors.Wrapf(err, "cannot open %s", storageConf)
}
tomlConfiguration := getTomlStorage(&storageOpts)
@ -353,7 +337,7 @@ func GetDefaultStoreOptions() (storage.StoreOptions, string, error) {
}
}
}
return storageOpts, volumePath, nil
return storageOpts, nil
}
// StorageConfigFile returns the path to the storage config file used