summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-06-30 05:33:21 -0400
committerGitHub <noreply@github.com>2021-06-30 05:33:21 -0400
commit78a3605018038d26a9e8868b6ed6ab01146be423 (patch)
tree253d9db10a45dbcb1baedd94715e93a8bdea27c8 /pkg
parent0d8d805a76762276c62bd7260a39eb26e99722b4 (diff)
parent2243b6020330ea06abdb594db9c6c8ff429cfc5d (diff)
downloadpodman-78a3605018038d26a9e8868b6ed6ab01146be423.tar.gz
podman-78a3605018038d26a9e8868b6ed6ab01146be423.tar.bz2
podman-78a3605018038d26a9e8868b6ed6ab01146be423.zip
Merge pull request #10789 from flouthoc/system-reset-prune-external
reset: remove external containers on podman system reset
Diffstat (limited to 'pkg')
-rw-r--r--pkg/domain/entities/engine_container.go1
-rw-r--r--pkg/domain/infra/abi/containers.go4
-rw-r--r--pkg/domain/infra/tunnel/containers.go6
-rw-r--r--pkg/ps/ps.go34
4 files changed, 35 insertions, 10 deletions
diff --git a/pkg/domain/entities/engine_container.go b/pkg/domain/entities/engine_container.go
index f695d32fd..4cd3cfd2a 100644
--- a/pkg/domain/entities/engine_container.go
+++ b/pkg/domain/entities/engine_container.go
@@ -32,6 +32,7 @@ type ContainerEngine interface {
ContainerInspect(ctx context.Context, namesOrIds []string, options InspectOptions) ([]*ContainerInspectReport, []error, error)
ContainerKill(ctx context.Context, namesOrIds []string, options KillOptions) ([]*KillReport, error)
ContainerList(ctx context.Context, options ContainerListOptions) ([]ListContainer, error)
+ ContainerListExternal(ctx context.Context) ([]ListContainer, error)
ContainerLogs(ctx context.Context, containers []string, options ContainerLogsOptions) error
ContainerMount(ctx context.Context, nameOrIDs []string, options ContainerMountOptions) ([]*ContainerMountReport, error)
ContainerPause(ctx context.Context, namesOrIds []string, options PauseUnPauseOptions) ([]*PauseUnpauseReport, error)
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index e6dd19e63..47fa553ce 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -854,6 +854,10 @@ func (ic *ContainerEngine) ContainerList(ctx context.Context, options entities.C
return ps.GetContainerLists(ic.Libpod, options)
}
+func (ic *ContainerEngine) ContainerListExternal(ctx context.Context) ([]entities.ListContainer, error) {
+ return ps.GetExternalContainerLists(ic.Libpod)
+}
+
// ContainerDiff provides changes to given container
func (ic *ContainerEngine) ContainerDiff(ctx context.Context, nameOrID string, opts entities.DiffOptions) (*entities.DiffReport, error) {
if opts.Latest {
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go
index 0047fc839..ccebfffa4 100644
--- a/pkg/domain/infra/tunnel/containers.go
+++ b/pkg/domain/infra/tunnel/containers.go
@@ -646,6 +646,12 @@ func (ic *ContainerEngine) ContainerList(ctx context.Context, opts entities.Cont
return containers.List(ic.ClientCtx, options)
}
+func (ic *ContainerEngine) ContainerListExternal(ctx context.Context) ([]entities.ListContainer, error) {
+ options := new(containers.ListOptions).WithAll(true)
+ options.WithNamespace(true).WithSize(true).WithSync(true).WithExternal(true)
+ return containers.List(ic.ClientCtx, options)
+}
+
func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.ContainerRunOptions) (*entities.ContainerRunReport, error) {
con, err := containers.CreateWithSpec(ic.ClientCtx, opts.Spec, nil)
if err != nil {
diff --git a/pkg/ps/ps.go b/pkg/ps/ps.go
index 0b76636de..ef79973d6 100644
--- a/pkg/ps/ps.go
+++ b/pkg/ps/ps.go
@@ -71,18 +71,11 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp
}
if options.All && options.External {
- externCons, err := runtime.StorageContainers()
+ listCon, err := GetExternalContainerLists(runtime)
if err != nil {
return nil, err
}
-
- for _, con := range externCons {
- listCon, err := ListStorageContainer(runtime, con, options)
- if err != nil {
- return nil, err
- }
- pss = append(pss, listCon)
- }
+ pss = append(pss, listCon...)
}
// Sort the containers we got
@@ -97,6 +90,27 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp
return pss, nil
}
+// GetExternalContainerLists returns list of external containers for e.g created by buildah
+func GetExternalContainerLists(runtime *libpod.Runtime) ([]entities.ListContainer, error) {
+ var (
+ pss = []entities.ListContainer{}
+ )
+
+ externCons, err := runtime.StorageContainers()
+ if err != nil {
+ return nil, err
+ }
+
+ for _, con := range externCons {
+ listCon, err := ListStorageContainer(runtime, con)
+ if err != nil {
+ return nil, err
+ }
+ pss = append(pss, listCon)
+ }
+ return pss, nil
+}
+
// BatchContainerOp is used in ps to reduce performance hits by "batching"
// locks.
func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities.ContainerListOptions) (entities.ListContainer, error) {
@@ -231,7 +245,7 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities
return ps, nil
}
-func ListStorageContainer(rt *libpod.Runtime, ctr storage.Container, opts entities.ContainerListOptions) (entities.ListContainer, error) {
+func ListStorageContainer(rt *libpod.Runtime, ctr storage.Container) (entities.ListContainer, error) {
name := "unknown"
if len(ctr.Names) > 0 {
name = ctr.Names[0]