diff --git a/daemon/config/config.go b/daemon/config/config.go index 80dd0bc740..339acf2fc3 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -600,16 +600,16 @@ func Validate(config *Config) error { return err } } - // validate MaxConcurrentDownloads + + // TODO(thaJeztah) Validations below should not accept "0" to be valid; see Validate() for a more in-depth description of this problem if config.MaxConcurrentDownloads != nil && *config.MaxConcurrentDownloads < 0 { return fmt.Errorf("invalid max concurrent downloads: %d", *config.MaxConcurrentDownloads) } - // validate MaxConcurrentUploads if config.MaxConcurrentUploads != nil && *config.MaxConcurrentUploads < 0 { return fmt.Errorf("invalid max concurrent uploads: %d", *config.MaxConcurrentUploads) } - if err := ValidateMaxDownloadAttempts(config); err != nil { - return err + if config.MaxDownloadAttempts != nil && *config.MaxDownloadAttempts < 0 { + return fmt.Errorf("invalid max download attempts: %d", *config.MaxDownloadAttempts) } // validate that "default" runtime is not reset @@ -642,14 +642,6 @@ func Validate(config *Config) error { return config.ValidatePlatformConfig() } -// ValidateMaxDownloadAttempts validates if the max-download-attempts is within the valid range -func ValidateMaxDownloadAttempts(config *Config) error { - if config.MaxDownloadAttempts != nil && *config.MaxDownloadAttempts <= 0 { - return fmt.Errorf("invalid max download attempts: %d", *config.MaxDownloadAttempts) - } - return nil -} - // GetDefaultRuntimeName returns the current default runtime func (conf *Config) GetDefaultRuntimeName() string { conf.Lock() diff --git a/daemon/config/config_test.go b/daemon/config/config_test.go index b5ec03cf13..a982ea2920 100644 --- a/daemon/config/config_test.go +++ b/daemon/config/config_test.go @@ -309,15 +309,18 @@ func TestValidateConfigurationErrors(t *testing.T) { }, expectedErr: "invalid max download attempts: -10", }, - { - name: "zero max-download-attempts", - config: &Config{ - CommonConfig: CommonConfig{ - MaxDownloadAttempts: intPtr(0), + // TODO(thaJeztah) temporarily excluding this test as it assumes defaults are set before validating and applying updated configs + /* + { + name: "zero max-download-attempts", + config: &Config{ + CommonConfig: CommonConfig{ + MaxDownloadAttempts: intPtr(0), + }, }, + expectedErr: "invalid max download attempts: 0", }, - expectedErr: "invalid max download attempts: 0", - }, + */ { name: "generic resource without =", config: &Config{ diff --git a/daemon/reload.go b/daemon/reload.go index edfd623f8d..368ec53ff2 100644 --- a/daemon/reload.go +++ b/daemon/reload.go @@ -56,9 +56,7 @@ func (daemon *Daemon) Reload(conf *config.Config) (err error) { } daemon.reloadDebug(conf, attributes) daemon.reloadMaxConcurrentDownloadsAndUploads(conf, attributes) - if err := daemon.reloadMaxDownloadAttempts(conf, attributes); err != nil { - return err - } + daemon.reloadMaxDownloadAttempts(conf, attributes) daemon.reloadShutdownTimeout(conf, attributes) daemon.reloadFeatures(conf, attributes) @@ -124,23 +122,17 @@ func (daemon *Daemon) reloadMaxConcurrentDownloadsAndUploads(conf *config.Config // reloadMaxDownloadAttempts updates configuration with max concurrent // download attempts when a connection is lost and updates the passed attributes -func (daemon *Daemon) reloadMaxDownloadAttempts(conf *config.Config, attributes map[string]string) error { - if err := config.ValidateMaxDownloadAttempts(conf); err != nil { - return err - } - - // If no value is set for max-download-attempts we assume it is the default value +func (daemon *Daemon) reloadMaxDownloadAttempts(conf *config.Config, attributes map[string]string) { // We always "reset" as the cost is lightweight and easy to maintain. maxDownloadAttempts := config.DefaultDownloadAttempts if conf.IsValueSet("max-download-attempts") && conf.MaxDownloadAttempts != nil { maxDownloadAttempts = *conf.MaxDownloadAttempts } daemon.configStore.MaxDownloadAttempts = &maxDownloadAttempts - logrus.Debugf("Reset Max Download Attempts: %d", *daemon.configStore.MaxDownloadAttempts) // prepare reload event attributes with updatable configurations attributes["max-download-attempts"] = fmt.Sprintf("%d", *daemon.configStore.MaxDownloadAttempts) - return nil + logrus.Debug("Reset Max Download Attempts: ", attributes["max-download-attempts"]) } // reloadShutdownTimeout updates configuration with daemon shutdown timeout option