summaryrefslogtreecommitdiff
path: root/pkg/domain
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/domain')
-rw-r--r--pkg/domain/entities/network.go4
-rw-r--r--pkg/domain/filters/containers.go11
-rw-r--r--pkg/domain/infra/abi/network.go26
3 files changed, 27 insertions, 14 deletions
diff --git a/pkg/domain/entities/network.go b/pkg/domain/entities/network.go
index f66a7f575..a89501664 100644
--- a/pkg/domain/entities/network.go
+++ b/pkg/domain/entities/network.go
@@ -92,4 +92,6 @@ type NetworkPruneReport struct {
// NetworkPruneOptions describes options for pruning
// unused cni networks
-type NetworkPruneOptions struct{}
+type NetworkPruneOptions struct {
+ Filters map[string][]string
+}
diff --git a/pkg/domain/filters/containers.go b/pkg/domain/filters/containers.go
index 98b8f7e88..02727e841 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/timetype"
"github.com/containers/podman/v3/pkg/util"
"github.com/pkg/errors"
)
@@ -186,18 +185,10 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
return false
}, nil
case "until":
- if len(filterValues) != 1 {
- return nil, errors.Errorf("specify exactly one timestamp for %s", filter)
- }
- ts, err := timetype.GetTimestamp(filterValues[0], time.Now())
- if err != nil {
- return nil, err
- }
- seconds, nanoseconds, err := timetype.ParseTimestamps(ts, 0)
+ until, err := util.ComputeUntilTimestamp(filter, filterValues)
if err != nil {
return nil, err
}
- until := time.Unix(seconds, nanoseconds)
return func(c *libpod.Container) bool {
if !until.IsZero() && c.CreatedTime().After((until)) {
return true
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)
}