diff options
author | Peter Hunt <pehunt@redhat.com> | 2019-04-15 15:44:32 -0400 |
---|---|---|
committer | Peter Hunt <pehunt@redhat.com> | 2019-04-16 11:23:18 -0400 |
commit | 4319552cf89e72925a80c63f427e5ef0a6376046 (patch) | |
tree | 5a0e38e63a41fdafe7f5d08daf496a0d68341aae /pkg/adapter | |
parent | 0b34b4a59cf090a47a2a13cc4814954c497b3d49 (diff) | |
download | podman-4319552cf89e72925a80c63f427e5ef0a6376046.tar.gz podman-4319552cf89e72925a80c63f427e5ef0a6376046.tar.bz2 podman-4319552cf89e72925a80c63f427e5ef0a6376046.zip |
Added remote pod prune
Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'pkg/adapter')
-rw-r--r-- | pkg/adapter/pods.go | 2 | ||||
-rw-r--r-- | pkg/adapter/pods_remote.go | 31 | ||||
-rw-r--r-- | pkg/adapter/runtime.go | 36 | ||||
-rw-r--r-- | pkg/adapter/runtime_remote.go | 18 |
4 files changed, 68 insertions, 19 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/adapter/runtime_remote.go b/pkg/adapter/runtime_remote.go index 08f421595..71f7380db 100644 --- a/pkg/adapter/runtime_remote.go +++ b/pkg/adapter/runtime_remote.go @@ -527,24 +527,6 @@ func (r *LocalRuntime) RemoveContainer(ctx context.Context, c *libpod.Container, return libpod.ErrNotImplemented } -// Pods retrieves all pods -// Filters can be provided which will determine which pods are included in the -// output. Multiple filters are handled by ANDing their output, so only pods -// matching all filters are returned -func (r *LocalRuntime) Pods(filters ...libpod.PodFilter) ([]*libpod.Pod, error) { - return nil, libpod.ErrNotImplemented -} - -// 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 *libpod.Pod, removeCtrs, force bool) error { - return libpod.ErrNotImplemented -} - // CreateVolume creates a volume over a varlink connection for the remote client func (r *LocalRuntime) CreateVolume(ctx context.Context, c *cliconfig.VolumeCreateValues, labels, opts map[string]string) (string, error) { cvOpts := iopodman.VolumeCreateOpts{ |