summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorPaul Holzinger <paul.holzinger@web.de>2021-03-15 12:55:06 +0100
committerPaul Holzinger <paul.holzinger@web.de>2021-03-15 14:02:04 +0100
commit57e8c66322849ff60e6126616c0c9883a80fb139 (patch)
treedc91b324d82675d66c6b1f37d6ca97c82597ae30 /libpod
parent762148deb6be6925d17bd12f219f7385e1402439 (diff)
downloadpodman-57e8c66322849ff60e6126616c0c9883a80fb139.tar.gz
podman-57e8c66322849ff60e6126616c0c9883a80fb139.tar.bz2
podman-57e8c66322849ff60e6126616c0c9883a80fb139.zip
Do not leak libpod package into the remote client
Some packages used by the remote client imported the libpod package. This is not wanted because it adds unnecessary bloat to the client and also causes problems with platform specific code(linux only), see #9710. The solution is to move the used functions/variables into extra packages which do not import libpod. This change shrinks the remote client size more than 6MB compared to the current master. [NO TESTS NEEDED] I have no idea how to test this properly but with #9710 the cross compile should fail. Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container.go18
-rw-r--r--libpod/container_internal.go8
-rw-r--r--libpod/define/container.go19
-rw-r--r--libpod/kube.go6
-rw-r--r--libpod/options.go2
-rw-r--r--libpod/runtime_ctr.go3
-rw-r--r--libpod/runtime_ctr_network.go12
-rw-r--r--libpod/runtime_ctr_network_unsupported.go12
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
-}