aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman
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 /cmd/podman
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 'cmd/podman')
-rw-r--r--cmd/podman/cliconfig/config.go2
-rw-r--r--cmd/podman/pods_prune.go64
-rw-r--r--cmd/podman/system_prune.go10
3 files changed, 24 insertions, 52 deletions
diff --git a/cmd/podman/cliconfig/config.go b/cmd/podman/cliconfig/config.go
index 16c98a13e..640a4bff4 100644
--- a/cmd/podman/cliconfig/config.go
+++ b/cmd/podman/cliconfig/config.go
@@ -159,7 +159,7 @@ type PruneContainersValues struct {
Force bool
}
-type PrunePodsValues struct {
+type PodPruneValues struct {
PodmanCommand
Force bool
}
diff --git a/cmd/podman/pods_prune.go b/cmd/podman/pods_prune.go
index 89401a98a..e6946f068 100644
--- a/cmd/podman/pods_prune.go
+++ b/cmd/podman/pods_prune.go
@@ -1,19 +1,15 @@
package main
import (
- "context"
-
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
- "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var (
- prunePodsCommand cliconfig.PrunePodsValues
- prunePodsDescription = `
+ podPruneCommand cliconfig.PodPruneValues
+ podPruneDescription = `
podman pod prune
Removes all exited pods
@@ -22,62 +18,30 @@ var (
Use: "prune",
Args: noSubArgs,
Short: "Remove all stopped pods",
- Long: prunePodsDescription,
+ Long: podPruneDescription,
RunE: func(cmd *cobra.Command, args []string) error {
- prunePodsCommand.InputArgs = args
- prunePodsCommand.GlobalFlags = MainGlobalOpts
- return prunePodsCmd(&prunePodsCommand)
+ podPruneCommand.InputArgs = args
+ podPruneCommand.GlobalFlags = MainGlobalOpts
+ return podPruneCmd(&podPruneCommand)
},
}
)
func init() {
- prunePodsCommand.Command = _prunePodsCommand
- prunePodsCommand.SetHelpTemplate(HelpTemplate())
- prunePodsCommand.SetUsageTemplate(UsageTemplate())
- flags := prunePodsCommand.Flags()
- flags.BoolVarP(&prunePodsCommand.Force, "force", "f", false, "Force removal of a running pods. The default is false")
+ podPruneCommand.Command = _prunePodsCommand
+ podPruneCommand.SetHelpTemplate(HelpTemplate())
+ podPruneCommand.SetUsageTemplate(UsageTemplate())
+ flags := podPruneCommand.Flags()
+ flags.BoolVarP(&podPruneCommand.Force, "force", "f", false, "Force removal of a running pods. The default is false")
}
-func prunePods(runtime *adapter.LocalRuntime, ctx context.Context, maxWorkers int, force bool) error {
- var deleteFuncs []shared.ParallelWorkerInput
-
- states := []string{shared.PodStateStopped, shared.PodStateExited}
- delPods, err := runtime.GetPodsByStatus(states)
- if err != nil {
- return err
- }
- if len(delPods) < 1 {
- return nil
- }
- for _, pod := range delPods {
- p := pod
- f := func() error {
- return runtime.RemovePod(ctx, p, force, force)
- }
-
- deleteFuncs = append(deleteFuncs, shared.ParallelWorkerInput{
- ContainerID: p.ID(),
- ParallelFunc: f,
- })
- }
- // Run the parallel funcs
- deleteErrors, errCount := shared.ParallelExecuteWorkerPool(maxWorkers, deleteFuncs)
- return printParallelOutput(deleteErrors, errCount)
-}
-
-func prunePodsCmd(c *cliconfig.PrunePodsValues) error {
+func podPruneCmd(c *cliconfig.PodPruneValues) error {
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
- maxWorkers := shared.Parallelize("rm")
- if c.GlobalIsSet("max-workers") {
- maxWorkers = c.GlobalFlags.MaxWorks
- }
- logrus.Debugf("Setting maximum workers to %d", maxWorkers)
-
- return prunePods(runtime, getContext(), maxWorkers, c.Bool("force"))
+ ok, failures, err := runtime.PrunePods(getContext(), c)
+ return printCmdResults(ok, failures)
}
diff --git a/cmd/podman/system_prune.go b/cmd/podman/system_prune.go
index 14cb96941..8900e2644 100644
--- a/cmd/podman/system_prune.go
+++ b/cmd/podman/system_prune.go
@@ -82,13 +82,21 @@ Are you sure you want to continue? [y/N] `, volumeString)
ctx := getContext()
fmt.Println("Deleted Containers")
lasterr := pruneContainers(runtime, ctx, rmWorkers, false, false)
+
fmt.Println("Deleted Pods")
- if err := prunePods(runtime, ctx, rmWorkers, true); err != nil {
+ pruneValues := cliconfig.PodPruneValues{
+ PodmanCommand: c.PodmanCommand,
+ Force: c.Force,
+ }
+ ok, failures, err := runtime.PrunePods(ctx, &pruneValues)
+ if err != nil {
if lasterr != nil {
logrus.Errorf("%q", lasterr)
}
lasterr = err
}
+ printCmdResults(ok, failures)
+
if c.Bool("volumes") {
fmt.Println("Deleted Volumes")
err := volumePrune(runtime, getContext())