types: propagate configuration load errors
if any error happens when loading the default configuration file, report it to the caller. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
8e9ae4fd4b
commit
1f647d954f
15
store.go
15
store.go
|
|
@ -643,8 +643,12 @@ type store struct {
|
|||
// return
|
||||
// }
|
||||
func GetStore(options types.StoreOptions) (Store, error) {
|
||||
defaultOpts, err := types.Options()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if options.RunRoot == "" && options.GraphRoot == "" && options.GraphDriverName == "" && len(options.GraphDriverOptions) == 0 {
|
||||
options = types.Options()
|
||||
options = defaultOpts
|
||||
}
|
||||
|
||||
if options.GraphRoot != "" {
|
||||
|
|
@ -677,9 +681,9 @@ func GetStore(options types.StoreOptions) (Store, error) {
|
|||
case options.RunRoot == "" && options.GraphRoot == "":
|
||||
return nil, errors.Wrap(ErrIncompleteOptions, "no storage runroot or graphroot specified")
|
||||
case options.GraphRoot == "":
|
||||
options.GraphRoot = types.Options().GraphRoot
|
||||
options.GraphRoot = defaultOpts.GraphRoot
|
||||
case options.RunRoot == "":
|
||||
options.RunRoot = types.Options().RunRoot
|
||||
options.RunRoot = defaultOpts.RunRoot
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(options.RunRoot, 0700); err != nil {
|
||||
|
|
@ -3715,7 +3719,10 @@ func ReloadConfigurationFile(configFile string, storeOptions *types.StoreOptions
|
|||
|
||||
// GetDefaultMountOptions returns the default mountoptions defined in container/storage
|
||||
func GetDefaultMountOptions() ([]string, error) {
|
||||
defaultStoreOptions := types.Options()
|
||||
defaultStoreOptions, err := types.Options()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return GetMountOptions(defaultStoreOptions.GraphDriverName, defaultStoreOptions.GraphDriverOptions)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
defaultStoreOptionsOnce sync.Once
|
||||
defaultStoreOptionsOnce sync.Once
|
||||
loadDefaultStoreOptionsErr error
|
||||
)
|
||||
|
||||
func loadDefaultStoreOptions() {
|
||||
|
|
@ -49,12 +50,18 @@ func loadDefaultStoreOptions() {
|
|||
// of the used storage.conf file, by returning defaultConfigFile
|
||||
// If override exists containers/storage uses it by default.
|
||||
defaultConfigFile = defaultOverrideConfigFile
|
||||
ReloadConfigurationFileIfNeeded(defaultOverrideConfigFile, &defaultStoreOptions)
|
||||
if err := ReloadConfigurationFileIfNeeded(defaultOverrideConfigFile, &defaultStoreOptions); err != nil {
|
||||
loadDefaultStoreOptionsErr = err
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !os.IsNotExist(err) {
|
||||
logrus.Warningf("Attempting to use %s, %v", defaultConfigFile, err)
|
||||
}
|
||||
ReloadConfigurationFileIfNeeded(defaultConfigFile, &defaultStoreOptions)
|
||||
if err := ReloadConfigurationFileIfNeeded(defaultConfigFile, &defaultStoreOptions); err != nil {
|
||||
loadDefaultStoreOptionsErr = err
|
||||
return
|
||||
}
|
||||
}
|
||||
// reload could set values to empty for run and graph root if config does not contains anything
|
||||
if defaultStoreOptions.RunRoot == "" {
|
||||
|
|
@ -74,6 +81,9 @@ func defaultStoreOptionsIsolated(rootless bool, rootlessUID int, storageConf str
|
|||
err error
|
||||
)
|
||||
defaultStoreOptionsOnce.Do(loadDefaultStoreOptions)
|
||||
if loadDefaultStoreOptionsErr != nil {
|
||||
return StoreOptions{}, loadDefaultStoreOptionsErr
|
||||
}
|
||||
storageOpts := defaultStoreOptions
|
||||
if rootless && rootlessUID != 0 {
|
||||
storageOpts, err = getRootlessStorageOpts(rootlessUID, storageOpts)
|
||||
|
|
@ -251,40 +261,40 @@ var prevReloadConfig = struct {
|
|||
}{}
|
||||
|
||||
// SetDefaultConfigFilePath sets the default configuration to the specified path
|
||||
func SetDefaultConfigFilePath(path string) {
|
||||
func SetDefaultConfigFilePath(path string) error {
|
||||
defaultConfigFile = path
|
||||
defaultConfigFileSet = true
|
||||
ReloadConfigurationFileIfNeeded(defaultConfigFile, &defaultStoreOptions)
|
||||
return ReloadConfigurationFileIfNeeded(defaultConfigFile, &defaultStoreOptions)
|
||||
}
|
||||
|
||||
func ReloadConfigurationFileIfNeeded(configFile string, storeOptions *StoreOptions) {
|
||||
func ReloadConfigurationFileIfNeeded(configFile string, storeOptions *StoreOptions) error {
|
||||
prevReloadConfig.mutex.Lock()
|
||||
defer prevReloadConfig.mutex.Unlock()
|
||||
|
||||
fi, err := os.Stat(configFile)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
fmt.Printf("Failed to read %s %v\n", configFile, err.Error())
|
||||
}
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
mtime := fi.ModTime()
|
||||
if prevReloadConfig.storeOptions != nil && prevReloadConfig.mod == mtime && prevReloadConfig.configFile == configFile {
|
||||
*storeOptions = *prevReloadConfig.storeOptions
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
ReloadConfigurationFile(configFile, storeOptions)
|
||||
if err := ReloadConfigurationFile(configFile, storeOptions); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
prevReloadConfig.storeOptions = storeOptions
|
||||
prevReloadConfig.mod = mtime
|
||||
prevReloadConfig.configFile = configFile
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadConfigurationFile parses the specified configuration file and overrides
|
||||
// the configuration in storeOptions.
|
||||
func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) {
|
||||
func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) error {
|
||||
config := new(TomlConfig)
|
||||
|
||||
meta, err := toml.DecodeFile(configFile, &config)
|
||||
|
|
@ -296,7 +306,7 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) {
|
|||
} else {
|
||||
if !os.IsNotExist(err) {
|
||||
fmt.Printf("Failed to read %s %v\n", configFile, err.Error())
|
||||
return
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -359,7 +369,7 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) {
|
|||
mappings, err := idtools.NewIDMappings(config.Storage.Options.RemapUser, config.Storage.Options.RemapGroup)
|
||||
if err != nil {
|
||||
fmt.Printf("Error initializing ID mappings for %s:%s %v\n", config.Storage.Options.RemapUser, config.Storage.Options.RemapGroup, err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
storeOptions.UIDMap = mappings.UIDs()
|
||||
storeOptions.GIDMap = mappings.GIDs()
|
||||
|
|
@ -367,16 +377,15 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) {
|
|||
|
||||
uidmap, err := idtools.ParseIDMap([]string{config.Storage.Options.RemapUIDs}, "remap-uids")
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
} else {
|
||||
storeOptions.UIDMap = uidmap
|
||||
return err
|
||||
}
|
||||
gidmap, err := idtools.ParseIDMap([]string{config.Storage.Options.RemapGIDs}, "remap-gids")
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
} else {
|
||||
storeOptions.GIDMap = gidmap
|
||||
return err
|
||||
}
|
||||
|
||||
storeOptions.UIDMap = uidmap
|
||||
storeOptions.GIDMap = gidmap
|
||||
storeOptions.RootAutoNsUser = config.Storage.Options.RootAutoUsernsUser
|
||||
if config.Storage.Options.AutoUsernsMinSize > 0 {
|
||||
storeOptions.AutoNsMinSize = config.Storage.Options.AutoUsernsMinSize
|
||||
|
|
@ -398,11 +407,12 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) {
|
|||
if len(storeOptions.GraphDriverOptions) == 1 && storeOptions.GraphDriverOptions[0] == "" {
|
||||
storeOptions.GraphDriverOptions = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Options() StoreOptions {
|
||||
func Options() (StoreOptions, error) {
|
||||
defaultStoreOptionsOnce.Do(loadDefaultStoreOptions)
|
||||
return defaultStoreOptions
|
||||
return defaultStoreOptions, loadDefaultStoreOptionsErr
|
||||
}
|
||||
|
||||
// Save overwrites the tomlConfig in storage.conf with the given conf
|
||||
|
|
|
|||
Loading…
Reference in New Issue