diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-03-15 14:25:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-15 14:25:30 -0400 |
commit | e7dc59252bd722377938ac3e6b4fd7e077f05293 (patch) | |
tree | 6a51b88aa97db1ff7dfa0313876b28844764aab1 /libpod | |
parent | fc02d16e728dfdd5a5f2e3bc622bbceb7f8c0d24 (diff) | |
parent | 8de56070393ad449dc54ae622d9b82f28a6a5c52 (diff) | |
download | podman-e7dc59252bd722377938ac3e6b4fd7e077f05293.tar.gz podman-e7dc59252bd722377938ac3e6b4fd7e077f05293.tar.bz2 podman-e7dc59252bd722377938ac3e6b4fd7e077f05293.zip |
Merge pull request #9716 from Luap99/remote-libpod
Do not leak libpod package into the remote client
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/network/files.go | 13 | ||||
-rw-r--r-- | libpod/network/netconflist.go | 7 | ||||
-rw-r--r-- | libpod/network/network.go | 9 | ||||
-rw-r--r-- | libpod/options.go | 2 |
8 files changed, 33 insertions, 49 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/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) |