diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-03-24 03:10:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-24 03:10:28 -0700 |
commit | 0cb306674af4a8740464e57767d6defb020efb8e (patch) | |
tree | cf047fc93a7f0183b6c3312736ed12b014189114 /libpod/network/netconflist.go | |
parent | 860de13d4fe530e585c82a87a81fb46f3d0275ef (diff) | |
parent | 914218c1e8fd0dc11c1caee807bbed0cf26fdaf8 (diff) | |
download | podman-0cb306674af4a8740464e57767d6defb020efb8e.tar.gz podman-0cb306674af4a8740464e57767d6defb020efb8e.tar.bz2 podman-0cb306674af4a8740464e57767d6defb020efb8e.zip |
Merge pull request #9785 from jmguzik/unification-of-label-filter
Unification of label and until filters across list/prune endpoints
Diffstat (limited to 'libpod/network/netconflist.go')
-rw-r--r-- | libpod/network/netconflist.go | 29 |
1 files changed, 3 insertions, 26 deletions
diff --git a/libpod/network/netconflist.go b/libpod/network/netconflist.go index b358bc530..08816f2bd 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,9 +260,9 @@ 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) + until, err := util.ComputeUntilTimestamp(filterValues) if err != nil { return false, err } @@ -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 { |