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

ps command to list container with volume filter does not work #16019

Closed
robinshine opened this issue Oct 1, 2022 · 15 comments · Fixed by #16934
Closed

ps command to list container with volume filter does not work #16019

robinshine opened this issue Oct 1, 2022 · 15 comments · Fixed by #16934
Assignees
Labels
Good First Issue This issue would be a good issue for a first time contributor to undertake. kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. remote Problem is in podman-remote

Comments

@robinshine
Copy link

robinshine commented Oct 1, 2022

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

Use "ps" command to list container with volume filter does not work

Steps to reproduce the issue:

  1. Run a container with a mounted volume, for instance:
podman run -it -v $(pwd)/data:/data ubuntu bash
  1. Run command to list all containers with mounting point "/data"
podman podman ps -f volume=/data

Describe the results you received:
No container returned

Describe the results you expected:
It should return all containers mounting volume to "/data" as docker works

Additional information you deem important (e.g. issue happens only occasionally):

Output of podman version:

4.2.1

Output of podman info:

host:
  arch: amd64
  buildahVersion: 1.27.0
  cgroupControllers:
  - cpu
  - io
  - memory
  - pids
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.1.4-2.fc36.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.4, commit: '
  cpuUtilization:
    idlePercent: 98.4
    systemPercent: 1.01
    userPercent: 0.58
  cpus: 1
  distribution:
    distribution: fedora
    variant: coreos
    version: "36"
  eventLogger: journald
  hostname: localhost.localdomain
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 1000000
    uidmap:
    - container_id: 0
      host_id: 501
      size: 1
    - container_id: 1
      host_id: 100000
      size: 1000000
  kernel: 5.19.9-200.fc36.x86_64
  linkmode: dynamic
  logDriver: journald
  memFree: 1649397760
  memTotal: 2066890752
  networkBackend: netavark
  ociRuntime:
    name: crun
    package: crun-1.6-2.fc36.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 1.6
      commit: 18cf2efbb8feb2b2f20e316520e0fd0b6c41ef4d
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +YAJL
  os: linux
  remoteSocket:
    exists: true
    path: /run/user/501/podman/podman.sock
  security:
    apparmorEnabled: false
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: true
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: true
  serviceIsRemote: true
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.2.0-0.2.beta.0.fc36.x86_64
    version: |-
      slirp4netns version 1.2.0-beta.0
      commit: 477db14a24ff1a3de3a705e51ca2c4c1fe3dda64
      libslirp: 4.6.1
      SLIRP_CONFIG_VERSION_MAX: 3
      libseccomp: 2.5.3
  swapFree: 0
  swapTotal: 0
  uptime: 0h 9m 1.00s
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  volume:
  - local
registries:
  search:
  - docker.io
store:
  configFile: /var/home/core/.config/containers/storage.conf
  containerStore:
    number: 0
    paused: 0
    running: 0
    stopped: 0
  graphDriverName: overlay
  graphOptions: {}
  graphRoot: /var/home/core/.local/share/containers/storage
  graphRootAllocated: 106825756672
  graphRootUsed: 2302984192
  graphStatus:
    Backing Filesystem: xfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Using metacopy: "false"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 2
  runRoot: /run/user/501/containers
  volumePath: /var/home/core/.local/share/containers/storage/volumes
version:
  APIVersion: 4.2.0
  Built: 1660228937
  BuiltTime: Thu Aug 11 22:42:17 2022
  GitCommit: ""
  GoVersion: go1.18.4
  Os: linux
  OsArch: linux/amd64
  Version: 4.2.0

Package info (e.g. output of rpm -q podman or apt list podman or brew info podman):

podman version 4.2.1

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/main/troubleshooting.md)

Yes

@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label Oct 1, 2022
@github-actions github-actions bot added the remote Problem is in podman-remote label Oct 1, 2022
@rhatdan rhatdan added the Good First Issue This issue would be a good issue for a first time contributor to undertake. label Oct 1, 2022
@Luap99
Copy link
Member

Luap99 commented Oct 1, 2022

The volume filter only searches for volume names AFAIK and not paths.

@rlanting
Copy link

rlanting commented Oct 6, 2022

When I do this:

podman run -it --rm -v /tmp/data:/data ubuntu bash

then for

podman ps -f volume=/data

I get no output. But for

podman ps -f volume=/tmp/data

I do get the right output.

That makes me feel that podman uses the wrong path to match against with the volume filter.

Also

//- volume=(<volume-name>|<mount-point-destination>)
says it searches volume name and mount point destination.

@rlanting
Copy link

rlanting commented Oct 6, 2022

if dest != "" && (mount.Source == source && mount.Destination == dest) {
return true
}
if dest == "" && mount.Source == source {
return true
}

That does not seem right. It matches when source and dest both match, or when source matches.

@rhatdan
Copy link
Member

rhatdan commented Oct 6, 2022

It matches when source matches and dest is not specified or is ""

@rhatdan
Copy link
Member

rhatdan commented Oct 6, 2022

I have not examined the problem just looking at the code above.

@jesselang
Copy link
Contributor

From what I've gathered, it seems like the behavior expected would be to match on the volume name or the mount point in the container (destination) rather than the mount point on the host (source). I'd be happy to take a swing at a PR for this.

@Luap99
Copy link
Member

Luap99 commented Oct 19, 2022

@jesselang Thanks, I assigned it to you. Feel free to ping me if you have any questions.

@github-actions
Copy link

A friendly reminder that this issue had no activity for 30 days.

@rhatdan
Copy link
Member

rhatdan commented Nov 21, 2022

@jesselang any progress?

@jesselang
Copy link
Contributor

I think I have a good handle on what needs to change, but have not had a chance to make the changes yet. I think I'll have some time to put towards this in the next few weeks.

@SamirPS
Copy link
Contributor

SamirPS commented Dec 18, 2022

Hello @jesselang can i try this issue ?

@jesselang
Copy link
Contributor

Sure, go for it @SamirPS . 🙂👍

@SamirPS
Copy link
Contributor

SamirPS commented Dec 18, 2022

@jesselang if i understand well the code need to be like this

for _, mount := range containerConfig.Spec.Mounts {
					if dest != "" && (mount.Source == source && mount.Destination == dest) {
						return true
					}
					if dest == "" && mount.Destination == source {
						return true
					}
				}
for _, vname := range containerConfig.NamedVolumes {
					if dest != "" && (vname.Name == source && vname.Dest == dest) {
						return true
					}
					if dest == "" && vname.Name == source {
						return true
					}
				}
			}

?

@rhatdan
Copy link
Member

rhatdan commented Dec 19, 2022

@Luap99 Could you help out on this?

@SamirPS
Copy link
Contributor

SamirPS commented Dec 19, 2022

If I redo the ticket step with this code, I have the machine listed with the volume data. Do I need to add a test or not?

SamirPS added a commit to SamirPS/podman that referenced this issue Jan 3, 2023
Modify the condition in line 149 in order to list container by mounting
point.
Closes containers#16019

Signed-off-by: SamirPS <[email protected]>
@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 5, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Good First Issue This issue would be a good issue for a first time contributor to undertake. kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. remote Problem is in podman-remote
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants