mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
added remove capabilities for pod
This commit is contained in:
parent
8ed81e4ec9
commit
64297ad1d5
7 changed files with 79 additions and 1 deletions
|
|
@ -3,10 +3,12 @@ package commands
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sasha-s/go-deadlock"
|
"github.com/sasha-s/go-deadlock"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Pod represents a Podman pod with its containers.
|
// Pod represents a Podman pod with its containers.
|
||||||
|
|
@ -69,6 +71,24 @@ func (p *Pod) Unpause() error {
|
||||||
return p.Runtime.UnpausePod(ctx, p.ID)
|
return p.Runtime.UnpausePod(ctx, p.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove removes the pod
|
||||||
|
func (p *Pod) Remove(force bool) error {
|
||||||
|
p.Log.Warn(fmt.Sprintf("removing pod %s", p.Name))
|
||||||
|
ctx := context.Background()
|
||||||
|
if err := p.Runtime.RemovePod(ctx, p.ID, force); err != nil {
|
||||||
|
if strings.Contains(err.Error(), "pod is running") ||
|
||||||
|
strings.Contains(err.Error(), "stop the pod before attempting removal") {
|
||||||
|
return ComplexError{
|
||||||
|
Code: MustStopContainer,
|
||||||
|
Message: err.Error(),
|
||||||
|
frame: xerrors.Caller(1),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// HasContainers returns true if the pod has non-infra containers.
|
// HasContainers returns true if the pod has non-infra containers.
|
||||||
func (p *Pod) HasContainers() bool {
|
func (p *Pod) HasContainers() bool {
|
||||||
return len(p.Containers) > 0
|
return len(p.Containers) > 0
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ type ContainerRuntime interface {
|
||||||
StopPod(ctx context.Context, id string, timeout *int) error
|
StopPod(ctx context.Context, id string, timeout *int) error
|
||||||
PausePod(ctx context.Context, id string) error
|
PausePod(ctx context.Context, id string) error
|
||||||
UnpausePod(ctx context.Context, id string) error
|
UnpausePod(ctx context.Context, id string) error
|
||||||
|
RemovePod(ctx context.Context, id string, force bool) error
|
||||||
|
|
||||||
// Events streams container/image/volume/network events
|
// Events streams container/image/volume/network events
|
||||||
Events(ctx context.Context) (<-chan Event, <-chan error)
|
Events(ctx context.Context) (<-chan Event, <-chan error)
|
||||||
|
|
|
||||||
|
|
@ -493,6 +493,16 @@ func (r *LibpodRuntime) UnpausePod(ctx context.Context, id string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemovePod removes a pod from the system.
|
||||||
|
func (r *LibpodRuntime) RemovePod(ctx context.Context, id string, force bool) error {
|
||||||
|
pod, err := r.runtime.LookupPod(id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = r.runtime.RemovePod(ctx, pod, true, force, 0)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Events streams container runtime events.
|
// Events streams container runtime events.
|
||||||
// For libpod, we use a polling approach since direct event streaming requires more setup.
|
// For libpod, we use a polling approach since direct event streaming requires more setup.
|
||||||
func (r *LibpodRuntime) Events(ctx context.Context) (<-chan Event, <-chan error) {
|
func (r *LibpodRuntime) Events(ctx context.Context) (<-chan Event, <-chan error) {
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,10 @@ func (r *LibpodRuntime) UnpausePod(ctx context.Context, id string) error {
|
||||||
return ErrLibpodNotAvailable
|
return ErrLibpodNotAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *LibpodRuntime) RemovePod(ctx context.Context, id string, force bool) error {
|
||||||
|
return ErrLibpodNotAvailable
|
||||||
|
}
|
||||||
|
|
||||||
// Events returns an error channel on non-Linux platforms.
|
// Events returns an error channel on non-Linux platforms.
|
||||||
func (r *LibpodRuntime) Events(ctx context.Context) (<-chan Event, <-chan error) {
|
func (r *LibpodRuntime) Events(ctx context.Context) (<-chan Event, <-chan error) {
|
||||||
eventsChan := make(chan Event)
|
eventsChan := make(chan Event)
|
||||||
|
|
|
||||||
|
|
@ -309,6 +309,11 @@ func (m *MockRuntime) UnpausePod(ctx context.Context, id string) error {
|
||||||
return ErrMockNotImplemented
|
return ErrMockNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MockRuntime) RemovePod(ctx context.Context, id string, force bool) error {
|
||||||
|
m.recordCall("RemovePod", id, force)
|
||||||
|
return ErrMockNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
|
|
||||||
func (m *MockRuntime) Events(ctx context.Context) (<-chan Event, <-chan error) {
|
func (m *MockRuntime) Events(ctx context.Context) (<-chan Event, <-chan error) {
|
||||||
|
|
|
||||||
|
|
@ -374,6 +374,13 @@ func (r *SocketRuntime) UnpausePod(ctx context.Context, id string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemovePod removes a pod from the system.
|
||||||
|
func (r *SocketRuntime) RemovePod(ctx context.Context, id string, force bool) error {
|
||||||
|
opts := &pods.RemoveOptions{Force: &force}
|
||||||
|
_, err := pods.Remove(r.conn, id, opts)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// aggregatePodStats combines stats from all containers in a pod into a single entry.
|
// aggregatePodStats combines stats from all containers in a pod into a single entry.
|
||||||
func aggregatePodStats(reports []*types.PodStatsReport) PodStatsEntry {
|
func aggregatePodStats(reports []*types.PodStatsReport) PodStatsEntry {
|
||||||
if len(reports) == 0 {
|
if len(reports) == 0 {
|
||||||
|
|
|
||||||
|
|
@ -473,7 +473,38 @@ func (gui *Gui) handleContainersRemoveMenu(g *gocui.Gui, v *gocui.View) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.IsPod {
|
if item.IsPod {
|
||||||
return gui.createErrorPanel("Remove not yet supported for pods")
|
pod := item.Pod
|
||||||
|
handleMenuPress := func(force bool) error {
|
||||||
|
return gui.WithWaitingStatus(gui.Tr.RemovingStatus, func() error {
|
||||||
|
if err := pod.Remove(force); err != nil {
|
||||||
|
if commands.HasErrorCode(err, commands.MustStopContainer) {
|
||||||
|
return gui.createConfirmationPanel(gui.Tr.Confirm, gui.Tr.MustForceToRemoveContainer, func(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
return gui.WithWaitingStatus(gui.Tr.RemovingStatus, func() error {
|
||||||
|
return pod.Remove(true)
|
||||||
|
})
|
||||||
|
}, nil)
|
||||||
|
}
|
||||||
|
return gui.createErrorPanel(err.Error())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
menuItems := []*types.MenuItem{
|
||||||
|
{
|
||||||
|
LabelColumns: []string{gui.Tr.Remove, "podman pod rm " + pod.ID[1:10]},
|
||||||
|
OnPress: func() error { return handleMenuPress(false) },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
LabelColumns: []string{gui.Tr.ForceRemove, "podman pod rm -f " + pod.ID[1:10]},
|
||||||
|
OnPress: func() error { return handleMenuPress(true) },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.Menu(CreateMenuOptions{
|
||||||
|
Title: "",
|
||||||
|
Items: menuItems,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
ctr := item.Container
|
ctr := item.Container
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue