mirror of
https://github.com/containers/podman.git
synced 2025-10-18 03:33:32 +08:00
Move rootless storage config into libpod
Previous commits ensured that we would use database-configured paths if not explicitly overridden. However, our runtime generation did unconditionally override storage config, which made this useless. Move rootless storage configuration setup to libpod, and change storage setup so we only override if a setting is explicitly set, so we can still override what we want. Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
@ -66,7 +66,7 @@ func createCmd(c *cli.Context) error {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
|
||||
runtime, err := libpodruntime.GetContainerRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
@ -11,32 +11,18 @@ import (
|
||||
|
||||
// GetRuntime generates a new libpod runtime configured by command line options
|
||||
func GetRuntime(c *cli.Context) (*libpod.Runtime, error) {
|
||||
storageOpts, err := util.GetDefaultStoreOptions()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return GetRuntimeWithStorageOpts(c, &storageOpts)
|
||||
}
|
||||
|
||||
// GetContainerRuntime generates a new libpod runtime configured by command line options for containers
|
||||
func GetContainerRuntime(c *cli.Context) (*libpod.Runtime, error) {
|
||||
mappings, err := util.ParseIDMapping(c.StringSlice("uidmap"), c.StringSlice("gidmap"), c.String("subuidmap"), c.String("subgidmap"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
storageOpts, err := util.GetDefaultStoreOptions()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
storageOpts.UIDMap = mappings.UIDMap
|
||||
storageOpts.GIDMap = mappings.GIDMap
|
||||
return GetRuntimeWithStorageOpts(c, &storageOpts)
|
||||
}
|
||||
|
||||
// GetRuntime generates a new libpod runtime configured by command line options
|
||||
func GetRuntimeWithStorageOpts(c *cli.Context, storageOpts *storage.StoreOptions) (*libpod.Runtime, error) {
|
||||
storageOpts := new(storage.StoreOptions)
|
||||
options := []libpod.RuntimeOption{}
|
||||
|
||||
if c.IsSet("uidmap") || c.IsSet("gidmap") || c.IsSet("subuidmap") || c.IsSet("subgidmap") {
|
||||
mappings, err := util.ParseIDMapping(c.StringSlice("uidmap"), c.StringSlice("gidmap"), c.String("subuidmap"), c.String("subgidmap"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
storageOpts.UIDMap = mappings.UIDMap
|
||||
storageOpts.GIDMap = mappings.GIDMap
|
||||
}
|
||||
|
||||
if c.GlobalIsSet("root") {
|
||||
storageOpts.GraphRoot = c.GlobalString("root")
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func runCmd(c *cli.Context) error {
|
||||
rootless.SetSkipStorageSetup(true)
|
||||
}
|
||||
|
||||
runtime, err := libpodruntime.GetContainerRuntime(c)
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
@ -29,18 +29,18 @@ func WithStorageConfig(config storage.StoreOptions) RuntimeOption {
|
||||
return ErrRuntimeFinalized
|
||||
}
|
||||
|
||||
rt.config.StorageConfig.RunRoot = config.RunRoot
|
||||
if config.RunRoot != "" {
|
||||
rt.config.StorageConfig.RunRoot = config.RunRoot
|
||||
rt.configuredFrom.storageRunRootSet = true
|
||||
}
|
||||
|
||||
rt.config.StorageConfig.GraphRoot = config.GraphRoot
|
||||
if config.GraphRoot != "" {
|
||||
rt.config.StorageConfig.GraphRoot = config.GraphRoot
|
||||
rt.configuredFrom.storageGraphRootSet = true
|
||||
}
|
||||
|
||||
rt.config.StorageConfig.GraphDriverName = config.GraphDriverName
|
||||
if config.GraphDriverName != "" {
|
||||
rt.config.StorageConfig.GraphDriverName = config.GraphDriverName
|
||||
rt.configuredFrom.storageGraphDriverSet = true
|
||||
}
|
||||
|
||||
@ -51,14 +51,20 @@ func WithStorageConfig(config storage.StoreOptions) RuntimeOption {
|
||||
rt.configuredFrom.libpodStaticDirSet = true
|
||||
}
|
||||
|
||||
rt.config.StorageConfig.GraphDriverOptions = make([]string, len(config.GraphDriverOptions))
|
||||
copy(rt.config.StorageConfig.GraphDriverOptions, config.GraphDriverOptions)
|
||||
if config.GraphDriverOptions != nil {
|
||||
rt.config.StorageConfig.GraphDriverOptions = make([]string, len(config.GraphDriverOptions))
|
||||
copy(rt.config.StorageConfig.GraphDriverOptions, config.GraphDriverOptions)
|
||||
}
|
||||
|
||||
rt.config.StorageConfig.UIDMap = make([]idtools.IDMap, len(config.UIDMap))
|
||||
copy(rt.config.StorageConfig.UIDMap, config.UIDMap)
|
||||
if config.UIDMap != nil {
|
||||
rt.config.StorageConfig.UIDMap = make([]idtools.IDMap, len(config.UIDMap))
|
||||
copy(rt.config.StorageConfig.UIDMap, config.UIDMap)
|
||||
}
|
||||
|
||||
rt.config.StorageConfig.GIDMap = make([]idtools.IDMap, len(config.GIDMap))
|
||||
copy(rt.config.StorageConfig.GIDMap, config.GIDMap)
|
||||
if config.GIDMap != nil {
|
||||
rt.config.StorageConfig.GIDMap = make([]idtools.IDMap, len(config.GIDMap))
|
||||
copy(rt.config.StorageConfig.GIDMap, config.GIDMap)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -278,6 +278,15 @@ 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, err := util.GetDefaultRootlessStoreOptions()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error retrieving rootless storage config")
|
||||
}
|
||||
runtime.config.StorageConfig = storageConf
|
||||
}
|
||||
|
||||
configPath := ConfigPath
|
||||
foundConfig := true
|
||||
rootlessConfigPath := ""
|
||||
|
@ -313,33 +313,31 @@ func getTomlStorage(storeOptions *storage.StoreOptions) *tomlConfig {
|
||||
return config
|
||||
}
|
||||
|
||||
// GetDefaultStoreOptions returns the storage ops for containers
|
||||
func GetDefaultStoreOptions() (storage.StoreOptions, error) {
|
||||
storageOpts := storage.DefaultStoreOptions
|
||||
if rootless.IsRootless() {
|
||||
var err error
|
||||
storageOpts, err = GetRootlessStorageOpts()
|
||||
// GetDefaultStoreOptions returns the storage ops for containers.
|
||||
func GetDefaultRootlessStoreOptions() (storage.StoreOptions, error) {
|
||||
var err error
|
||||
storageOpts, err := GetRootlessStorageOpts()
|
||||
if err != nil {
|
||||
return storageOpts, err
|
||||
}
|
||||
|
||||
storageConf := filepath.Join(os.Getenv("HOME"), ".config/containers/storage.conf")
|
||||
if _, err := os.Stat(storageConf); err == nil {
|
||||
storage.ReloadConfigurationFile(storageConf, &storageOpts)
|
||||
} else if os.IsNotExist(err) {
|
||||
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, err
|
||||
return storageOpts, errors.Wrapf(err, "cannot open %s", storageConf)
|
||||
}
|
||||
|
||||
storageConf := filepath.Join(os.Getenv("HOME"), ".config/containers/storage.conf")
|
||||
if _, err := os.Stat(storageConf); err == nil {
|
||||
storage.ReloadConfigurationFile(storageConf, &storageOpts)
|
||||
} else if os.IsNotExist(err) {
|
||||
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, errors.Wrapf(err, "cannot open %s", storageConf)
|
||||
}
|
||||
|
||||
tomlConfiguration := getTomlStorage(&storageOpts)
|
||||
defer file.Close()
|
||||
enc := toml.NewEncoder(file)
|
||||
if err := enc.Encode(tomlConfiguration); err != nil {
|
||||
os.Remove(storageConf)
|
||||
}
|
||||
tomlConfiguration := getTomlStorage(&storageOpts)
|
||||
defer file.Close()
|
||||
enc := toml.NewEncoder(file)
|
||||
if err := enc.Encode(tomlConfiguration); err != nil {
|
||||
os.Remove(storageConf)
|
||||
}
|
||||
}
|
||||
|
||||
return storageOpts, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user