summaryrefslogtreecommitdiff
path: root/libpod/network
diff options
context:
space:
mode:
authorJakub Guzik <jakubmguzik@gmail.com>2021-03-23 00:13:44 +0100
committerMatthew Heon <mheon@redhat.com>2021-03-29 13:26:18 -0400
commit183a68a817208821a9fc79a3c9c19202a63dfb44 (patch)
treebd56722c15906e77fa210ac446da6a63213b2279 /libpod/network
parentd1589f280474dd90236a59f8b32bb2a4a04fd683 (diff)
downloadpodman-183a68a817208821a9fc79a3c9c19202a63dfb44.tar.gz
podman-183a68a817208821a9fc79a3c9c19202a63dfb44.tar.bz2
podman-183a68a817208821a9fc79a3c9c19202a63dfb44.zip
Unification of label filter across list/prune endpoints
Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
Diffstat (limited to 'libpod/network')
-rw-r--r--libpod/network/netconflist.go27
1 files changed, 2 insertions, 25 deletions
diff --git a/libpod/network/netconflist.go b/libpod/network/netconflist.go
index b358bc530..179620a0d 100644
--- a/libpod/network/netconflist.go
+++ b/libpod/network/netconflist.go
@@ -225,7 +225,7 @@ func IfPassesFilter(netconf *libcni.NetworkConfigList, filters map[string][]stri
case "label":
// matches all labels
- result = matchPruneLabelFilters(netconf, filterValues)
+ result = util.MatchLabelFilters(filterValues, GetNetworkLabels(netconf))
case "driver":
// matches only for the DefaultNetworkDriver
@@ -260,7 +260,7 @@ func IfPassesPruneFilter(config *config.Config, netconf *libcni.NetworkConfigLis
for key, filterValues := range f {
switch strings.ToLower(key) {
case "label":
- return matchPruneLabelFilters(netconf, filterValues), nil
+ return util.MatchLabelFilters(filterValues, GetNetworkLabels(netconf)), nil
case "until":
until, err := util.ComputeUntilTimestamp(key, filterValues)
if err != nil {
@@ -280,29 +280,6 @@ func IfPassesPruneFilter(config *config.Config, netconf *libcni.NetworkConfigLis
return false, nil
}
-func matchPruneLabelFilters(netconf *libcni.NetworkConfigList, filterValues []string) bool {
- labels := GetNetworkLabels(netconf)
- result := true
-outer:
- for _, filterValue := range filterValues {
- filterArray := strings.SplitN(filterValue, "=", 2)
- filterKey := filterArray[0]
- if len(filterArray) > 1 {
- filterValue = filterArray[1]
- } else {
- filterValue = ""
- }
- for labelKey, labelValue := range labels {
- if labelKey == filterKey && (filterValue == "" || labelValue == filterValue) {
- result = true
- continue outer
- }
- }
- result = false
- }
- return result
-}
-
func getCreatedTimestamp(config *config.Config, netconf *libcni.NetworkConfigList) (*time.Time, error) {
networkConfigPath, err := GetCNIConfigPathByNameOrID(config, netconf.Name)
if err != nil {