mirror of
https://github.com/containers/podman.git
synced 2025-08-26 03:01:31 +08:00
Add --restart flag to pod create
Add --restart flag to pod create to allow users to set the restart policy for the pod, which applies to all the containers in the pod. This reuses the restart policy already there for containers and has the same restart policy options. Add "never" to the restart policy options to match k8s syntax. It is a synonym for "no" and does the exact same thing where the containers are not restarted once exited. Only the containers that have exited will be restarted based on the restart policy, running containers will not be restarted when an exited container is restarted in the same pod (same as is done in k8s). Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
This commit is contained in:
@ -808,27 +808,12 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions
|
||||
s.OOMScoreAdj = c.OOMScoreAdj
|
||||
}
|
||||
if c.Restart != "" {
|
||||
splitRestart := strings.Split(c.Restart, ":")
|
||||
switch len(splitRestart) {
|
||||
case 1:
|
||||
// No retries specified
|
||||
case 2:
|
||||
if strings.ToLower(splitRestart[0]) != "on-failure" {
|
||||
return errors.New("restart policy retries can only be specified with on-failure restart policy")
|
||||
}
|
||||
retries, err := strconv.Atoi(splitRestart[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing restart policy retry count: %w", err)
|
||||
}
|
||||
if retries < 0 {
|
||||
return errors.New("must specify restart policy retry count as a number greater than 0")
|
||||
}
|
||||
var retriesUint = uint(retries)
|
||||
s.RestartRetries = &retriesUint
|
||||
default:
|
||||
return errors.New("invalid restart policy: may specify retries at most once")
|
||||
policy, retries, err := util.ParseRestartPolicy(c.Restart)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.RestartPolicy = splitRestart[0]
|
||||
s.RestartPolicy = policy
|
||||
s.RestartRetries = &retries
|
||||
}
|
||||
|
||||
if len(s.Secrets) == 0 || len(c.Secrets) != 0 {
|
||||
|
Reference in New Issue
Block a user