diff options
author | openshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com> | 2022-07-11 12:53:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-11 12:53:59 +0000 |
commit | 0df8c6e1572c30fed45d96a4761060d3d440d69d (patch) | |
tree | 77539110d85fa8f4400eaa4609ddd7bbc4da6bf3 /pkg/domain | |
parent | 3691c9b1ba8e63f56b5cc36cdb1670fcfbdba0a1 (diff) | |
parent | d1754bdd4f299c8d92671493add4a69ef7850e1d (diff) | |
download | podman-0df8c6e1572c30fed45d96a4761060d3d440d69d.tar.gz podman-0df8c6e1572c30fed45d96a4761060d3d440d69d.tar.bz2 podman-0df8c6e1572c30fed45d96a4761060d3d440d69d.zip |
Merge pull request #14826 from sstosh/net-prune
Refactored networkPrune function
Diffstat (limited to 'pkg/domain')
-rw-r--r-- | pkg/domain/entities/network.go | 3 | ||||
-rw-r--r-- | pkg/domain/entities/system.go | 2 | ||||
-rw-r--r-- | pkg/domain/infra/abi/system.go | 29 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/network.go | 2 |
4 files changed, 16 insertions, 20 deletions
diff --git a/pkg/domain/entities/network.go b/pkg/domain/entities/network.go index d375c2e20..9e59953c6 100644 --- a/pkg/domain/entities/network.go +++ b/pkg/domain/entities/network.go @@ -81,8 +81,7 @@ type NetworkPruneReport struct { Error error } -// NetworkPruneOptions describes options for pruning -// unused cni networks +// NetworkPruneOptions describes options for pruning unused networks type NetworkPruneOptions struct { Filters map[string][]string } diff --git a/pkg/domain/entities/system.go b/pkg/domain/entities/system.go index 331d2bcdc..8dd0a61be 100644 --- a/pkg/domain/entities/system.go +++ b/pkg/domain/entities/system.go @@ -28,7 +28,7 @@ type SystemPruneReport struct { PodPruneReport []*PodPruneReport ContainerPruneReports []*reports.PruneReport ImagePruneReports []*reports.PruneReport - NetworkPruneReports []*reports.PruneReport + NetworkPruneReports []*NetworkPruneReport VolumePruneReports []*reports.PruneReport ReclaimedSpace uint64 } diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go index 96690afef..0faae01c8 100644 --- a/pkg/domain/infra/abi/system.go +++ b/pkg/domain/infra/abi/system.go @@ -157,15 +157,15 @@ func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.Sys // TODO: Figure out cleaner way to handle all of the different PruneOptions // Remove all unused pods. - podPruneReport, err := ic.prunePodHelper(ctx) + podPruneReports, err := ic.prunePodHelper(ctx) if err != nil { return nil, err } - if len(podPruneReport) > 0 { + if len(podPruneReports) > 0 { found = true } - systemPruneReport.PodPruneReport = append(systemPruneReport.PodPruneReport, podPruneReport...) + systemPruneReport.PodPruneReport = append(systemPruneReport.PodPruneReport, podPruneReports...) // Remove all unused containers. containerPruneOptions := entities.ContainerPruneOptions{} @@ -201,38 +201,35 @@ func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.Sys networkPruneOptions := entities.NetworkPruneOptions{} networkPruneOptions.Filters = options.Filters - networkPruneReport, err := ic.NetworkPrune(ctx, networkPruneOptions) + networkPruneReports, err := ic.NetworkPrune(ctx, networkPruneOptions) if err != nil { return nil, err } - if len(networkPruneReport) > 0 { + if len(networkPruneReports) > 0 { found = true } - for _, net := range networkPruneReport { - systemPruneReport.NetworkPruneReports = append(systemPruneReport.NetworkPruneReports, &reports.PruneReport{ - Id: net.Name, - Err: net.Error, - Size: 0, - }) - } + + // Networks reclaimedSpace are always '0'. + systemPruneReport.NetworkPruneReports = append(systemPruneReport.NetworkPruneReports, networkPruneReports...) // Remove unused volume data. if options.Volume { volumePruneOptions := entities.VolumePruneOptions{} volumePruneOptions.Filters = (url.Values)(options.Filters) - volumePruneReport, err := ic.VolumePrune(ctx, volumePruneOptions) + volumePruneReports, err := ic.VolumePrune(ctx, volumePruneOptions) if err != nil { return nil, err } - if len(volumePruneReport) > 0 { + if len(volumePruneReports) > 0 { found = true } - reclaimedSpace += reports.PruneReportsSize(volumePruneReport) - systemPruneReport.VolumePruneReports = append(systemPruneReport.VolumePruneReports, volumePruneReport...) + reclaimedSpace += reports.PruneReportsSize(volumePruneReports) + systemPruneReport.VolumePruneReports = append(systemPruneReport.VolumePruneReports, volumePruneReports...) } } + systemPruneReport.ReclaimedSpace = reclaimedSpace return systemPruneReport, nil } diff --git a/pkg/domain/infra/tunnel/network.go b/pkg/domain/infra/tunnel/network.go index ffdcbab1e..6e27b8e56 100644 --- a/pkg/domain/infra/tunnel/network.go +++ b/pkg/domain/infra/tunnel/network.go @@ -96,7 +96,7 @@ func (ic *ContainerEngine) NetworkExists(ctx context.Context, networkname string }, nil } -// Network prune removes unused cni networks +// Network prune removes unused networks func (ic *ContainerEngine) NetworkPrune(ctx context.Context, options entities.NetworkPruneOptions) ([]*entities.NetworkPruneReport, error) { opts := new(network.PruneOptions).WithFilters(options.Filters) return network.Prune(ic.ClientCtx, opts) |