diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-05-03 23:14:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-03 23:14:12 +0200 |
commit | 4aa90145bf611a7bc08ddff7e061a630154e8b40 (patch) | |
tree | 01dc345c05b6ef2c5416eb169f0388c3afb4feb1 /libpod/options.go | |
parent | 2658e870d21dc03096740f17fa869463136d3fae (diff) | |
parent | d3286952e6f99b3c1f8ba177d8caddc9544adea4 (diff) | |
download | podman-4aa90145bf611a7bc08ddff7e061a630154e8b40.tar.gz podman-4aa90145bf611a7bc08ddff7e061a630154e8b40.tar.bz2 podman-4aa90145bf611a7bc08ddff7e061a630154e8b40.zip |
Merge pull request #2826 from mheon/restart_policy
Add restart policy for containers
Diffstat (limited to 'libpod/options.go')
-rw-r--r-- | libpod/options.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libpod/options.go b/libpod/options.go index 86c04db09..7ec7dfe63 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -1239,6 +1239,41 @@ func WithUseImageHosts() CtrCreateOption { } } +// WithRestartPolicy sets the container's restart policy. Valid values are +// "no", "on-failure", and "always". The empty string is allowed, and will be +// equivalent to "no". +func WithRestartPolicy(policy string) CtrCreateOption { + return func(ctr *Container) error { + if ctr.valid { + return ErrCtrFinalized + } + + switch policy { + case RestartPolicyNone, RestartPolicyNo, RestartPolicyOnFailure, RestartPolicyAlways: + ctr.config.RestartPolicy = policy + default: + return errors.Wrapf(ErrInvalidArg, "%q is not a valid restart policy", policy) + } + + return nil + } +} + +// WithRestartRetries sets the number of retries to use when restarting a +// container with the "on-failure" restart policy. +// 0 is an allowed value, and indicates infinite retries. +func WithRestartRetries(tries uint) CtrCreateOption { + return func(ctr *Container) error { + if ctr.valid { + return ErrCtrFinalized + } + + ctr.config.RestartRetries = tries + + return nil + } +} + // withIsInfra sets the container to be an infra container. This means the container will be sometimes hidden // and expected to be the first container in the pod. func withIsInfra() CtrCreateOption { |