summaryrefslogtreecommitdiff
path: root/pkg/adapter/pods.go
diff options
context:
space:
mode:
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 (