diff options
author | Jhon Honce <jhonce@redhat.com> | 2019-04-18 10:34:27 -0700 |
---|---|---|
committer | Jhon Honce <jhonce@redhat.com> | 2019-04-18 15:13:56 -0700 |
commit | 69962682e990ddb9437291b98bd335e74c090fc8 (patch) | |
tree | 409dfe0466aa8024a6295e40901a17b8b62b8691 /pkg/adapter/pods_remote.go | |
parent | e4947e5fd699f584cb815a4f4fd92f22b62f2c8a (diff) | |
download | podman-69962682e990ddb9437291b98bd335e74c090fc8.tar.gz podman-69962682e990ddb9437291b98bd335e74c090fc8.tar.bz2 podman-69962682e990ddb9437291b98bd335e74c090fc8.zip |
Refactor of 'podman prune' to better support remote
* Push iterations into the service not the client
* Add e2e tests
* Refactor to use new frameworks
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'pkg/adapter/pods_remote.go')
-rw-r--r-- | pkg/adapter/pods_remote.go | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/pkg/adapter/pods_remote.go b/pkg/adapter/pods_remote.go index 00a5d9a32..7cf38aac0 100644 --- a/pkg/adapter/pods_remote.go +++ b/pkg/adapter/pods_remote.go @@ -14,13 +14,9 @@ import ( "github.com/containers/libpod/libpod" "github.com/containers/libpod/pkg/varlinkapi" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) -// Pod ... -type Pod struct { - remotepod -} - // PodContainerStats is struct containing an adapter Pod and a libpod // ContainerStats and is used primarily for outputing pod stats. type PodContainerStats struct { @@ -28,13 +24,6 @@ type PodContainerStats struct { ContainerStats map[string]*libpod.ContainerStats } -type remotepod struct { - config *libpod.PodConfig - state *libpod.PodInspectState - containers []libpod.PodContainerInfo - Runtime *LocalRuntime -} - // RemovePods removes one or more based on the cli context. func (r *LocalRuntime) RemovePods(ctx context.Context, cli *cliconfig.PodRmValues) ([]string, []error) { var ( @@ -539,3 +528,34 @@ func (r *LocalRuntime) RemovePod(ctx context.Context, p *Pod, removeCtrs, force } return nil } + +// PrunePods... +func (r *LocalRuntime) PrunePods(ctx context.Context, cli *cliconfig.PodPruneValues) ([]string, map[string]error, error) { + var ( + ok = []string{} + failures = map[string]error{} + ) + states := []string{shared.PodStateStopped, shared.PodStateExited} + if cli.Force { + states = append(states, shared.PodStateRunning) + } + + ids, err := iopodman.GetPodsByStatus().Call(r.Conn, states) + if err != nil { + return ok, failures, err + } + if len(ids) < 1 { + return ok, failures, nil + } + + for _, id := range ids { + _, err := iopodman.RemovePod().Call(r.Conn, id, cli.Force) + if err != nil { + logrus.Debugf("Failed to remove pod %s: %s", id, err.Error()) + failures[id] = err + } else { + ok = append(ok, id) + } + } + return ok, failures, nil +} |