From d21a962ef655fbefec055c3e1a105151d700c62d Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Wed, 31 Mar 2021 16:03:37 -0400 Subject: [PATCH] ReloadConfigurationFile should Reset storage options Currently in Podman if we reset the CONTAINERS_STORAGE_CONF path, we get the graph driver options from the original config file as well as the options from the override path. This PR resets the storageconf to the initial state when called multiple times. Also if user sets STORAGE_OPTS="" then we should use it to override all other storage options. Signed-off-by: Daniel J Walsh --- types/options.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/types/options.go b/types/options.go index 007c5288bf..3e09ee5469 100644 --- a/types/options.go +++ b/types/options.go @@ -278,6 +278,7 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) { fmt.Printf("Failed to parse %s %v\n", configFile, err.Error()) return } + storeOptions.GraphDriverName = "" if config.Storage.Driver != "" { storeOptions.GraphDriverName = config.Storage.Driver } @@ -288,15 +289,20 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) { if storeOptions.GraphDriverName == "" { logrus.Errorf("The storage 'driver' option must be set in %s, guarantee proper operation.", configFile) } + storeOptions.RunRoot = "" if config.Storage.RunRoot != "" { storeOptions.RunRoot = config.Storage.RunRoot } + storeOptions.GraphRoot = "" if config.Storage.GraphRoot != "" { storeOptions.GraphRoot = config.Storage.GraphRoot } + storeOptions.RootlessStoragePath = "" if config.Storage.RootlessStoragePath != "" { storeOptions.RootlessStoragePath = config.Storage.RootlessStoragePath } + // Reset GraphDriverOptions in case this function is called multiple times. + storeOptions.GraphDriverOptions = []string{} for _, s := range config.Storage.Options.AdditionalImageStores { storeOptions.GraphDriverOptions = append(storeOptions.GraphDriverOptions, fmt.Sprintf("%s.imagestore=%s", config.Storage.Driver, s)) } @@ -334,30 +340,34 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) { storeOptions.GIDMap = mappings.GIDs() } + storeOptions.UIDMap = nil uidmap, err := idtools.ParseIDMap([]string{config.Storage.Options.RemapUIDs}, "remap-uids") if err != nil { fmt.Print(err) } else { - storeOptions.UIDMap = append(storeOptions.UIDMap, uidmap...) + storeOptions.UIDMap = uidmap } + storeOptions.GIDMap = nil gidmap, err := idtools.ParseIDMap([]string{config.Storage.Options.RemapGIDs}, "remap-gids") if err != nil { fmt.Print(err) } else { - storeOptions.GIDMap = append(storeOptions.GIDMap, gidmap...) + storeOptions.GIDMap = gidmap } storeOptions.RootAutoNsUser = config.Storage.Options.RootAutoUsernsUser + storeOptions.AutoNsMinSize = 0 if config.Storage.Options.AutoUsernsMinSize > 0 { storeOptions.AutoNsMinSize = config.Storage.Options.AutoUsernsMinSize } + storeOptions.AutoNsMaxSize = 0 if config.Storage.Options.AutoUsernsMaxSize > 0 { storeOptions.AutoNsMaxSize = config.Storage.Options.AutoUsernsMaxSize } storeOptions.GraphDriverOptions = append(storeOptions.GraphDriverOptions, cfg.GetGraphDriverOptions(storeOptions.GraphDriverName, config.Storage.Options)...) - if os.Getenv("STORAGE_OPTS") != "" { - storeOptions.GraphDriverOptions = append(storeOptions.GraphDriverOptions, strings.Split(os.Getenv("STORAGE_OPTS"), ",")...) + if opts, ok := os.LookupEnv("STORAGE_OPTS"); ok { + storeOptions.GraphDriverOptions = strings.Split(opts, ",") } if len(storeOptions.GraphDriverOptions) == 1 && storeOptions.GraphDriverOptions[0] == "" { storeOptions.GraphDriverOptions = nil