mirror of https://github.com/containers/podman.git
Add --filter to podman system prune
Also document the allowable filters in podman system prune, podman image prune and podman container prune. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
059c2ee739
commit
15cdcdca76
|
@ -46,6 +46,9 @@ func init() {
|
||||||
flags.BoolVarP(&force, "force", "f", false, "Do not prompt for confirmation. The default is false")
|
flags.BoolVarP(&force, "force", "f", false, "Do not prompt for confirmation. The default is false")
|
||||||
flags.BoolVarP(&pruneOptions.All, "all", "a", false, "Remove all unused data")
|
flags.BoolVarP(&pruneOptions.All, "all", "a", false, "Remove all unused data")
|
||||||
flags.BoolVar(&pruneOptions.Volume, "volumes", false, "Prune volumes")
|
flags.BoolVar(&pruneOptions.Volume, "volumes", false, "Prune volumes")
|
||||||
|
filterFlagName := "filter"
|
||||||
|
flags.StringArrayVar(&pruneOptions.Filter, filterFlagName, []string{}, "Provide filter values (e.g. 'label=<key>=<value>')")
|
||||||
|
_ = pruneCommand.RegisterFlagCompletionFunc(filterFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,17 @@ podman-container-prune - Remove all stopped containers from local storage
|
||||||
|
|
||||||
Provide filter values.
|
Provide filter values.
|
||||||
|
|
||||||
|
The --filter flag format is of “key=value”. If there is more than one filter, then pass multiple flags (e.g., --filter "foo=bar" --filter "bif=baz")
|
||||||
|
|
||||||
|
Supported filters:
|
||||||
|
|
||||||
|
- `until` (_timestamp_) - only remove containers and images created before given timestamp
|
||||||
|
- `label` (label=_key_, label=_key=value_, label!=_key_, or label!=_key=value_) - only remove containers and images, with (or without, in case label!=... is used) the specified labels.
|
||||||
|
|
||||||
|
The until filter can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. 10m, 1h30m) computed relative to the machine’s time.
|
||||||
|
|
||||||
|
The label filter accepts two formats. One is the label=... (label=_key_ or label=_key=value_), which removes containers with the specified labels. The other format is the label!=... (label!=_key_ or label!=_key=value_), which removes containers without the specified labels.
|
||||||
|
|
||||||
#### **--force**, **-f**
|
#### **--force**, **-f**
|
||||||
|
|
||||||
Do not provide an interactive prompt for container removal.
|
Do not provide an interactive prompt for container removal.
|
||||||
|
@ -63,3 +74,4 @@ podman(1), podman-ps
|
||||||
|
|
||||||
## HISTORY
|
## HISTORY
|
||||||
December 2018, Originally compiled by Brent Baude (bbaude at redhat dot com)
|
December 2018, Originally compiled by Brent Baude (bbaude at redhat dot com)
|
||||||
|
December 2020, converted filter information from docs.docker.com documentation by Dan Walsh (dwalsh at redhat dot com)
|
||||||
|
|
|
@ -22,6 +22,17 @@ Remove dangling images and images that have no associated containers.
|
||||||
|
|
||||||
Provide filter values.
|
Provide filter values.
|
||||||
|
|
||||||
|
The --filter flag format is of “key=value”. If there is more than one filter, then pass multiple flags (e.g., --filter "foo=bar" --filter "bif=baz")
|
||||||
|
|
||||||
|
Supported filters:
|
||||||
|
|
||||||
|
- `until` (_timestamp_) - only remove containers and images created before given timestamp
|
||||||
|
- `label` (label=_key_, label=_key=value_, label!=_key_, or label!=_key=value_) - only remove containers and images, with (or without, in case label!=... is used) the specified labels.
|
||||||
|
|
||||||
|
The until filter can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. 10m, 1h30m) computed relative to the machine’s time.
|
||||||
|
|
||||||
|
The label filter accepts two formats. One is the label=... (label=_key_ or label=_key=value_), which removes images with the specified labels. The other format is the label!=... (label!=_key_ or label!=_key=value_), which removes images without the specified labels.
|
||||||
|
|
||||||
#### **--force**, **-f**
|
#### **--force**, **-f**
|
||||||
|
|
||||||
Do not provide an interactive prompt for container removal.
|
Do not provide an interactive prompt for container removal.
|
||||||
|
@ -93,3 +104,4 @@ podman(1), podman-images
|
||||||
|
|
||||||
## HISTORY
|
## HISTORY
|
||||||
December 2018, Originally compiled by Brent Baude (bbaude at redhat dot com)
|
December 2018, Originally compiled by Brent Baude (bbaude at redhat dot com)
|
||||||
|
December 2020, converted filter information from docs.docker.com documentation by Dan Walsh (dwalsh at redhat dot com)
|
||||||
|
|
|
@ -18,6 +18,21 @@ By default, volumes are not removed to prevent important data from being deleted
|
||||||
|
|
||||||
Recursively remove all unused pod, container, image and volume data (Maximum 50 iterations.)
|
Recursively remove all unused pod, container, image and volume data (Maximum 50 iterations.)
|
||||||
|
|
||||||
|
#### **--filter**=*filters*
|
||||||
|
|
||||||
|
Provide filter values.
|
||||||
|
|
||||||
|
The --filter flag format is of “key=value”. If there is more than one filter, then pass multiple flags (e.g., --filter "foo=bar" --filter "bif=baz")
|
||||||
|
|
||||||
|
Supported filters:
|
||||||
|
|
||||||
|
- `until` (_timestamp_) - only remove containers and images created before given timestamp
|
||||||
|
- `label` (label=_key_, label=_key=value_, label!=_key_, or label!=_key=value_) - only remove containers and images, with (or without, in case label!=... is used) the specified labels.
|
||||||
|
|
||||||
|
The until filter can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. 10m, 1h30m) computed relative to the machine’s time.
|
||||||
|
|
||||||
|
The label filter accepts two formats. One is the label=... (label=_key_ or label=_key=value_), which removes containers and images with the specified labels. The other format is the label!=... (label!=_key_ or label!=_key=value_), which removes containers and images without the specified labels.
|
||||||
|
|
||||||
#### **--force**, **-f**
|
#### **--force**, **-f**
|
||||||
|
|
||||||
Do not prompt for confirmation
|
Do not prompt for confirmation
|
||||||
|
@ -35,3 +50,4 @@ podman(1), podman-image-prune(1), podman-container-prune(1), podman-pod-prune(1)
|
||||||
|
|
||||||
## HISTORY
|
## HISTORY
|
||||||
February 2019, Originally compiled by Dan Walsh (dwalsh at redhat dot com)
|
February 2019, Originally compiled by Dan Walsh (dwalsh at redhat dot com)
|
||||||
|
December 2020, converted filter information from docs.docker.com documentation by Dan Walsh (dwalsh at redhat dot com)
|
||||||
|
|
|
@ -19,6 +19,7 @@ type ServiceOptions struct {
|
||||||
type SystemPruneOptions struct {
|
type SystemPruneOptions struct {
|
||||||
All bool
|
All bool
|
||||||
Volume bool
|
Volume bool
|
||||||
|
Filter []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// SystemPruneReport provides report after system prune is executed.
|
// SystemPruneReport provides report after system prune is executed.
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -179,7 +180,16 @@ func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.Sys
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
systemPruneReport.PodPruneReport = append(systemPruneReport.PodPruneReport, podPruneReport...)
|
systemPruneReport.PodPruneReport = append(systemPruneReport.PodPruneReport, podPruneReport...)
|
||||||
containerPruneReport, err := ic.pruneContainersHelper(nil)
|
containerPruneOptions := entities.ContainerPruneOptions{}
|
||||||
|
for _, f := range options.Filter {
|
||||||
|
t := strings.SplitN(f, "=", 2)
|
||||||
|
containerPruneOptions.Filters = make(url.Values)
|
||||||
|
if len(t) < 2 {
|
||||||
|
return nil, errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
|
||||||
|
}
|
||||||
|
containerPruneOptions.Filters.Add(t[0], t[1])
|
||||||
|
}
|
||||||
|
containerPruneReport, err := ic.ContainerPrune(ctx, containerPruneOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -194,7 +204,7 @@ func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.Sys
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
results, err := ic.Libpod.ImageRuntime().PruneImages(ctx, options.All, nil)
|
results, err := ic.Libpod.ImageRuntime().PruneImages(ctx, options.All, options.Filter)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue