summaryrefslogtreecommitdiff
path: root/pkg/adapter/pods.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2019-04-18 10:34:27 -0700
committerJhon Honce <jhonce@redhat.com>2019-04-18 15:13:56 -0700
commit69962682e990ddb9437291b98bd335e74c090fc8 (patch)
tree409dfe0466aa8024a6295e40901a17b8b62b8691 /pkg/adapter/pods.go
parente4947e5fd699f584cb815a4f4fd92f22b62f2c8a (diff)
downloadpodman-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.go')
-rw-r--r--pkg/adapter/pods.go51
1 files changed, 45 insertions, 6 deletions
diff --git a/pkg/adapter/pods.go b/pkg/adapter/pods.go
index 901c1857b..bb7d9cce6 100644
--- a/pkg/adapter/pods.go
+++ b/pkg/adapter/pods.go
@@ -4,20 +4,16 @@ package adapter
import (
"context"
- "github.com/pkg/errors"
"strings"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/adapter/shortcuts"
+ "github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
)
-// Pod ...
-type Pod struct {
- *libpod.Pod
-}
-
// PodContainerStats is struct containing an adapter Pod and a libpod
// ContainerStats and is used primarily for outputing pod stats.
type PodContainerStats struct {
@@ -25,6 +21,49 @@ type PodContainerStats struct {
ContainerStats map[string]*libpod.ContainerStats
}
+// PrunePods removes pods
+func (r *LocalRuntime) PrunePods(ctx context.Context, cli *cliconfig.PodPruneValues) ([]string, map[string]error, error) {
+ var (
+ ok = []string{}
+ failures = map[string]error{}
+ )
+
+ maxWorkers := shared.DefaultPoolSize("rm")
+ if cli.GlobalIsSet("max-workers") {
+ maxWorkers = cli.GlobalFlags.MaxWorks
+ }
+ logrus.Debugf("Setting maximum rm workers to %d", maxWorkers)
+
+ states := []string{shared.PodStateStopped, shared.PodStateExited}
+ if cli.Force {
+ states = append(states, shared.PodStateRunning)
+ }
+
+ pods, err := r.GetPodsByStatus(states)
+ if err != nil {
+ return ok, failures, err
+ }
+ if len(pods) < 1 {
+ return ok, failures, nil
+ }
+
+ pool := shared.NewPool("pod_prune", maxWorkers, len(pods))
+ for _, p := range pods {
+ p := p
+
+ pool.Add(shared.Job{p.ID(),
+ func() error {
+ err := r.Runtime.RemovePod(ctx, p, cli.Force, cli.Force)
+ if err != nil {
+ logrus.Debugf("Failed to remove pod %s: %s", p.ID(), err.Error())
+ }
+ return err
+ },
+ })
+ }
+ return pool.Run()
+}
+
// RemovePods ...
func (r *LocalRuntime) RemovePods(ctx context.Context, cli *cliconfig.PodRmValues) ([]string, []error) {
var (