diff options
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container.go | 18 | ||||
-rw-r--r-- | libpod/container_internal.go | 8 | ||||
-rw-r--r-- | libpod/define/container.go | 19 | ||||
-rw-r--r-- | libpod/kube.go | 6 | ||||
-rw-r--r-- | libpod/options.go | 2 | ||||
-rw-r--r-- | libpod/runtime_ctr.go | 3 | ||||
-rw-r--r-- | libpod/runtime_ctr_network.go | 12 | ||||
-rw-r--r-- | libpod/runtime_ctr_network_unsupported.go | 12 |
8 files changed, 29 insertions, 51 deletions
diff --git a/libpod/container.go b/libpod/container.go index 65abbfd5e..c49d8feeb 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -84,24 +84,6 @@ func (ns LinuxNS) String() string { } } -// Valid restart policy types. -const ( - // RestartPolicyNone indicates that no restart policy has been requested - // by a container. - RestartPolicyNone = "" - // RestartPolicyNo is identical in function to RestartPolicyNone. - RestartPolicyNo = "no" - // RestartPolicyAlways unconditionally restarts the container. - RestartPolicyAlways = "always" - // RestartPolicyOnFailure restarts the container on non-0 exit code, - // with an optional maximum number of retries. - RestartPolicyOnFailure = "on-failure" - // RestartPolicyUnlessStopped unconditionally restarts unless stopped - // by the user. It is identical to Always except with respect to - // handling of system restart, which Podman does not yet support. - RestartPolicyUnlessStopped = "unless-stopped" -) - // Container is a single OCI container. // All operations on a Container that access state must begin with a call to // syncContainer(). diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 1614211fb..106e2569b 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -219,14 +219,14 @@ func (c *Container) shouldRestart() bool { // If we did not get a restart policy match, return false // Do the same if we're not a policy that restarts. if !c.state.RestartPolicyMatch || - c.config.RestartPolicy == RestartPolicyNo || - c.config.RestartPolicy == RestartPolicyNone { + c.config.RestartPolicy == define.RestartPolicyNo || + c.config.RestartPolicy == define.RestartPolicyNone { return false } // If we're RestartPolicyOnFailure, we need to check retries and exit // code. - if c.config.RestartPolicy == RestartPolicyOnFailure { + if c.config.RestartPolicy == define.RestartPolicyOnFailure { if c.state.ExitCode == 0 { return false } @@ -332,7 +332,7 @@ func (c *Container) syncContainer() error { // Only save back to DB if state changed if c.state.State != oldState { // Check for a restart policy match - if c.config.RestartPolicy != RestartPolicyNone && c.config.RestartPolicy != RestartPolicyNo && + if c.config.RestartPolicy != define.RestartPolicyNone && c.config.RestartPolicy != define.RestartPolicyNo && (oldState == define.ContainerStateRunning || oldState == define.ContainerStatePaused) && (c.state.State == define.ContainerStateStopped || c.state.State == define.ContainerStateExited) && !c.state.StoppedByUser { diff --git a/libpod/define/container.go b/libpod/define/container.go new file mode 100644 index 000000000..5a2ff026f --- /dev/null +++ b/libpod/define/container.go @@ -0,0 +1,19 @@ +package define + +// Valid restart policy types. +const ( + // RestartPolicyNone indicates that no restart policy has been requested + // by a container. + RestartPolicyNone = "" + // RestartPolicyNo is identical in function to RestartPolicyNone. + RestartPolicyNo = "no" + // RestartPolicyAlways unconditionally restarts the container. + RestartPolicyAlways = "always" + // RestartPolicyOnFailure restarts the container on non-0 exit code, + // with an optional maximum number of retries. + RestartPolicyOnFailure = "on-failure" + // RestartPolicyUnlessStopped unconditionally restarts unless stopped + // by the user. It is identical to Always except with respect to + // handling of system restart, which Podman does not yet support. + RestartPolicyUnlessStopped = "unless-stopped" +) diff --git a/libpod/kube.go b/libpod/kube.go index 6feb69fea..407c4ae00 100644 --- a/libpod/kube.go +++ b/libpod/kube.go @@ -83,11 +83,11 @@ func (p *Pod) GenerateForKube() (*v1.Pod, []v1.ServicePort, error) { for _, ctr := range allContainers { if !ctr.IsInfra() { switch ctr.Config().RestartPolicy { - case RestartPolicyAlways: + case define.RestartPolicyAlways: pod.Spec.RestartPolicy = v1.RestartPolicyAlways - case RestartPolicyOnFailure: + case define.RestartPolicyOnFailure: pod.Spec.RestartPolicy = v1.RestartPolicyOnFailure - case RestartPolicyNo: + case define.RestartPolicyNo: pod.Spec.RestartPolicy = v1.RestartPolicyNever default: // some pod create from cmdline, such as "", so set it to Never pod.Spec.RestartPolicy = v1.RestartPolicyNever diff --git a/libpod/options.go b/libpod/options.go index 48888a2f2..85862cc17 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -1364,7 +1364,7 @@ func WithRestartPolicy(policy string) CtrCreateOption { } switch policy { - case RestartPolicyNone, RestartPolicyNo, RestartPolicyOnFailure, RestartPolicyAlways, RestartPolicyUnlessStopped: + case define.RestartPolicyNone, define.RestartPolicyNo, define.RestartPolicyOnFailure, define.RestartPolicyAlways, define.RestartPolicyUnlessStopped: ctr.config.RestartPolicy = policy default: return errors.Wrapf(define.ErrInvalidArg, "%q is not a valid restart policy", policy) diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 057313c82..19690d79b 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -12,6 +12,7 @@ import ( "github.com/containers/common/pkg/config" "github.com/containers/podman/v3/libpod/define" "github.com/containers/podman/v3/libpod/events" + "github.com/containers/podman/v3/libpod/network" "github.com/containers/podman/v3/libpod/shutdown" "github.com/containers/podman/v3/pkg/cgroups" "github.com/containers/podman/v3/pkg/domain/entities/reports" @@ -203,7 +204,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai if len(ctr.config.Networks) > 0 { netNames := make([]string, 0, len(ctr.config.Networks)) for _, nameOrID := range ctr.config.Networks { - netName, err := normalizeNetworkName(r.config, nameOrID) + netName, err := network.NormalizeName(r.config, nameOrID) if err != nil { return nil, err } diff --git a/libpod/runtime_ctr_network.go b/libpod/runtime_ctr_network.go deleted file mode 100644 index 51ed982e2..000000000 --- a/libpod/runtime_ctr_network.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build linux - -package libpod - -import ( - "github.com/containers/common/pkg/config" - "github.com/containers/podman/v3/libpod/network" -) - -func normalizeNetworkName(config *config.Config, nameOrID string) (string, error) { - return network.NormalizeName(config, nameOrID) -} diff --git a/libpod/runtime_ctr_network_unsupported.go b/libpod/runtime_ctr_network_unsupported.go deleted file mode 100644 index fb7e802ac..000000000 --- a/libpod/runtime_ctr_network_unsupported.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !linux - -package libpod - -import ( - "github.com/containers/common/pkg/config" - "github.com/containers/podman/v3/libpod/define" -) - -func normalizeNetworkName(config *config.Config, nameOrID string) (string, error) { - return "", define.ErrNotImplemented -} |