Add podman system prune --external

This just calls GC on the local storage, which will remove any leftover
directories from previous containers that are not in the podman db anymore.
This is useful primarily for transient store mode, but can also help in
the case of an unclean shutdown.

Also adds some e2e test to ensure prune --external works.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
This commit is contained in:
Alexander Larsson
2022-11-30 13:49:28 +01:00
parent f1dbfda807
commit 93d2ec148c
10 changed files with 146 additions and 15 deletions

View File

@ -18,9 +18,10 @@ type ServiceOptions struct {
// SystemPruneOptions provides options to prune system.
type SystemPruneOptions struct {
All bool
Volume bool
Filters map[string][]string `json:"filters" schema:"filters"`
All bool
Volume bool
Filters map[string][]string `json:"filters" schema:"filters"`
External bool
}
// SystemPruneReport provides report after system prune is executed.

View File

@ -160,6 +160,18 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, noMoveProcess bool)
// SystemPrune removes unused data from the system. Pruning pods, containers, networks, volumes and images.
func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.SystemPruneOptions) (*entities.SystemPruneReport, error) {
var systemPruneReport = new(entities.SystemPruneReport)
if options.External {
if options.All || options.Volume || len(options.Filters) > 0 {
return nil, fmt.Errorf("system prune --external cannot be combined with other options")
}
err := ic.Libpod.GarbageCollect()
if err != nil {
return nil, err
}
return systemPruneReport, nil
}
filters := []string{}
for k, v := range options.Filters {
filters = append(filters, fmt.Sprintf("%s=%s", k, v[0]))

View File

@ -19,7 +19,7 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, noMoveProcess bool)
// SystemPrune prunes unused data from the system.
func (ic *ContainerEngine) SystemPrune(ctx context.Context, opts entities.SystemPruneOptions) (*entities.SystemPruneReport, error) {
options := new(system.PruneOptions).WithAll(opts.All).WithVolumes(opts.Volume).WithFilters(opts.Filters)
options := new(system.PruneOptions).WithAll(opts.All).WithVolumes(opts.Volume).WithFilters(opts.Filters).WithExternal(opts.External)
return system.Prune(ic.ClientCtx, options)
}