summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/common/completion.go9
-rw-r--r--cmd/podman/common/specgen.go6
-rw-r--r--cmd/podman/networks/list.go2
-rw-r--r--cmd/podman/parse/filters.go (renamed from pkg/domain/filters/helpers.go)4
-rw-r--r--cmd/podman/system/prune.go4
-rw-r--r--cmd/podman/volumes/prune.go6
-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/network/files.go13
-rw-r--r--libpod/network/netconflist.go7
-rw-r--r--libpod/network/network.go9
-rw-r--r--libpod/options.go2
-rw-r--r--pkg/api/handlers/compat/networks.go3
-rw-r--r--pkg/autoupdate/autoupdate.go6
-rw-r--r--pkg/domain/filters/containers.go2
-rw-r--r--pkg/domain/filters/pods.go2
-rw-r--r--pkg/domain/infra/abi/play.go8
-rw-r--r--pkg/network/network.go27
-rw-r--r--pkg/systemd/define/const.go9
-rw-r--r--pkg/systemd/generate/common.go11
-rw-r--r--pkg/systemd/generate/containers.go3
-rw-r--r--pkg/systemd/generate/containers_test.go41
-rw-r--r--pkg/systemd/generate/pods.go3
-rw-r--r--test/e2e/containers_conf_test.go2
26 files changed, 123 insertions, 107 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index 7629a8145..bc106263c 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -8,12 +8,11 @@ import (
"github.com/containers/common/pkg/config"
"github.com/containers/podman/v3/cmd/podman/registry"
- "github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/registries"
"github.com/containers/podman/v3/pkg/rootless"
- systemdGen "github.com/containers/podman/v3/pkg/systemd/generate"
+ systemdDefine "github.com/containers/podman/v3/pkg/systemd/define"
"github.com/containers/podman/v3/pkg/util"
"github.com/spf13/cobra"
)
@@ -732,8 +731,8 @@ func AutocompletePullOption(cmd *cobra.Command, args []string, toComplete string
// AutocompleteRestartOption - Autocomplete restart options for create and run command.
// -> "always", "no", "on-failure", "unless-stopped"
func AutocompleteRestartOption(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- restartOptions := []string{libpod.RestartPolicyAlways, libpod.RestartPolicyNo,
- libpod.RestartPolicyOnFailure, libpod.RestartPolicyUnlessStopped}
+ restartOptions := []string{define.RestartPolicyAlways, define.RestartPolicyNo,
+ define.RestartPolicyOnFailure, define.RestartPolicyUnlessStopped}
return restartOptions, cobra.ShellCompDirectiveNoFileComp
}
@@ -908,7 +907,7 @@ func AutocompleteEventFilter(cmd *cobra.Command, args []string, toComplete strin
// AutocompleteSystemdRestartOptions - Autocomplete systemd restart options.
// -> "no", "on-success", "on-failure", "on-abnormal", "on-watchdog", "on-abort", "always"
func AutocompleteSystemdRestartOptions(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- return systemdGen.RestartPolicies, cobra.ShellCompDirectiveNoFileComp
+ return systemdDefine.RestartPolicies, cobra.ShellCompDirectiveNoFileComp
}
// AutocompleteTrustType - Autocomplete trust type options.
diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go
index 2fafbfac1..d1b67d963 100644
--- a/cmd/podman/common/specgen.go
+++ b/cmd/podman/common/specgen.go
@@ -14,7 +14,7 @@ import (
envLib "github.com/containers/podman/v3/pkg/env"
ns "github.com/containers/podman/v3/pkg/namespaces"
"github.com/containers/podman/v3/pkg/specgen"
- systemdGen "github.com/containers/podman/v3/pkg/systemd/generate"
+ systemdDefine "github.com/containers/podman/v3/pkg/systemd/define"
"github.com/containers/podman/v3/pkg/util"
"github.com/docker/go-units"
"github.com/opencontainers/runtime-spec/specs-go"
@@ -342,8 +342,8 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
return errors.Wrapf(err, "unable to process labels")
}
- if systemdUnit, exists := osEnv[systemdGen.EnvVariable]; exists {
- labels[systemdGen.EnvVariable] = systemdUnit
+ if systemdUnit, exists := osEnv[systemdDefine.EnvVariable]; exists {
+ labels[systemdDefine.EnvVariable] = systemdUnit
}
s.Labels = labels
diff --git a/cmd/podman/networks/list.go b/cmd/podman/networks/list.go
index 2181f850b..fcbcb6722 100644
--- a/cmd/podman/networks/list.go
+++ b/cmd/podman/networks/list.go
@@ -12,8 +12,8 @@ import (
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/validate"
- "github.com/containers/podman/v3/libpod/network"
"github.com/containers/podman/v3/pkg/domain/entities"
+ "github.com/containers/podman/v3/pkg/network"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
diff --git a/pkg/domain/filters/helpers.go b/cmd/podman/parse/filters.go
index 6a5fb68b1..8a10f2a97 100644
--- a/pkg/domain/filters/helpers.go
+++ b/cmd/podman/parse/filters.go
@@ -1,4 +1,4 @@
-package filters
+package parse
import (
"net/url"
@@ -7,7 +7,7 @@ import (
"github.com/pkg/errors"
)
-func ParseFilterArgumentsIntoFilters(filters []string) (url.Values, error) {
+func FilterArgumentsIntoFilters(filters []string) (url.Values, error) {
parsedFilters := make(url.Values)
for _, f := range filters {
t := strings.SplitN(f, "=", 2)
diff --git a/cmd/podman/system/prune.go b/cmd/podman/system/prune.go
index dcb3316f0..136c15304 100644
--- a/cmd/podman/system/prune.go
+++ b/cmd/podman/system/prune.go
@@ -8,11 +8,11 @@ import (
"strings"
"github.com/containers/common/pkg/completion"
+ "github.com/containers/podman/v3/cmd/podman/parse"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/utils"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/pkg/domain/entities"
- dfilters "github.com/containers/podman/v3/pkg/domain/filters"
"github.com/docker/go-units"
"github.com/spf13/cobra"
)
@@ -80,7 +80,7 @@ Are you sure you want to continue? [y/N] `, volumeString)
}
}
- pruneOptions.Filters, err = dfilters.ParseFilterArgumentsIntoFilters(filters)
+ pruneOptions.Filters, err = parse.FilterArgumentsIntoFilters(filters)
if err != nil {
return err
}
diff --git a/cmd/podman/volumes/prune.go b/cmd/podman/volumes/prune.go
index 8f78d0bae..8e190b870 100644
--- a/cmd/podman/volumes/prune.go
+++ b/cmd/podman/volumes/prune.go
@@ -9,11 +9,11 @@ import (
"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/parse"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/utils"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/pkg/domain/entities"
- "github.com/containers/podman/v3/pkg/domain/filters"
"github.com/spf13/cobra"
)
@@ -58,14 +58,14 @@ func prune(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
- pruneOptions.Filters, err = filters.ParseFilterArgumentsIntoFilters(filter)
+ pruneOptions.Filters, err = parse.FilterArgumentsIntoFilters(filter)
if !force {
reader := bufio.NewReader(os.Stdin)
fmt.Println("WARNING! This will remove all volumes not used by at least one container. The following volumes will be removed:")
if err != nil {
return err
}
- listOptions.Filter, err = filters.ParseFilterArgumentsIntoFilters(filter)
+ listOptions.Filter, err = parse.FilterArgumentsIntoFilters(filter)
if err != nil {
return err
}
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/network/files.go b/libpod/network/files.go
index fe483e25c..d876113f9 100644
--- a/libpod/network/files.go
+++ b/libpod/network/files.go
@@ -11,6 +11,7 @@ import (
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
"github.com/containers/common/pkg/config"
"github.com/containers/podman/v3/libpod/define"
+ "github.com/containers/podman/v3/pkg/network"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -67,7 +68,7 @@ func GetCNIConfigPathByNameOrID(config *config.Config, name string) (string, err
if conf.Name == name {
return confFile, nil
}
- if strings.HasPrefix(GetNetworkID(conf.Name), name) {
+ if strings.HasPrefix(network.GetNetworkID(conf.Name), name) {
idMatch++
file = confFile
}
@@ -92,16 +93,6 @@ func ReadRawCNIConfByNameOrID(config *config.Config, name string) ([]byte, error
return b, err
}
-// GetCNIPlugins returns a list of plugins that a given network
-// has in the form of a string
-func GetCNIPlugins(list *libcni.NetworkConfigList) string {
- plugins := make([]string, 0, len(list.Plugins))
- for _, plug := range list.Plugins {
- plugins = append(plugins, plug.Network.Type)
- }
- return strings.Join(plugins, ",")
-}
-
// GetNetworkLabels returns a list of labels as a string
func GetNetworkLabels(list *libcni.NetworkConfigList) NcLabels {
cniJSON := make(map[string]interface{})
diff --git a/libpod/network/netconflist.go b/libpod/network/netconflist.go
index 1a1583587..a45a4109a 100644
--- a/libpod/network/netconflist.go
+++ b/libpod/network/netconflist.go
@@ -7,6 +7,7 @@ import (
"strings"
"github.com/containernetworking/cni/libcni"
+ "github.com/containers/podman/v3/pkg/network"
"github.com/containers/podman/v3/pkg/util"
"github.com/pkg/errors"
)
@@ -211,7 +212,7 @@ func IfPassesFilter(netconf *libcni.NetworkConfigList, filters map[string][]stri
case "plugin":
// match one plugin
- plugins := GetCNIPlugins(netconf)
+ plugins := network.GetCNIPlugins(netconf)
for _, val := range filterValues {
if strings.Contains(plugins, val) {
result = true
@@ -243,7 +244,7 @@ func IfPassesFilter(netconf *libcni.NetworkConfigList, filters map[string][]stri
case "driver":
// matches only for the DefaultNetworkDriver
for _, filterValue := range filterValues {
- plugins := GetCNIPlugins(netconf)
+ plugins := network.GetCNIPlugins(netconf)
if filterValue == DefaultNetworkDriver &&
strings.Contains(plugins, DefaultNetworkDriver) {
result = true
@@ -253,7 +254,7 @@ func IfPassesFilter(netconf *libcni.NetworkConfigList, filters map[string][]stri
case "id":
// matches part of one id
for _, filterValue := range filterValues {
- if strings.Contains(GetNetworkID(netconf.Name), filterValue) {
+ if strings.Contains(network.GetNetworkID(netconf.Name), filterValue) {
result = true
break
}
diff --git a/libpod/network/network.go b/libpod/network/network.go
index f19a764ef..ed4e6388a 100644
--- a/libpod/network/network.go
+++ b/libpod/network/network.go
@@ -1,8 +1,6 @@
package network
import (
- "crypto/sha256"
- "encoding/hex"
"encoding/json"
"net"
"os"
@@ -245,13 +243,6 @@ func Exists(config *config.Config, name string) (bool, error) {
return true, nil
}
-// GetNetworkID return the network ID for a given name.
-// It is just the sha256 hash but this should be good enough.
-func GetNetworkID(name string) string {
- hash := sha256.Sum256([]byte(name))
- return hex.EncodeToString(hash[:])
-}
-
// PruneNetworks removes networks that are not being used and that is not the default
// network. To keep proper fencing for imports, you must provide the used networks
// to this function as a map. the key is meaningful in the map, the book is a no-op
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/pkg/api/handlers/compat/networks.go b/pkg/api/handlers/compat/networks.go
index 28e90ac28..dfb1d7fda 100644
--- a/pkg/api/handlers/compat/networks.go
+++ b/pkg/api/handlers/compat/networks.go
@@ -16,6 +16,7 @@ import (
"github.com/containers/podman/v3/pkg/api/handlers/utils"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/domain/infra/abi"
+ networkid "github.com/containers/podman/v3/pkg/network"
"github.com/docker/docker/api/types"
dockerNetwork "github.com/docker/docker/api/types/network"
"github.com/gorilla/schema"
@@ -135,7 +136,7 @@ func getNetworkResourceByNameOrID(nameOrID string, runtime *libpod.Runtime, filt
report := types.NetworkResource{
Name: conf.Name,
- ID: network.GetNetworkID(conf.Name),
+ ID: networkid.GetNetworkID(conf.Name),
Created: time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.Nsec)), // nolint: unconvert
Scope: "local",
Driver: network.DefaultNetworkDriver,
diff --git a/pkg/autoupdate/autoupdate.go b/pkg/autoupdate/autoupdate.go
index 53095c295..e271b9466 100644
--- a/pkg/autoupdate/autoupdate.go
+++ b/pkg/autoupdate/autoupdate.go
@@ -13,7 +13,7 @@ import (
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/libpod/image"
"github.com/containers/podman/v3/pkg/systemd"
- systemdGen "github.com/containers/podman/v3/pkg/systemd/generate"
+ systemdDefine "github.com/containers/podman/v3/pkg/systemd/define"
"github.com/containers/podman/v3/pkg/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -178,10 +178,10 @@ func AutoUpdate(runtime *libpod.Runtime, options Options) ([]string, []error) {
updatedUnits := []string{}
for _, ctr := range containersToRestart {
labels := ctr.Labels()
- unit, exists := labels[systemdGen.EnvVariable]
+ unit, exists := labels[systemdDefine.EnvVariable]
if !exists {
// Shouldn't happen but let's be sure of it.
- errs = append(errs, errors.Errorf("error auto-updating container %q: no %s label found", ctr.ID(), systemdGen.EnvVariable))
+ errs = append(errs, errors.Errorf("error auto-updating container %q: no %s label found", ctr.ID(), systemdDefine.EnvVariable))
continue
}
_, err := conn.RestartUnit(unit, "replace", nil)
diff --git a/pkg/domain/filters/containers.go b/pkg/domain/filters/containers.go
index 6f4b4e8a0..98b8f7e88 100644
--- a/pkg/domain/filters/containers.go
+++ b/pkg/domain/filters/containers.go
@@ -7,7 +7,7 @@ import (
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/define"
- "github.com/containers/podman/v3/libpod/network"
+ "github.com/containers/podman/v3/pkg/network"
"github.com/containers/podman/v3/pkg/timetype"
"github.com/containers/podman/v3/pkg/util"
"github.com/pkg/errors"
diff --git a/pkg/domain/filters/pods.go b/pkg/domain/filters/pods.go
index 53d10213a..0490a4848 100644
--- a/pkg/domain/filters/pods.go
+++ b/pkg/domain/filters/pods.go
@@ -6,7 +6,7 @@ import (
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/define"
- "github.com/containers/podman/v3/libpod/network"
+ "github.com/containers/podman/v3/pkg/network"
"github.com/containers/podman/v3/pkg/util"
"github.com/pkg/errors"
)
diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go
index b7ca69281..efc7c86e3 100644
--- a/pkg/domain/infra/abi/play.go
+++ b/pkg/domain/infra/abi/play.go
@@ -173,13 +173,13 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
var ctrRestartPolicy string
switch podYAML.Spec.RestartPolicy {
case v1.RestartPolicyAlways:
- ctrRestartPolicy = libpod.RestartPolicyAlways
+ ctrRestartPolicy = define.RestartPolicyAlways
case v1.RestartPolicyOnFailure:
- ctrRestartPolicy = libpod.RestartPolicyOnFailure
+ ctrRestartPolicy = define.RestartPolicyOnFailure
case v1.RestartPolicyNever:
- ctrRestartPolicy = libpod.RestartPolicyNo
+ ctrRestartPolicy = define.RestartPolicyNo
default: // Default to Always
- ctrRestartPolicy = libpod.RestartPolicyAlways
+ ctrRestartPolicy = define.RestartPolicyAlways
}
configMaps := []v1.ConfigMap{}
diff --git a/pkg/network/network.go b/pkg/network/network.go
new file mode 100644
index 000000000..44132ca28
--- /dev/null
+++ b/pkg/network/network.go
@@ -0,0 +1,27 @@
+package network
+
+import (
+ "crypto/sha256"
+ "encoding/hex"
+ "strings"
+
+ "github.com/containernetworking/cni/libcni"
+)
+
+// GetCNIPlugins returns a list of plugins that a given network
+// has in the form of a string
+func GetCNIPlugins(list *libcni.NetworkConfigList) string {
+ plugins := make([]string, 0, len(list.Plugins))
+ for _, plug := range list.Plugins {
+ plugins = append(plugins, plug.Network.Type)
+ }
+ return strings.Join(plugins, ",")
+}
+
+// GetNetworkID return the network ID for a given name.
+// It is just the sha256 hash but this should be good enough.
+// The caller has to make sure it is only called with the network name.
+func GetNetworkID(name string) string {
+ hash := sha256.Sum256([]byte(name))
+ return hex.EncodeToString(hash[:])
+}
diff --git a/pkg/systemd/define/const.go b/pkg/systemd/define/const.go
new file mode 100644
index 000000000..1b50be5db
--- /dev/null
+++ b/pkg/systemd/define/const.go
@@ -0,0 +1,9 @@
+package define
+
+// EnvVariable "PODMAN_SYSTEMD_UNIT" is set in all generated systemd units and
+// is set to the unit's (unique) name.
+const EnvVariable = "PODMAN_SYSTEMD_UNIT"
+
+// RestartPolicies includes all valid restart policies to be used in a unit
+// file.
+var RestartPolicies = []string{"no", "on-success", "on-failure", "on-abnormal", "on-watchdog", "on-abort", "always"}
diff --git a/pkg/systemd/generate/common.go b/pkg/systemd/generate/common.go
index bbd1a5f92..94a6f4cb5 100644
--- a/pkg/systemd/generate/common.go
+++ b/pkg/systemd/generate/common.go
@@ -4,25 +4,18 @@ import (
"strconv"
"strings"
+ "github.com/containers/podman/v3/pkg/systemd/define"
"github.com/pkg/errors"
)
-// EnvVariable "PODMAN_SYSTEMD_UNIT" is set in all generated systemd units and
-// is set to the unit's (unique) name.
-const EnvVariable = "PODMAN_SYSTEMD_UNIT"
-
// minTimeoutStopSec is the minimal stop timeout for generated systemd units.
// Once exceeded, processes of the services are killed and the cgroup(s) are
// cleaned up.
const minTimeoutStopSec = 60
-// RestartPolicies includes all valid restart policies to be used in a unit
-// file.
-var RestartPolicies = []string{"no", "on-success", "on-failure", "on-abnormal", "on-watchdog", "on-abort", "always"}
-
// validateRestartPolicy checks that the user-provided policy is valid.
func validateRestartPolicy(restart string) error {
- for _, i := range RestartPolicies {
+ for _, i := range define.RestartPolicies {
if i == restart {
return nil
}
diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go
index 92c6d8865..9343a5067 100644
--- a/pkg/systemd/generate/containers.go
+++ b/pkg/systemd/generate/containers.go
@@ -11,6 +11,7 @@ import (
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/pkg/domain/entities"
+ "github.com/containers/podman/v3/pkg/systemd/define"
"github.com/containers/podman/v3/version"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -173,7 +174,7 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst
info.Executable = executable
}
- info.EnvVariable = EnvVariable
+ info.EnvVariable = define.EnvVariable
info.ExecStart = "{{{{.Executable}}}} start {{{{.ContainerNameOrID}}}}"
info.ExecStop = "{{{{.Executable}}}} stop {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} {{{{.ContainerNameOrID}}}}"
info.ExecStopPost = "{{{{.Executable}}}} stop {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} {{{{.ContainerNameOrID}}}}"
diff --git a/pkg/systemd/generate/containers_test.go b/pkg/systemd/generate/containers_test.go
index 747c54699..ebbbdb786 100644
--- a/pkg/systemd/generate/containers_test.go
+++ b/pkg/systemd/generate/containers_test.go
@@ -4,6 +4,7 @@ import (
"testing"
"github.com/containers/podman/v3/pkg/domain/entities"
+ "github.com/containers/podman/v3/pkg/systemd/define"
"github.com/stretchr/testify/assert"
)
@@ -398,7 +399,7 @@ WantedBy=multi-user.target default.target
PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid",
StopTimeout: 22,
PodmanVersion: "CI",
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodID,
false,
@@ -414,7 +415,7 @@ WantedBy=multi-user.target default.target
PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid",
StopTimeout: 22,
PodmanVersion: "CI",
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodIDNoHeaderInfo,
false,
@@ -430,7 +431,7 @@ WantedBy=multi-user.target default.target
PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid",
StopTimeout: 10,
PodmanVersion: "CI",
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodName,
false,
@@ -447,7 +448,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 10,
PodmanVersion: "CI",
BoundToServices: []string{"pod", "a", "b", "c"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodNameBoundTo,
false,
@@ -462,7 +463,7 @@ WantedBy=multi-user.target default.target
PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid",
StopTimeout: 10,
PodmanVersion: "CI",
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
"",
false,
@@ -479,7 +480,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 10,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "container", "run", "--name", "jadda-jadda", "--hostname", "hello-world", "awesome-image:latest", "command", "arg1", "...", "argN", "foo=arg \"with \" space"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodWithNameAndGeneric,
true,
@@ -496,7 +497,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 10,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "run", "-d", "--name", "jadda-jadda", "--hostname", "hello-world", "awesome-image:latest", "command", "arg1", "...", "argN"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodWithExplicitShortDetachParam,
true,
@@ -513,7 +514,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 10,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "run", "-d", "--name", "jadda-jadda", "--hostname", "hello-world", "awesome-image:latest", "command", "arg1", "...", "argN"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
Pod: &podInfo{
PodIDFile: "%t/pod-foobar.pod-id-file",
},
@@ -533,7 +534,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 10,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "run", "--detach", "--name", "jadda-jadda", "--hostname", "hello-world", "awesome-image:latest", "command", "arg1", "...", "argN"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodNameNewDetach,
true,
@@ -550,7 +551,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 10,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "run", "awesome-image:latest"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodIDNew,
true,
@@ -567,7 +568,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 42,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "run", "--detach=true", "awesome-image:latest"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
genGoodNewDetach("--detach=true"),
true,
@@ -584,7 +585,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 42,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "run", "--detach=false", "awesome-image:latest"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
genGoodNewDetach("-d"),
true,
@@ -601,7 +602,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 42,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "run", "--name", "test", "-p", "80:80", "--detach=false", "awesome-image:latest", "somecmd", "--detach=false"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodNameNewDetachFalseWithCmd,
true,
@@ -618,7 +619,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 42,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "run", "--name", "test", "-p", "80:80", "--detach=false", "--detach=false", "awesome-image:latest", "somecmd", "--detach=false"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodNameNewDetachFalseWithCmd,
true,
@@ -635,7 +636,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 42,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "run", "-dti", "awesome-image:latest"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
genGoodNewDetach("-dti"),
true,
@@ -652,7 +653,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 42,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "run", "-tid", "awesome-image:latest"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
genGoodNewDetach("-tid"),
true,
@@ -669,7 +670,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 42,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "--events-backend", "none", "--runroot", "/root", "run", "awesome-image:latest"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodNewRootFlags,
true,
@@ -686,7 +687,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 10,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "container", "create", "awesome-image:latest"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodContainerCreate,
true,
@@ -703,7 +704,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 10,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "create", "--name", "test", "--log-driver=journald", "--log-opt=tag={{.Name}}", "awesome-image:latest"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodNewWithJournaldTag,
true,
@@ -720,7 +721,7 @@ WantedBy=multi-user.target default.target
StopTimeout: 10,
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "create", "--name", "test", "awesome-image:latest", "sh", "-c", "kill $$ && echo %\\"},
- EnvVariable: EnvVariable,
+ EnvVariable: define.EnvVariable,
},
goodNewWithSpecialChars,
true,
diff --git a/pkg/systemd/generate/pods.go b/pkg/systemd/generate/pods.go
index 8c0401278..f96058d36 100644
--- a/pkg/systemd/generate/pods.go
+++ b/pkg/systemd/generate/pods.go
@@ -11,6 +11,7 @@ import (
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/pkg/domain/entities"
+ "github.com/containers/podman/v3/pkg/systemd/define"
"github.com/containers/podman/v3/version"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -237,7 +238,7 @@ func executePodTemplate(info *podInfo, options entities.GenerateSystemdOptions)
info.Executable = executable
}
- info.EnvVariable = EnvVariable
+ info.EnvVariable = define.EnvVariable
info.ExecStart = "{{{{.Executable}}}} start {{{{.InfraNameOrID}}}}"
info.ExecStop = "{{{{.Executable}}}} stop {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} {{{{.InfraNameOrID}}}}"
info.ExecStopPost = "{{{{.Executable}}}} stop {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} {{{{.InfraNameOrID}}}}"
diff --git a/test/e2e/containers_conf_test.go b/test/e2e/containers_conf_test.go
index 6b1a0d16e..aa2380c51 100644
--- a/test/e2e/containers_conf_test.go
+++ b/test/e2e/containers_conf_test.go
@@ -311,7 +311,7 @@ var _ = Describe("Podman run", func() {
session = podmanTest.Podman([]string{"run", ALPINE, "date", "+'%H %Z'"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
- Expect(session.OutputToString()).To(ContainSubstring("EST"))
+ Expect(session.OutputToString()).To(Or(ContainSubstring("EST"), ContainSubstring("EDT")))
// Umask
session = podmanTest.Podman([]string{"run", "--rm", ALPINE, "sh", "-c", "umask"})