aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-12-14 20:56:55 +0100
committerGitHub <noreply@github.com>2021-12-14 20:56:55 +0100
commitc36fb8b1138b112ec3d53e5cf89a2fbcb12e6840 (patch)
treed81ca6337af0e83f6bfc127c1296103a47f95046 /pkg
parenta0894b5ecd6c64d30b82a7b79bc1e2e87c7f0a4e (diff)
parent888c778ee975b449aef6dec6bbdfb029a7fe385e (diff)
downloadpodman-c36fb8b1138b112ec3d53e5cf89a2fbcb12e6840.tar.gz
podman-c36fb8b1138b112ec3d53e5cf89a2fbcb12e6840.tar.bz2
podman-c36fb8b1138b112ec3d53e5cf89a2fbcb12e6840.zip
Merge pull request #12595 from Luap99/network-id
fix network id handling
Diffstat (limited to 'pkg')
-rw-r--r--pkg/domain/filters/containers.go18
-rw-r--r--pkg/domain/filters/pods.go20
-rw-r--r--pkg/domain/infra/abi/pods.go2
-rw-r--r--pkg/network/network.go27
4 files changed, 24 insertions, 43 deletions
diff --git a/pkg/domain/filters/containers.go b/pkg/domain/filters/containers.go
index 269cd2d27..a28167d3e 100644
--- a/pkg/domain/filters/containers.go
+++ b/pkg/domain/filters/containers.go
@@ -8,7 +8,6 @@ import (
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/define"
- "github.com/containers/podman/v3/pkg/network"
"github.com/containers/podman/v3/pkg/util"
"github.com/pkg/errors"
)
@@ -210,6 +209,15 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
return false
}, nil
case "network":
+ var inputNetNames []string
+ for _, val := range filterValues {
+ net, err := r.Network().NetworkInspect(val)
+ if err != nil {
+ // ignore not found errors
+ break
+ }
+ inputNetNames = append(inputNetNames, net.Name)
+ }
return func(c *libpod.Container) bool {
networkMode := c.NetworkMode()
// support docker like `--filter network=container:<IDorName>`
@@ -247,12 +255,8 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
return false
}
for _, net := range networks {
- netID := network.GetNetworkID(net)
- for _, val := range filterValues {
- // match by network name or id
- if val == net || val == netID {
- return true
- }
+ if util.StringInSlice(net, inputNetNames) {
+ return true
}
}
return false
diff --git a/pkg/domain/filters/pods.go b/pkg/domain/filters/pods.go
index 9a2f0a3ba..ed7506bf3 100644
--- a/pkg/domain/filters/pods.go
+++ b/pkg/domain/filters/pods.go
@@ -6,7 +6,6 @@ import (
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/define"
- "github.com/containers/podman/v3/pkg/network"
"github.com/containers/podman/v3/pkg/util"
"github.com/pkg/errors"
)
@@ -14,7 +13,7 @@ import (
// GeneratePodFilterFunc takes a filter and filtervalue (key, value)
// and generates a libpod function that can be used to filter
// pods
-func GeneratePodFilterFunc(filter string, filterValues []string) (
+func GeneratePodFilterFunc(filter string, filterValues []string, r *libpod.Runtime) (
func(pod *libpod.Pod) bool, error) {
switch filter {
case "ctr-ids":
@@ -128,6 +127,15 @@ func GeneratePodFilterFunc(filter string, filterValues []string) (
return false
}, nil
case "network":
+ var inputNetNames []string
+ for _, val := range filterValues {
+ net, err := r.Network().NetworkInspect(val)
+ if err != nil {
+ // ignore not found errors
+ break
+ }
+ inputNetNames = append(inputNetNames, net.Name)
+ }
return func(p *libpod.Pod) bool {
infra, err := p.InfraContainer()
// no infra, quick out
@@ -140,12 +148,8 @@ func GeneratePodFilterFunc(filter string, filterValues []string) (
return false
}
for _, net := range networks {
- netID := network.GetNetworkID(net)
- for _, val := range filterValues {
- // match by network name or id
- if val == net || val == netID {
- return true
- }
+ if util.StringInSlice(net, inputNetNames) {
+ return true
}
}
return false
diff --git a/pkg/domain/infra/abi/pods.go b/pkg/domain/infra/abi/pods.go
index 028de9e81..fc0a2337c 100644
--- a/pkg/domain/infra/abi/pods.go
+++ b/pkg/domain/infra/abi/pods.go
@@ -325,7 +325,7 @@ func (ic *ContainerEngine) PodPs(ctx context.Context, options entities.PodPSOpti
filters := make([]libpod.PodFilter, 0, len(options.Filters))
for k, v := range options.Filters {
- f, err := dfilters.GeneratePodFilterFunc(k, v)
+ f, err := dfilters.GeneratePodFilterFunc(k, v, ic.Libpod)
if err != nil {
return nil, err
}
diff --git a/pkg/network/network.go b/pkg/network/network.go
deleted file mode 100644
index 44132ca28..000000000
--- a/pkg/network/network.go
+++ /dev/null
@@ -1,27 +0,0 @@
-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[:])
-}