Skip to content

Commit

Permalink
Merge pull request #9716 from Luap99/remote-libpod
Browse files Browse the repository at this point in the history
Do not leak libpod package into the remote client
  • Loading branch information
openshift-merge-robot authored Mar 15, 2021
2 parents fc02d16 + 8de5607 commit e7dc592
Show file tree
Hide file tree
Showing 26 changed files with 123 additions and 107 deletions.
9 changes: 4 additions & 5 deletions cmd/podman/common/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions cmd/podman/common/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/networks/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions pkg/domain/filters/helpers.go → cmd/podman/parse/filters.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package filters
package parse

import (
"net/url"
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/system/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/podman/volumes/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
18 changes: 0 additions & 18 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
8 changes: 4 additions & 4 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions libpod/define/container.go
Original file line number Diff line number Diff line change
@@ -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"
)
6 changes: 3 additions & 3 deletions libpod/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions libpod/network/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand All @@ -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{})
Expand Down
7 changes: 4 additions & 3 deletions libpod/network/netconflist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
9 changes: 0 additions & 9 deletions libpod/network/network.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package network

import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"net"
"os"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libpod/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/handlers/compat/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions pkg/autoupdate/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/filters/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/filters/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
8 changes: 4 additions & 4 deletions pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
Loading

0 comments on commit e7dc592

Please sign in to comment.