diff options
author | Toshiki Sonoda <sonoda.toshiki@fujitsu.com> | 2022-06-14 14:04:03 +0900 |
---|---|---|
committer | Toshiki Sonoda <sonoda.toshiki@fujitsu.com> | 2022-06-14 14:04:03 +0900 |
commit | 4811cb110accec51df168742df6a319f48ed37b6 (patch) | |
tree | e6128ffefd9355620747002031ca4ca17811e81c /cmd | |
parent | c044d455a1f42447fa800f0a5b4e83a7e271dbeb (diff) | |
download | podman-4811cb110accec51df168742df6a319f48ed37b6.tar.gz podman-4811cb110accec51df168742df6a319f48ed37b6.tar.bz2 podman-4811cb110accec51df168742df6a319f48ed37b6.zip |
podman system prune support prune unused networks
This is an enhancement for the podman system prune feature.
In this issue, it is mentioned that 'network prune' should be
wired into 'podman system prune'
https://github.com/containers/podman/issues/8673
Therefore, I add the function to remove unused networks.
Signed-off-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/system/prune.go | 6 | ||||
-rw-r--r-- | cmd/podman/utils/utils.go | 15 |
2 files changed, 21 insertions, 0 deletions
diff --git a/cmd/podman/system/prune.go b/cmd/podman/system/prune.go index ff78f93bb..1d6ba8155 100644 --- a/cmd/podman/system/prune.go +++ b/cmd/podman/system/prune.go @@ -75,6 +75,7 @@ func prune(cmd *cobra.Command, args []string) error { } } + // Remove all unused pods, containers, images, networks, and volume data. pruneOptions.Filters, err = parse.FilterArgumentsIntoFilters(filters) if err != nil { return err @@ -106,6 +107,11 @@ func prune(cmd *cobra.Command, args []string) error { if err != nil { return err } + // Print Network prune results + err = utils.PrintNetworkPruneResults(response.NetworkPruneReports, true) + if err != nil { + return err + } fmt.Printf("Total reclaimed space: %s\n", units.HumanSize((float64)(response.ReclaimedSpace))) return nil diff --git a/cmd/podman/utils/utils.go b/cmd/podman/utils/utils.go index 6fd6647d0..73bb34983 100644 --- a/cmd/podman/utils/utils.go +++ b/cmd/podman/utils/utils.go @@ -84,3 +84,18 @@ func PrintImagePruneResults(imagePruneReports []*reports.PruneReport, heading bo return nil } + +func PrintNetworkPruneResults(networkPruneReport []*reports.PruneReport, heading bool) error { + var errs OutputErrors + if heading && len(networkPruneReport) > 0 { + fmt.Println("Deleted Networks") + } + for _, r := range networkPruneReport { + if r.Err == nil { + fmt.Println(r.Id) + } else { + errs = append(errs, r.Err) + } + } + return errs.PrintErrors() +} |