diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-01-25 23:23:39 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-25 23:23:39 -0800 |
commit | d07f611885311538895fe5b665dccf75d1448fc3 (patch) | |
tree | c308c5445220b675567d67e0e3c296d31b90528d /libpod/runtime_pod.go | |
parent | 689da532fa8f9c72d4fd7afe963d6eb44fe0e623 (diff) | |
parent | 5da70b04dd95263a536cc148288d2e20cd9dea30 (diff) | |
download | podman-d07f611885311538895fe5b665dccf75d1448fc3.tar.gz podman-d07f611885311538895fe5b665dccf75d1448fc3.tar.bz2 podman-d07f611885311538895fe5b665dccf75d1448fc3.zip |
Merge pull request #4965 from baude/reviewcorrections3
APIv2 review corrections #3
Diffstat (limited to 'libpod/runtime_pod.go')
-rw-r--r-- | libpod/runtime_pod.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libpod/runtime_pod.go b/libpod/runtime_pod.go index 66f9b10c9..e1dc31391 100644 --- a/libpod/runtime_pod.go +++ b/libpod/runtime_pod.go @@ -182,3 +182,31 @@ func (r *Runtime) GetRunningPods() ([]*Pod, error) { } return runningPods, nil } + +// PrunePods removes unused pods and their containers from local storage. +// If force is given, then running pods are also included in the pruning. +func (r *Runtime) PrunePods() (map[string]error, error) { + response := make(map[string]error) + states := []string{define.PodStateStopped, define.PodStateExited} + filterFunc := func(p *Pod) bool { + state, _ := p.GetPodStatus() + for _, status := range states { + if state == status { + return true + } + } + return false + } + pods, err := r.Pods(filterFunc) + if err != nil { + return nil, err + } + if len(pods) < 1 { + return response, nil + } + for _, pod := range pods { + err := r.removePod(context.TODO(), pod, true, false) + response[pod.ID()] = err + } + return response, nil +} |