summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-04-30 20:10:27 +0200
committerGitHub <noreply@github.com>2019-04-30 20:10:27 +0200
commite509eb25e7804c3d13e98fb6c788c739764016c4 (patch)
tree052396e79f9e099429e1aadd1afd34123fc4525e /pkg
parent75189d5b97d18d6b1a229e75d8427c85d2872d61 (diff)
parent1b2419ceb15b3c29b71c7d909ae143670d8a3a36 (diff)
downloadpodman-e509eb25e7804c3d13e98fb6c788c739764016c4.tar.gz
podman-e509eb25e7804c3d13e98fb6c788c739764016c4.tar.bz2
podman-e509eb25e7804c3d13e98fb6c788c739764016c4.zip
Merge pull request #2995 from jwhonce/wip/cleanup
Refactor container cleanup to use latest functions
Diffstat (limited to 'pkg')
-rw-r--r--pkg/adapter/containers.go42
-rw-r--r--pkg/adapter/containers_remote.go5
2 files changed, 47 insertions, 0 deletions
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go
index fb85e54ba..9ec897a60 100644
--- a/pkg/adapter/containers.go
+++ b/pkg/adapter/containers.go
@@ -834,3 +834,45 @@ func (r *LocalRuntime) Prune(ctx context.Context, maxWorkers int, force bool) ([
}
return pool.Run()
}
+
+// CleanupContainers any leftovers bits of stopped containers
+func (r *LocalRuntime) CleanupContainers(ctx context.Context, cli *cliconfig.CleanupValues) ([]string, map[string]error, error) {
+ var (
+ ok = []string{}
+ failures = map[string]error{}
+ )
+
+ ctrs, err := shortcuts.GetContainersByContext(cli.All, cli.Latest, cli.InputArgs, r.Runtime)
+ if err != nil {
+ return ok, failures, err
+ }
+
+ for _, ctr := range ctrs {
+ if cli.Remove {
+ err = removeContainer(ctx, ctr, r)
+ } else {
+ err = cleanupContainer(ctx, ctr, r)
+ }
+
+ if err == nil {
+ ok = append(ok, ctr.ID())
+ } else {
+ failures[ctr.ID()] = err
+ }
+ }
+ return ok, failures, nil
+}
+
+func removeContainer(ctx context.Context, ctr *libpod.Container, runtime *LocalRuntime) error {
+ if err := runtime.RemoveContainer(ctx, ctr, false, true); err != nil {
+ return errors.Wrapf(err, "failed to cleanup and remove container %v", ctr.ID())
+ }
+ return nil
+}
+
+func cleanupContainer(ctx context.Context, ctr *libpod.Container, runtime *LocalRuntime) error {
+ if err := ctr.Cleanup(ctx); err != nil {
+ return errors.Wrapf(err, "failed to cleanup container %v", ctr.ID())
+ }
+ return nil
+}
diff --git a/pkg/adapter/containers_remote.go b/pkg/adapter/containers_remote.go
index 5a67d4957..a3a48a564 100644
--- a/pkg/adapter/containers_remote.go
+++ b/pkg/adapter/containers_remote.go
@@ -883,3 +883,8 @@ func (r *LocalRuntime) Prune(ctx context.Context, maxWorkers int, force bool) ([
}
return ok, failures, nil
}
+
+// Cleanup any leftovers bits of stopped containers
+func (r *LocalRuntime) CleanupContainers(ctx context.Context, cli *cliconfig.CleanupValues) ([]string, map[string]error, error) {
+ return nil, nil, errors.New("container cleanup not supported for remote clients")
+}