diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-03-18 06:32:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-18 06:32:29 -0700 |
commit | 629183bd7f0073dfcbfa4d611abc62a9c5711dab (patch) | |
tree | 812ebb2c5a6685f1f333ec960365e97b4e91457f /pkg/domain/infra/abi/network.go | |
parent | 77b3a2df645f2548f7bd2da85bbdb17e4de98310 (diff) | |
parent | 8ea02d0b6033b6ffdc68d38f3276410f4e2e8eb9 (diff) | |
download | podman-629183bd7f0073dfcbfa4d611abc62a9c5711dab.tar.gz podman-629183bd7f0073dfcbfa4d611abc62a9c5711dab.tar.bz2 podman-629183bd7f0073dfcbfa4d611abc62a9c5711dab.zip |
Merge pull request #9710 from jmguzik/network-prune-filters-http-api
Network prune filters for http api (compat and libpod)
Diffstat (limited to 'pkg/domain/infra/abi/network.go')
-rw-r--r-- | pkg/domain/infra/abi/network.go | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/pkg/domain/infra/abi/network.go b/pkg/domain/infra/abi/network.go index edde8ece6..1a833332c 100644 --- a/pkg/domain/infra/abi/network.go +++ b/pkg/domain/infra/abi/network.go @@ -174,17 +174,37 @@ func (ic *ContainerEngine) NetworkPrune(ctx context.Context, options entities.Ne if err != nil { return nil, err } + networks, err := network.LoadCNIConfsFromDir(network.GetCNIConfDir(runtimeConfig)) + if err != nil { + return nil, err + } + // Gather up all the non-default networks that the // containers want - usedNetworks := make(map[string]bool) + networksToKeep := make(map[string]bool) for _, c := range cons { nets, _, err := c.Networks() if err != nil { return nil, err } for _, n := range nets { - usedNetworks[n] = true + networksToKeep[n] = true + } + } + if len(options.Filters) != 0 { + for _, n := range networks { + // This network will be kept anyway + if _, found := networksToKeep[n.Name]; found { + continue + } + ok, err := network.IfPassesPruneFilter(runtimeConfig, n, options.Filters) + if err != nil { + return nil, err + } + if !ok { + networksToKeep[n.Name] = true + } } } - return network.PruneNetworks(runtimeConfig, usedNetworks) + return network.PruneNetworks(runtimeConfig, networksToKeep) } |