Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show c/storage (Buildah/CRI-O) containers in ps #7290

Merged
merged 1 commit into from
Sep 9, 2020

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Aug 11, 2020

The podman ps --all command will now show containers that
are under the control of other c/storage container systems and
the new ps --external option will show only containers that are
in c/storage but are not controlled by libpod.

In the below examples, the '*working-container' entries were created
by Buildah.

podman ps -a
CONTAINER ID  IMAGE                             COMMAND  CREATED       STATUS                   PORTS  NAMES
9257ef8c786c  docker.io/library/busybox:latest  ls /etc  8 hours ago   Exited (0) 8 hours ago          gifted_jang
d302c81856da  docker.io/library/busybox:latest  buildah  30 hours ago  external                        busybox-working-container
7a5a7b099d33  localhost/tom:latest              ls -alF  30 hours ago  Exited (0) 30 hours ago         hopeful_hellman
01d601fca090  localhost/tom:latest              ls -alf  30 hours ago  Exited (1) 30 hours ago         determined_panini
ee58f429ff26  localhost/tom:latest              buildah  33 hours ago  external                        alpine-working-container

podman ps --external
CONTAINER ID  IMAGE                             COMMAND  CREATED       STATUS    PORTS  NAMES
d302c81856da  docker.io/library/busybox:latest  buildah  30 hours ago  external         busybox-working-container
ee58f429ff26  localhost/tom:latest              buildah  33 hours ago  external         alpine-working-container

Signed-off-by: TomSweeneyRedHat [email protected]
Signed-off-by: Daniel J Walsh [email protected]

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 11, 2020
@rhatdan rhatdan changed the title Show c/storage (Buildah/CRI-O) containers in ps [WIP] Show c/storage (Buildah/CRI-O) containers in ps Aug 11, 2020
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 11, 2020
@@ -56,10 +57,10 @@ func init() {
func listFlagSet(flags *pflag.FlagSet) {
flags.BoolVarP(&listOpts.All, "all", "a", false, "Show all the containers, default is only running containers")
flags.StringSliceVarP(&filters, "filter", "f", []string{}, "Filter output based on conditions given")
flags.BoolVar(&listOpts.External, "external", true, "Show containers in storage not controlled by Podman")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we should use --storage here for consistency with podman rm --storage

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this.

@rhatdan rhatdan force-pushed the external branch 4 times, most recently from d25a551 to aeef06e Compare August 16, 2020 11:42
@rhatdan rhatdan force-pushed the external branch 3 times, most recently from ff2b7a7 to 985e7aa Compare August 25, 2020 12:19
@rhatdan rhatdan changed the title [WIP] Show c/storage (Buildah/CRI-O) containers in ps Show c/storage (Buildah/CRI-O) containers in ps Aug 25, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 25, 2020
// StorageContainers returns a list of containers from containers/storage that
// are not currently known to Podman. The list of containers passed in are all
// of the containers known to Podman from the GetContainers() function.
func (r *Runtime) StorageContainers() ([]*Container, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't make this return Libpod containers - having a bunch of semi-functional things wandering around calling themselves a libpod.Container is asking for trouble (they don't have valid locks, for example, we'll panic the moment someone tries to call a real Libpod function on one of them). I think we need a separate API for this, that returns something like []*StorageContainer - we can translate those into the PS container struct in pkg/domain, so the code in PS will remain unchanged.


Display containers that are not controlled by Podman but are stored in containers storage. These containers
are generally created via other container technology such as Buildah or CRI-O and may depend on the
same container images that Podman is using. These containers are denoted with a 'NA' in the COMMAND and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the 'NA' still apply? Your example shows 'Buildah`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, good catch.

@@ -32,12 +32,19 @@ all the containers information. By default it lists:

**--all**, **-a**

Show all the containers, default is only running containers
Show all the containers including those created by other container technologies such as Buildah and CRI-O. The default displays only running containers created by Podman. Containers not created by Podman have an 'NA' status.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto 'NA' as to below.


// We only have a store when doing all, storage or size, so skip this otherwise.
if r.store == nil {
return retCtrs, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be an error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? All of the other checks ignore this issue and just return success?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having no store is something that we deliberately did ourselves - we should never be calling this in a case where the store is not set up, so returning an error seems correct

return retCtrs, errors.Wrapf(err, "error reading list of all containers")
}
for _, container := range storeContainers {
if _, err := r.state.Container(container.ID); err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use HasContainer instead - is a lot faster

@rhatdan rhatdan force-pushed the external branch 3 times, most recently from f1686ce to 4cc6c75 Compare August 26, 2020 10:06
@TomSweeneyRedHat
Copy link
Member

@rhatdan gating issue, looks like a man page needs tweaking.

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been wanting this feature for a long time, thank you!

I'd love to see tests, but that's hard: you need to interrupt a podman-build in just the right way. I'll see if I can figure it out for a followup PR.

@edsantiago
Copy link
Member

/hold

Possible bug. Will report in full in a few minutes, but I need time to investigate. Please do not merge yet.

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 1, 2020
Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic bug. I happened to have leftover buildah containers on my system; as submitted, this PR was only showing them when I specified --all but not with --storage. Trivial fix.

(And, if you agree with my "non-running" doc change below, please include that too)

@@ -56,9 +57,9 @@ func init() {
func listFlagSet(flags *pflag.FlagSet) {
flags.BoolVarP(&listOpts.All, "all", "a", false, "Show all the containers, default is only running containers")
flags.StringSliceVarP(&filters, "filter", "f", []string{}, "Filter output based on conditions given")
flags.BoolVar(&listOpts.Storage, "storage", true, "Show containers in storage not controlled by Podman")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should default to false

@@ -68,7 +69,31 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp
return nil, err
}
pss = append(pss, listCon)
}

if options.All && options.Storage {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ||, not &&'

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mheon
Copy link
Member

mheon commented Sep 1, 2020 via email

@edsantiago
Copy link
Member

I'd prefer it if we took the all flag out of the picture entirely

I was ambivalent at first -- it does significantly change the behavior of ps -a -- but the more I think about it the more I really want it in ps -a.

Disturbingly often I find myself in annoying situations where podman rm and rmi start complaining at me about "in use by a container" or something like that. podman ps -a shows nothing. I've trained myself to run buildah containers and buildah rm, and that usually fixes things (typically leftovers from a failed podman build). I think normal humans might not knoow to do this, and would appreciate ps -a showing something useful.

This still leaves the problem of removing those containers. podman rm and rm --storage aren't actually very helpful here. But we can address that later.

@mheon
Copy link
Member

mheon commented Sep 1, 2020

I would really prefer the opposite, because I don't want people to see these containers and then try using them with other Podman commands. The output of ps may not be as complete as it should be, but I strongly suspect people will not be able to identify what is a storage container and what is a Podman container on first glance, and they will try and interact with these containers using the standard Podman commands (podman start, podman rm, podman inspect, etc) and will get a series of wonderfully contradictory "that container does not exist" errors. We need to make this an explicit thing people opt into to prevent normal operation of Podman from becoming horribly confusing.

This is really a no-win scenario - we can either show them and confuse people as to why they don't act like normal Podman containers, or not show them and confuse people as to why they see errors that their image is "in use".

@edsantiago
Copy link
Member

That's a good point. I defer to you in this matter. And I agree that it's a no-win.

@edsantiago
Copy link
Member

Proposed test: run a long build with a short timeout:

@test "podman ps --storage" {
    PODMAN_TIMEOUT=5 run_podman 124 build -t thiswillneverexist - <<EOF
FROM $IMAGE
RUN sleep 15
EOF

    run_podman ps --storage
    is "${lines[1]}" \
       "[0-9a-f]\{12\} \+$IMAGE *buildah .* seconds ago .* storage .* ${PODMAN_TEST_IMAGE_NAME}-working-container" \
       "podman ps --storage"

    run_podman rm --storage -f "${lines[1]:0:12}"
}

Requires minor surgery to helpers.bash, so please don't include in your PR. I'm commenting here just to see if anyone has better ideas on how to test. I don't like this because it adds 15 seconds to the already-long system test run time. Any other ideas?

@rhatdan
Copy link
Member Author

rhatdan commented Sep 2, 2020

We can discuss this next week, but I am preparing to make these containers first class within podman, IE allow podman ps -a to show them by default. Allow podman rm to remove them by default. Allow podman diff to show the difference by default (Something requested by CRI-O).

Users do not understand these and do not understand how to use them. If we make --storage the default and properly show that they are not libpod containers, I believe the user experience will be better for the users.

$ ./bin/podman ps -a
CONTAINER ID  IMAGE   COMMAND  CREATED  STATUS  PORTS   NAMES
$ buildah from alpine
alpine-working-container
 $ ./bin/podman ps -a
CONTAINER ID  IMAGE                            COMMAND  CREATED        STATUS   PORTS   NAMES
84c690fc961c  docker.io/library/alpine:latest  buildah  2 seconds ago  storage          alpine-working-container
$ ./bin/podman rm alpine-working-container
alpine-working-container

These containers are unknown by libpod but Podman should be able to deal with them.
We can allow the storage flag to be set in containers.conf to allow us to get back to the current behaviour if users and distros want, but I think that these containers not being usable by default is a User Interface failure.

@TomSweeneyRedHat
Copy link
Member

I second the thought of a post scrum chat on how ps should show the variety of containers next week, fwiw.

@mheon
Copy link
Member

mheon commented Sep 2, 2020

Concur. I still have serious doubts (we can maybe get a few commands to work in an OK-ish way, but the vast majority of Podman will never work with these containers)

@vrothberg
Copy link
Member

vrothberg commented Sep 7, 2020

Just a friendly ping to bump the issue up in the mailboxes. Let's chat in tomorrows water cooler.

@rhatdan
Copy link
Member Author

rhatdan commented Sep 8, 2020

@vrothberg @giuseppe @mheon @baude @jwhonce @ashley-cui @QiWang19 This is less controversial now since the --format is defaulted to false.

The `podman ps --all` command will now show containers that
are under the control of other c/storage container systems and
the new `ps --storage` option will show only containers that are
in c/storage but are not controlled by libpod.

In the below examples, the '*working-container' entries were created
by Buildah.

```
podman ps -a
CONTAINER ID  IMAGE                             COMMAND  CREATED       STATUS                   PORTS  NAMES
9257ef8c786c  docker.io/library/busybox:latest  ls /etc  8 hours ago   Exited (0) 8 hours ago          gifted_jang
d302c81856da  docker.io/library/busybox:latest  buildah  30 hours ago  storage                         busybox-working-container
7a5a7b099d33  localhost/tom:latest              ls -alF  30 hours ago  Exited (0) 30 hours ago         hopeful_hellman
01d601fca090  localhost/tom:latest              ls -alf  30 hours ago  Exited (1) 30 hours ago         determined_panini
ee58f429ff26  localhost/tom:latest              buildah  33 hours ago  storage                         alpine-working-container

podman ps --external
CONTAINER ID  IMAGE                             COMMAND  CREATED       STATUS    PORTS  NAMES
d302c81856da  docker.io/library/busybox:latest  buildah  30 hours ago  external         busybox-working-container
ee58f429ff26  localhost/tom:latest              buildah  33 hours ago  external         alpine-working-container

```
Signed-off-by: TomSweeneyRedHat <[email protected]>
Signed-off-by: Daniel J Walsh <[email protected]>
@rhatdan
Copy link
Member Author

rhatdan commented Sep 9, 2020

I added more documentation to explain what these are to the podman build man page and tried to standardize on the term external containers in all of the effected man pages.

@mheon
Copy link
Member

mheon commented Sep 9, 2020

LGTM

@mheon
Copy link
Member

mheon commented Sep 9, 2020

Restarted two tests (hopefully flakes)

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 9, 2020
@vrothberg
Copy link
Member

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 9, 2020
@openshift-merge-robot openshift-merge-robot merged commit 49cb0ed into containers:master Sep 9, 2020
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants