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

podman inspect format doesn' t work for Container Port bindings #8444

Closed
aojea opened this issue Nov 22, 2020 · 12 comments · Fixed by #8642
Closed

podman inspect format doesn' t work for Container Port bindings #8444

aojea opened this issue Nov 22, 2020 · 12 comments · Fixed by #8642
Assignees
Labels
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.

Comments

@aojea
Copy link
Contributor

aojea commented Nov 22, 2020

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

/kind bug

Description

KIND uses

		"podman", "inspect",
		"--format",
		"{{ json .NetworkSettings.Ports }}",

to get the exposed ports of the containers, this fails with new version because it no longer reports a json

sudo podman inspect kind-control-plane -f "{{ json .NetworkSettings.Ports }}"
ERRO[0000] Error printing inspect output: template: all inspect:1: function "json" not defined 

It also says that the inspect command defaults to json

  -f, --format string   Format the output to a Go template or json (default "json")

but it is returning a go struct:

sudo podman inspect kind-control-plane -f "{{ .NetworkSettings.Ports }}"
map[6443/tcp:[{127.0.0.1 33405}]]

Describe the results you expected:

Is json not going to be the default moving forward or not going to be available as output of the inspect command?

Output of podman version:

Version:      2.2.0-rc1
API Version:  2.1.0
Go Version:   go1.15.2
Built:        Fri Nov 20 21:31:20 2020
OS/Arch:      linux/amd64

Output of podman info --debug:

host:
  arch: amd64
  buildahVersion: 1.18.0
  cgroupManager: cgroupfs
  cgroupVersion: v1
  conmon:
    package: conmon-2.0.21-2.fc32.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.21, commit: 81d18b6c3ffc266abdef7ca94c1450e669a6a388'
  cpus: 12
  distribution:
    distribution: fedora
    version: "32"
  eventLogger: journald
  hostname: aojea-laptop
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
    uidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
  kernel: 5.8.18-200.fc32.x86_64
  linkmode: dynamic
  memFree: 14766825472
  memTotal: 33391648768
  ociRuntime:
    name: runc
    package: runc-1.0.0-144.dev.gite6555cc.fc32.x86_64
    path: /usr/bin/runc
    version: |-
      runc version 1.0.0-rc10+dev
      commit: fbdbaf85ecbc0e077f336c03062710435607dbf1
      spec: 1.0.1-dev
  os: linux
  remoteSocket:
    path: /run/user/1000/podman/podman.sock
  rootless: true
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.1.4-1.fc32.x86_64
    version: |-
      slirp4netns version 1.1.4
      commit: b66ffa8e262507e37fca689822d23430f3357fe8
      libslirp: 4.3.1
      SLIRP_CONFIG_VERSION_MAX: 2
  swapFree: 16764628992
  swapTotal: 16764628992
  uptime: 15h 9m 43.77s (Approximately 0.62 days)
registries:
  search:
  - registry.fedoraproject.org
  - registry.access.redhat.com
  - registry.centos.org
  - docker.io
store:
  configFile: /home/aojea/.config/containers/storage.conf
  containerStore:
    number: 4
    paused: 0
    running: 0
    stopped: 4
  graphDriverName: overlay
  graphOptions:
    overlay.mount_program:
      Executable: /usr/bin/fuse-overlayfs
      Package: fuse-overlayfs-1.2.0-1.fc32.x86_64
      Version: |-
        fusermount3 version: 3.9.1
        fuse-overlayfs: version 1.1.0
        FUSE library version 3.9.1
        using FUSE kernel interface version 7.31
  graphRoot: /home/aojea/.local/share/containers/storage
  graphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "false"
  imageStore:
    number: 12
  runRoot: /run/user/1000/containers
  volumePath: /home/aojea/.local/share/containers/storage/volumes
version:
  APIVersion: 2.1.0
  Built: 1605904280
  BuiltTime: Fri Nov 20 21:31:20 2020
  GitCommit: ""
  GoVersion: go1.15.2
  OsArch: linux/amd64
  Version: 2.2.0-rc1

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

podman-2.2.0-0.4.rc1.el8.x86_64

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide?

Yes

Additional environment details (AWS, VirtualBox, physical, etc.):

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Nov 22, 2020
@aojea
Copy link
Contributor Author

aojea commented Nov 22, 2020

more interesting behaviours

$ sudo podman inspect -f "{{ .NetworkSettings.Ports }}" kind-control-plane 
map[6443/tcp:[{127.0.0.1 33405}]]

however,

$ sudo podman inspect -f "{{range .NetworkSettings.Ports }}" kind-control-plane 
ERRO[0000] Error printing inspect output: template: all inspect:2: unexpected EOF 

@zhangguanzhang
Copy link
Collaborator

zhangguanzhang commented Nov 22, 2020

/assign @jwhonce PTAL

@rhatdan
Copy link
Member

rhatdan commented Nov 23, 2020

The man page indicates to me that it returns go format structs OR JSON.
If you specify a --format, you will not necessarily get json, unless the field you specify is in json format.

@aojea
Copy link
Contributor Author

aojea commented Nov 23, 2020

The man page indicates to me that it returns go format structs OR JSON.
If you specify a --format, you will not necessarily get json, unless the field you specify is in json format.

with previous version, because you could specify JSON in 2.1.x

-f "{{ json .NetworkSettings.Ports }}"

and now it returns

function "json" not defined

@rhatdan
Copy link
Member

rhatdan commented Nov 24, 2020

@jwhonce PTAL

@aojea aojea changed the title podman inspect format doesn' t return json podman inspect format doesn' t work for Container Port bindings Dec 1, 2020
@aojea
Copy link
Contributor Author

aojea commented Dec 1, 2020

ok , so forget about the json thing, @jwhonce can you give me a way to obtain the port bindings, I can't iterate over the map and I don't know how to do it, I tried in all different formats without success

sudo bin/podman inspect kind-control-plane -f '{{range $key,$value := .NetworkSettings.Ports}} {{ .key }} {{end}}'
ERRO[0000] Error printing inspect output: template: all inspect:1:63: executing "all inspect" at <.key>: can't evaluate field key in type []define.InspectHostPort 

or

 sudo bin/podman inspect kind-control-plane -f '{{range  .NetworkSettings.Ports}} {{ .HostIP}}{{end}}'
ERRO[0000] Error printing inspect output: template: all inspect:1:49: executing "all inspect" at <.HostIP>: can't evaluate field HostIP in type []define.InspectHostPort 

however, I can get the map

 sudo bin/podman inspect kind-control-plane -f '{{.NetworkSettings.Ports}}'
map[6443/tcp:[{127.0.0.1 45271}]]

@aojea
Copy link
Contributor Author

aojea commented Dec 1, 2020

ok, so the problem is that is not returning a map when it tries to evaluate, it tries to evaluate a slice

[aojea@aojea-laptop kind]$ sudo podman inspect -f '{{range $key := .NetworkSettings.Ports }}{{ range .key}} {{ .HostPort }} {{end}} {{end}}' kind-control-plane
ERRO[0000] Error printing inspect output: template: all inspect:1:62: executing "all inspect" at <.key>: can't evaluate field key in type []define.InspectHostPort 
sudo podman inspect -f '{{range .NetworkSettings.Ports }}{{ range .}} {{ .HostPort }} {{end}} {{end}}' kind-control-plane
 33179

@aojea
Copy link
Contributor Author

aojea commented Dec 1, 2020

anyway, this is a big problem and blocker for docker users to migrate to podman, the inspect functions are heavily used for automation on CI and other systems, also, this is working totally different than in 2.1

@zhangguanzhang
Copy link
Collaborator

@jwhonce PTAL

jwhonce added a commit to jwhonce/podman that referenced this issue Dec 7, 2020
* Add template func to inspect template processing
* Added test using repro from containers#8444

Fixes containers#8444

Signed-off-by: Jhon Honce <[email protected]>
@BobyMCbobs
Copy link

I have this same issue on version 2.2.1.
Which release is this meant to be fixed in?

@rhatdan
Copy link
Member

rhatdan commented Jan 10, 2021

Is it working on the main branch?

@mheon
Copy link
Member

mheon commented Jan 10, 2021 via email

@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 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants