Merge pull request #11820 from jwhonce/issues/11810

[NO TESTS NEEDED] Ignore removed containers
This commit is contained in:
OpenShift Merge Robot
2021-10-02 07:46:05 -04:00
committed by GitHub
2 changed files with 18 additions and 9 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
// Listcontainer describes a container suitable for listing // ListContainer describes a container suitable for listing
type ListContainer struct { type ListContainer struct {
// AutoRemove // AutoRemove
AutoRemove bool AutoRemove bool
@ -18,7 +18,7 @@ type ListContainer struct {
Command []string Command []string
// Container creation time // Container creation time
Created time.Time Created time.Time
// Human readable container creation time. // Human-readable container creation time.
CreatedAt string CreatedAt string
// If container has exited/stopped // If container has exited/stopped
Exited bool Exited bool
@ -65,7 +65,7 @@ type ListContainer struct {
Status string Status string
} }
// ListContainer Namespaces contains the identifiers of the container's Linux namespaces // ListContainerNamespaces contains the identifiers of the container's Linux namespaces
type ListContainerNamespaces struct { type ListContainerNamespaces struct {
// Mount namespace // Mount namespace
MNT string `json:"Mnt,omitempty"` MNT string `json:"Mnt,omitempty"`

View File

@ -15,6 +15,7 @@ import (
"github.com/containers/podman/v3/pkg/domain/filters" "github.com/containers/podman/v3/pkg/domain/filters"
psdefine "github.com/containers/podman/v3/pkg/ps/define" psdefine "github.com/containers/podman/v3/pkg/ps/define"
"github.com/containers/storage" "github.com/containers/storage"
"github.com/containers/storage/types"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -63,11 +64,15 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp
} }
for _, con := range cons { for _, con := range cons {
listCon, err := ListContainerBatch(runtime, con, options) listCon, err := ListContainerBatch(runtime, con, options)
if err != nil { switch {
case errors.Cause(err) == define.ErrNoSuchCtr:
continue
case err != nil:
return nil, err return nil, err
} default:
pss = append(pss, listCon) pss = append(pss, listCon)
} }
}
if options.All && options.External { if options.All && options.External {
listCon, err := GetExternalContainerLists(runtime) listCon, err := GetExternalContainerLists(runtime)
@ -89,7 +94,7 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp
return pss, nil return pss, nil
} }
// GetExternalContainerLists returns list of external containers for e.g created by buildah // GetExternalContainerLists returns list of external containers for e.g. created by buildah
func GetExternalContainerLists(runtime *libpod.Runtime) ([]entities.ListContainer, error) { func GetExternalContainerLists(runtime *libpod.Runtime) ([]entities.ListContainer, error) {
var ( var (
pss = []entities.ListContainer{} pss = []entities.ListContainer{}
@ -102,15 +107,19 @@ func GetExternalContainerLists(runtime *libpod.Runtime) ([]entities.ListContaine
for _, con := range externCons { for _, con := range externCons {
listCon, err := ListStorageContainer(runtime, con) listCon, err := ListStorageContainer(runtime, con)
if err != nil { switch {
case errors.Cause(err) == types.ErrLoadError:
continue
case err != nil:
return nil, err return nil, err
} default:
pss = append(pss, listCon) pss = append(pss, listCon)
} }
}
return pss, nil return pss, nil
} }
// BatchContainerOp is used in ps to reduce performance hits by "batching" // ListContainerBatch is used in ps to reduce performance hits by "batching"
// locks. // locks.
func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities.ContainerListOptions) (entities.ListContainer, error) { func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities.ContainerListOptions) (entities.ListContainer, error) {
var ( var (