Added remote pod prune
Signed-off-by: Peter Hunt <pehunt@redhat.com>
This commit is contained in:
parent
0b34b4a59c
commit
4319552cf8
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
"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"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
|
@ -43,15 +42,8 @@ func init() {
|
|||
func prunePods(runtime *adapter.LocalRuntime, ctx context.Context, maxWorkers int, force bool) error {
|
||||
var deleteFuncs []shared.ParallelWorkerInput
|
||||
|
||||
filter := func(p *libpod.Pod) bool {
|
||||
state, err := shared.GetPodStatus(p)
|
||||
// pod states should be the same
|
||||
if state == shared.PodStateStopped || (state == shared.PodStateExited && err == nil) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
delPods, err := runtime.Pods(filter)
|
||||
states := []string{shared.PodStateStopped, shared.PodStateExited}
|
||||
delPods, err := runtime.GetPodsByStatus(states)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1053,6 +1053,9 @@ method TopPod(pod: string, latest: bool, descriptors: []string) -> (stats: []str
|
|||
# ~~~
|
||||
method GetPodStats(name: string) -> (pod: string, containers: []ContainerStats)
|
||||
|
||||
# GetPodsByStatus searches for pods whose status is included in statuses
|
||||
method GetPodsByStatus(statuses: []string) -> (pods: []string)
|
||||
|
||||
# ImageExists talks a full or partial image ID or name and returns an int as to whether
|
||||
# the image exists in local storage. An int result of 0 means the image does exist in
|
||||
# local storage; whereas 1 indicates the image does not exists in local storage.
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue