mirror of
https://github.com/containers/podman.git
synced 2025-10-25 02:04:43 +08:00
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:
@ -19,8 +19,9 @@ func SystemPrune(w http.ResponseWriter, r *http.Request) {
|
||||
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
|
||||
|
||||
query := struct {
|
||||
All bool `schema:"all"`
|
||||
Volumes bool `schema:"volumes"`
|
||||
All bool `schema:"all"`
|
||||
Volumes bool `schema:"volumes"`
|
||||
External bool `schema:"external"`
|
||||
}{}
|
||||
|
||||
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
||||
@ -38,9 +39,10 @@ func SystemPrune(w http.ResponseWriter, r *http.Request) {
|
||||
containerEngine := abi.ContainerEngine{Libpod: runtime}
|
||||
|
||||
pruneOptions := entities.SystemPruneOptions{
|
||||
All: query.All,
|
||||
Volume: query.Volumes,
|
||||
Filters: *filterMap,
|
||||
All: query.All,
|
||||
Volume: query.Volumes,
|
||||
Filters: *filterMap,
|
||||
External: query.External,
|
||||
}
|
||||
report, err := containerEngine.SystemPrune(r.Context(), pruneOptions)
|
||||
if err != nil {
|
||||
|
||||
@ -14,9 +14,10 @@ type EventsOptions struct {
|
||||
//
|
||||
//go:generate go run ../generator/generator.go PruneOptions
|
||||
type PruneOptions struct {
|
||||
All *bool
|
||||
Filters map[string][]string
|
||||
Volumes *bool
|
||||
All *bool
|
||||
Filters map[string][]string
|
||||
Volumes *bool
|
||||
External *bool
|
||||
}
|
||||
|
||||
// VersionOptions are optional options for getting version info
|
||||
|
||||
@ -61,3 +61,18 @@ func (o *PruneOptions) GetVolumes() bool {
|
||||
}
|
||||
return *o.Volumes
|
||||
}
|
||||
|
||||
// WithExternal set field External to given value
|
||||
func (o *PruneOptions) WithExternal(value bool) *PruneOptions {
|
||||
o.External = &value
|
||||
return o
|
||||
}
|
||||
|
||||
// GetExternal returns value of field External
|
||||
func (o *PruneOptions) GetExternal() bool {
|
||||
if o.External == nil {
|
||||
var z bool
|
||||
return z
|
||||
}
|
||||
return *o.External
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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]))
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user