Browse code

Extract healthcheck-validation to a function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2018/12/19 09:09:06
Showing 1 changed files
... ...
@@ -268,23 +268,8 @@ func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *conta
268 268
 			}
269 269
 		}
270 270
 
271
-		// Validate the healthcheck params of Config
272
-		if config.Healthcheck != nil {
273
-			if config.Healthcheck.Interval != 0 && config.Healthcheck.Interval < containertypes.MinimumDuration {
274
-				return nil, errors.Errorf("Interval in Healthcheck cannot be less than %s", containertypes.MinimumDuration)
275
-			}
276
-
277
-			if config.Healthcheck.Timeout != 0 && config.Healthcheck.Timeout < containertypes.MinimumDuration {
278
-				return nil, errors.Errorf("Timeout in Healthcheck cannot be less than %s", containertypes.MinimumDuration)
279
-			}
280
-
281
-			if config.Healthcheck.Retries < 0 {
282
-				return nil, errors.Errorf("Retries in Healthcheck cannot be negative")
283
-			}
284
-
285
-			if config.Healthcheck.StartPeriod != 0 && config.Healthcheck.StartPeriod < containertypes.MinimumDuration {
286
-				return nil, errors.Errorf("StartPeriod in Healthcheck cannot be less than %s", containertypes.MinimumDuration)
287
-			}
271
+		if err := validateHealthCheck(config.Healthcheck); err != nil {
272
+			return nil, err
288 273
 		}
289 274
 	}
290 275
 
... ...
@@ -351,3 +336,23 @@ func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *conta
351 351
 	}
352 352
 	return warnings, err
353 353
 }
354
+
355
+// validateHealthCheck validates the healthcheck params of Config
356
+func validateHealthCheck(healthConfig *containertypes.HealthConfig) error {
357
+	if healthConfig == nil {
358
+		return nil
359
+	}
360
+	if healthConfig.Interval != 0 && healthConfig.Interval < containertypes.MinimumDuration {
361
+		return errors.Errorf("Interval in Healthcheck cannot be less than %s", containertypes.MinimumDuration)
362
+	}
363
+	if healthConfig.Timeout != 0 && healthConfig.Timeout < containertypes.MinimumDuration {
364
+		return errors.Errorf("Timeout in Healthcheck cannot be less than %s", containertypes.MinimumDuration)
365
+	}
366
+	if healthConfig.Retries < 0 {
367
+		return errors.Errorf("Retries in Healthcheck cannot be negative")
368
+	}
369
+	if healthConfig.StartPeriod != 0 && healthConfig.StartPeriod < containertypes.MinimumDuration {
370
+		return errors.Errorf("StartPeriod in Healthcheck cannot be less than %s", containertypes.MinimumDuration)
371
+	}
372
+	return nil
373
+}