mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Extract restart-policy-validation to a function
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
6a7da0b31b
commit
e1809510ca
1 changed files with 21 additions and 16 deletions
|
@ -308,23 +308,9 @@ func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *conta
|
|||
}
|
||||
}
|
||||
|
||||
p := hostConfig.RestartPolicy
|
||||
|
||||
switch p.Name {
|
||||
case "always", "unless-stopped", "no":
|
||||
if p.MaximumRetryCount != 0 {
|
||||
return nil, errors.Errorf("maximum retry count cannot be used with restart policy '%s'", p.Name)
|
||||
}
|
||||
case "on-failure":
|
||||
if p.MaximumRetryCount < 0 {
|
||||
return nil, errors.Errorf("maximum retry count cannot be negative")
|
||||
}
|
||||
case "":
|
||||
// do nothing
|
||||
default:
|
||||
return nil, errors.Errorf("invalid restart policy '%s'", p.Name)
|
||||
if err := validateRestartPolicy(hostConfig.RestartPolicy); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !hostConfig.Isolation.IsValid() {
|
||||
return nil, errors.Errorf("invalid isolation '%s' on %s", hostConfig.Isolation, runtime.GOOS)
|
||||
}
|
||||
|
@ -356,3 +342,22 @@ func validateHealthCheck(healthConfig *containertypes.HealthConfig) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateRestartPolicy(policy containertypes.RestartPolicy) error {
|
||||
switch policy.Name {
|
||||
case "always", "unless-stopped", "no":
|
||||
if policy.MaximumRetryCount != 0 {
|
||||
return errors.Errorf("maximum retry count cannot be used with restart policy '%s'", policy.Name)
|
||||
}
|
||||
case "on-failure":
|
||||
if policy.MaximumRetryCount < 0 {
|
||||
return errors.Errorf("maximum retry count cannot be negative")
|
||||
}
|
||||
case "":
|
||||
// do nothing
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("invalid restart policy '%s'", policy.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue