Skip to content

Commit

Permalink
[NO TESTS NEEDED] Ignore removed containers
Browse files Browse the repository at this point in the history
* Ignore condition when containers are removed while listing them for
ps output.

  No tests added at this time as they would create a race condition for
CI.

* Updated godocs

See containers#11810 for reproducer.

Fixes containers#11810

Signed-off-by: Jhon Honce <jhonce@redhat.com>
  • Loading branch information
jwhonce committed Oct 1, 2021
1 parent e9d8524 commit c67593d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pkg/domain/entities/container_ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
"github.com/pkg/errors"
)

// Listcontainer describes a container suitable for listing
// ListContainer describes a container suitable for listing
type ListContainer struct {
// AutoRemove
AutoRemove bool
// Container command
Command []string
// Container creation time
Created time.Time
// Human readable container creation time.
// Human-readable container creation time.
CreatedAt string
// If container has exited/stopped
Exited bool
Expand Down Expand Up @@ -65,7 +65,7 @@ type ListContainer struct {
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 {
// Mount namespace
MNT string `json:"Mnt,omitempty"`
Expand Down
21 changes: 15 additions & 6 deletions pkg/ps/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/containers/podman/v3/pkg/domain/filters"
psdefine "github.com/containers/podman/v3/pkg/ps/define"
"github.com/containers/storage"
"github.com/containers/storage/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -63,10 +64,14 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp
}
for _, con := range cons {
listCon, err := ListContainerBatch(runtime, con, options)
if err != nil {
switch {
case errors.Cause(err) == define.ErrNoSuchCtr:
continue
case err != nil:
return nil, err
default:
pss = append(pss, listCon)
}
pss = append(pss, listCon)
}

if options.All && options.External {
Expand All @@ -89,7 +94,7 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp
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) {
var (
pss = []entities.ListContainer{}
Expand All @@ -102,15 +107,19 @@ func GetExternalContainerLists(runtime *libpod.Runtime) ([]entities.ListContaine

for _, con := range externCons {
listCon, err := ListStorageContainer(runtime, con)
if err != nil {
switch {
case errors.Cause(err) == types.ErrLoadError:
continue
case err != nil:
return nil, err
default:
pss = append(pss, listCon)
}
pss = append(pss, listCon)
}
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.
func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities.ContainerListOptions) (entities.ListContainer, error) {
var (
Expand Down

0 comments on commit c67593d

Please sign in to comment.