Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -308,23 +308,9 @@ func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *conta |
| 308 | 308 |
} |
| 309 | 309 |
} |
| 310 | 310 |
|
| 311 |
- p := hostConfig.RestartPolicy |
|
| 312 |
- |
|
| 313 |
- switch p.Name {
|
|
| 314 |
- case "always", "unless-stopped", "no": |
|
| 315 |
- if p.MaximumRetryCount != 0 {
|
|
| 316 |
- return nil, errors.Errorf("maximum retry count cannot be used with restart policy '%s'", p.Name)
|
|
| 317 |
- } |
|
| 318 |
- case "on-failure": |
|
| 319 |
- if p.MaximumRetryCount < 0 {
|
|
| 320 |
- return nil, errors.Errorf("maximum retry count cannot be negative")
|
|
| 321 |
- } |
|
| 322 |
- case "": |
|
| 323 |
- // do nothing |
|
| 324 |
- default: |
|
| 325 |
- return nil, errors.Errorf("invalid restart policy '%s'", p.Name)
|
|
| 311 |
+ if err := validateRestartPolicy(hostConfig.RestartPolicy); err != nil {
|
|
| 312 |
+ return nil, err |
|
| 326 | 313 |
} |
| 327 |
- |
|
| 328 | 314 |
if !hostConfig.Isolation.IsValid() {
|
| 329 | 315 |
return nil, errors.Errorf("invalid isolation '%s' on %s", hostConfig.Isolation, runtime.GOOS)
|
| 330 | 316 |
} |
| ... | ... |
@@ -356,3 +342,22 @@ func validateHealthCheck(healthConfig *containertypes.HealthConfig) error {
|
| 356 | 356 |
} |
| 357 | 357 |
return nil |
| 358 | 358 |
} |
| 359 |
+ |
|
| 360 |
+func validateRestartPolicy(policy containertypes.RestartPolicy) error {
|
|
| 361 |
+ switch policy.Name {
|
|
| 362 |
+ case "always", "unless-stopped", "no": |
|
| 363 |
+ if policy.MaximumRetryCount != 0 {
|
|
| 364 |
+ return errors.Errorf("maximum retry count cannot be used with restart policy '%s'", policy.Name)
|
|
| 365 |
+ } |
|
| 366 |
+ case "on-failure": |
|
| 367 |
+ if policy.MaximumRetryCount < 0 {
|
|
| 368 |
+ return errors.Errorf("maximum retry count cannot be negative")
|
|
| 369 |
+ } |
|
| 370 |
+ case "": |
|
| 371 |
+ // do nothing |
|
| 372 |
+ return nil |
|
| 373 |
+ default: |
|
| 374 |
+ return errors.Errorf("invalid restart policy '%s'", policy.Name)
|
|
| 375 |
+ } |
|
| 376 |
+ return nil |
|
| 377 |
+} |