From 6a7da0b31b505d499aa7785195dc43df7b257b5c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 19 Dec 2018 01:09:06 +0100 Subject: [PATCH] Extract healthcheck-validation to a function Signed-off-by: Sebastiaan van Stijn --- daemon/container.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index 1382f5b630..4213c5cca4 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -268,23 +268,8 @@ func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *conta } } - // Validate the healthcheck params of Config - if config.Healthcheck != nil { - if config.Healthcheck.Interval != 0 && config.Healthcheck.Interval < containertypes.MinimumDuration { - return nil, errors.Errorf("Interval in Healthcheck cannot be less than %s", containertypes.MinimumDuration) - } - - if config.Healthcheck.Timeout != 0 && config.Healthcheck.Timeout < containertypes.MinimumDuration { - return nil, errors.Errorf("Timeout in Healthcheck cannot be less than %s", containertypes.MinimumDuration) - } - - if config.Healthcheck.Retries < 0 { - return nil, errors.Errorf("Retries in Healthcheck cannot be negative") - } - - if config.Healthcheck.StartPeriod != 0 && config.Healthcheck.StartPeriod < containertypes.MinimumDuration { - return nil, errors.Errorf("StartPeriod in Healthcheck cannot be less than %s", containertypes.MinimumDuration) - } + if err := validateHealthCheck(config.Healthcheck); err != nil { + return nil, err } } @@ -351,3 +336,23 @@ func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *conta } return warnings, err } + +// validateHealthCheck validates the healthcheck params of Config +func validateHealthCheck(healthConfig *containertypes.HealthConfig) error { + if healthConfig == nil { + return nil + } + if healthConfig.Interval != 0 && healthConfig.Interval < containertypes.MinimumDuration { + return errors.Errorf("Interval in Healthcheck cannot be less than %s", containertypes.MinimumDuration) + } + if healthConfig.Timeout != 0 && healthConfig.Timeout < containertypes.MinimumDuration { + return errors.Errorf("Timeout in Healthcheck cannot be less than %s", containertypes.MinimumDuration) + } + if healthConfig.Retries < 0 { + return errors.Errorf("Retries in Healthcheck cannot be negative") + } + if healthConfig.StartPeriod != 0 && healthConfig.StartPeriod < containertypes.MinimumDuration { + return errors.Errorf("StartPeriod in Healthcheck cannot be less than %s", containertypes.MinimumDuration) + } + return nil +}