summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-04-17 08:55:59 -0700
committerGitHub <noreply@github.com>2019-04-17 08:55:59 -0700
commit799d4667c1c33ac025741e2082739999f5b4563a (patch)
tree9fe87a7fc5f470314f754b8452163c4f59fd1a2c /pkg
parentd0c5e216ca508d195b805d0e48b159cfbff868a9 (diff)
parent4319552cf89e72925a80c63f427e5ef0a6376046 (diff)
downloadpodman-799d4667c1c33ac025741e2082739999f5b4563a.tar.gz
podman-799d4667c1c33ac025741e2082739999f5b4563a.tar.bz2
podman-799d4667c1c33ac025741e2082739999f5b4563a.zip
Merge pull request #2936 from haircommander/pod-prune
Add podman pod prune
Diffstat (limited to 'pkg')
-rw-r--r--pkg/adapter/pods.go2
-rw-r--r--pkg/adapter/pods_remote.go31
-rw-r--r--pkg/adapter/runtime.go36
-rw-r--r--pkg/varlinkapi/pods.go22
4 files changed, 90 insertions, 1 deletions
diff --git a/pkg/adapter/pods.go b/pkg/adapter/pods.go
index 669971789..901c1857b 100644
--- a/pkg/adapter/pods.go
+++ b/pkg/adapter/pods.go
@@ -38,7 +38,7 @@ func (r *LocalRuntime) RemovePods(ctx context.Context, cli *cliconfig.PodRmValue
}
for _, p := range pods {
- if err := r.RemovePod(ctx, p, cli.Force, cli.Force); err != nil {
+ if err := r.Runtime.RemovePod(ctx, p, cli.Force, cli.Force); err != nil {
errs = append(errs, err)
} else {
podids = append(podids, p.ID())
diff --git a/pkg/adapter/pods_remote.go b/pkg/adapter/pods_remote.go
index 4a32607a2..00a5d9a32 100644
--- a/pkg/adapter/pods_remote.go
+++ b/pkg/adapter/pods_remote.go
@@ -214,6 +214,23 @@ func (r *LocalRuntime) GetAllPods() ([]*Pod, error) {
return pods, nil
}
+// GetPodsByStatus returns a slice of pods filtered by a libpod status
+func (r *LocalRuntime) GetPodsByStatus(statuses []string) ([]*Pod, error) {
+ podIDs, err := iopodman.GetPodsByStatus().Call(r.Conn, statuses)
+ if err != nil {
+ return nil, err
+ }
+ pods := make([]*Pod, 0, len(podIDs))
+ for _, p := range podIDs {
+ pod, err := r.LookupPod(p)
+ if err != nil {
+ return nil, err
+ }
+ pods = append(pods, pod)
+ }
+ return pods, nil
+}
+
// ID returns the id of a remote pod
func (p *Pod) ID() string {
return p.config.ID
@@ -508,3 +525,17 @@ func (p *Pod) GetPodStats(previousContainerStats map[string]*libpod.ContainerSta
}
return newContainerStats, nil
}
+
+// RemovePod removes a pod
+// If removeCtrs is specified, containers will be removed
+// Otherwise, a pod that is not empty will return an error and not be removed
+// If force is specified with removeCtrs, all containers will be stopped before
+// being removed
+// Otherwise, the pod will not be removed if any containers are running
+func (r *LocalRuntime) RemovePod(ctx context.Context, p *Pod, removeCtrs, force bool) error {
+ _, err := iopodman.RemovePod().Call(r.Conn, p.ID(), force)
+ if err != nil {
+ return err
+ }
+ return nil
+}
diff --git a/pkg/adapter/runtime.go b/pkg/adapter/runtime.go
index b5ec9f7a9..6ed9cee77 100644
--- a/pkg/adapter/runtime.go
+++ b/pkg/adapter/runtime.go
@@ -369,3 +369,39 @@ func (r *LocalRuntime) Diff(c *cliconfig.DiffValues, to string) ([]archive.Chang
func (r *LocalRuntime) GenerateKube(c *cliconfig.GenerateKubeValues) (*v1.Pod, *v1.Service, error) {
return shared.GenerateKube(c.InputArgs[0], c.Service, r.Runtime)
}
+
+// GetPodsByStatus returns a slice of pods filtered by a libpod status
+func (r *LocalRuntime) GetPodsByStatus(statuses []string) ([]*Pod, error) {
+ var adapterPods []*Pod
+
+ filterFunc := func(p *libpod.Pod) bool {
+ state, _ := shared.GetPodStatus(p)
+ for _, status := range statuses {
+ if state == status {
+ return true
+ }
+ }
+ return false
+ }
+ pods, err := r.Runtime.Pods(filterFunc)
+ if err != nil {
+ return nil, err
+ }
+ for _, p := range pods {
+ adapterPod := Pod{
+ p,
+ }
+ adapterPods = append(adapterPods, &adapterPod)
+ }
+ return adapterPods, nil
+}
+
+// RemovePod removes a pod
+// If removeCtrs is specified, containers will be removed
+// Otherwise, a pod that is not empty will return an error and not be removed
+// If force is specified with removeCtrs, all containers will be stopped before
+// being removed
+// Otherwise, the pod will not be removed if any containers are running
+func (r *LocalRuntime) RemovePod(ctx context.Context, p *Pod, removeCtrs, force bool) error {
+ return r.Runtime.RemovePod(ctx, p.Pod, removeCtrs, force)
+}
diff --git a/pkg/varlinkapi/pods.go b/pkg/varlinkapi/pods.go
index ac8e24747..f34375bf5 100644
--- a/pkg/varlinkapi/pods.go
+++ b/pkg/varlinkapi/pods.go
@@ -101,6 +101,28 @@ func (i *LibpodAPI) GetPod(call iopodman.VarlinkCall, name string) error {
return call.ReplyGetPod(listPod)
}
+// GetPodsByStatus returns a slice of pods filtered by a libpod status
+func (i *LibpodAPI) GetPodsByStatus(call iopodman.VarlinkCall, statuses []string) error {
+ filterFuncs := func(p *libpod.Pod) bool {
+ state, _ := shared.GetPodStatus(p)
+ for _, status := range statuses {
+ if state == status {
+ return true
+ }
+ }
+ return false
+ }
+ filteredPods, err := i.Runtime.Pods(filterFuncs)
+ if err != nil {
+ return call.ReplyErrorOccurred(err.Error())
+ }
+ podIDs := make([]string, 0, len(filteredPods))
+ for _, p := range filteredPods {
+ podIDs = append(podIDs, p.ID())
+ }
+ return call.ReplyGetPodsByStatus(podIDs)
+}
+
// InspectPod ...
func (i *LibpodAPI) InspectPod(call iopodman.VarlinkCall, name string) error {
pod, err := i.Runtime.LookupPod(name)