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

Container completions broken when inspecting without specifying container in the command #18672

Closed
leo8a opened this issue May 24, 2023 · 5 comments · Fixed by #19261
Closed
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. stale-issue

Comments

@leo8a
Copy link
Contributor

leo8a commented May 24, 2023

Issue Description

When the podman inspect <container_name> command is used with the --format flag, the autocompletion doesn't show possible options for Go templates (see example below).

-> podman inspect <container_name> -f {{.   #TAB TAB

However, when container is included in the command, the autocompletion works properly.

-> podman container inspect <container_name> -f {{.     #TAB TAB
{{.AppArmorProfile}}  {{.ConmonPidFile}}    {{.EffectiveCaps}}    {{.HostnamePath}}     {{.ImageDigest}}      {{.MountLabel}}       {{.NetworkSettings.   {{.PidFile}}          {{.RestartCount}}     {{.State.
{{.Args}}             {{.Created.           {{.ExecIDs}}          {{.HostsPath}}        {{.ImageName}}        {{.Mounts}}           {{.OCIConfigPath}}    {{.Pod}}              {{.Rootfs}}           {{.StaticDir}}
{{.BoundingCaps}}     {{.Dependencies}}     {{.GraphDriver.       {{.ID}}               {{.IsInfra}}          {{.Name}}             {{.OCIRuntime}}       {{.ProcessLabel}}     {{.SizeRootFs}}       
{{.Config.            {{.Driver}}           {{.HostConfig.        {{.Image}}            {{.IsService}}        {{.Namespace}}        {{.Path}}             {{.ResolvConfPath}}   {{.SizeRw}}  

Maybe this is the intended behavior. However, I believe that in the first (broken) example, the autocompletion could be triggered since the name of the container is already passed to the command, and hence the autocompletion for containers could be identified at that moment.

Other useful information:

-> podman version
Client:       Podman Engine
Version:      4.5.0
API Version:  4.5.0
Go Version:   go1.19.7
Built:        Fri Apr 14 17:42:56 2023
OS/Arch:      linux/amd64

-> rpm -q podman
podman-4.5.0-1.fc37.x86_64

Steps to reproduce the issue

Steps to reproduce the issue

  1. podman inspect <container_name> -f {{. #TAB TAB

Describe the results you received

Empty results

Describe the results you expected

{{.AppArmorProfile}} {{.ConmonPidFile}} {{.EffectiveCaps}} {{.HostnamePath}} {{.ImageDigest}} {{.MountLabel}} {{.NetworkSettings. {{.PidFile}} {{.RestartCount}} {{.State.
{{.Args}} {{.Created. {{.ExecIDs}} {{.HostsPath}} {{.ImageName}} {{.Mounts}} {{.OCIConfigPath}} {{.Pod}} {{.Rootfs}} {{.StaticDir}}
{{.BoundingCaps}} {{.Dependencies}} {{.GraphDriver. {{.ID}} {{.IsInfra}} {{.Name}} {{.OCIRuntime}} {{.ProcessLabel}} {{.SizeRootFs}}
{{.Config. {{.Driver}} {{.HostConfig. {{.Image}} {{.IsService}} {{.Namespace}} {{.Path}} {{.ResolvConfPath}} {{.SizeRw}}

podman info output

host:
  arch: amd64
  buildahVersion: 1.30.0
  cgroupControllers:
  - cpu
  - io
  - memory
  - pids
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.1.7-2.fc37.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.7, commit: '
  cpuUtilization:
    idlePercent: 77.28
    systemPercent: 4.77
    userPercent: 17.95
  cpus: 8
  databaseBackend: boltdb
  distribution:
    distribution: fedora
    variant: workstation
    version: "37"
  eventLogger: journald
  hostname: red-fedora
  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: 6.2.15-200.fc37.x86_64
  linkmode: dynamic
  logDriver: journald
  memFree: 627425280
  memTotal: 16499519488
  networkBackend: cni
  ociRuntime:
    name: crun
    package: crun-1.8.4-1.fc37.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 1.8.4
      commit: 5a8fa99a5e41facba2eda4af12fa26313918805b
      rundir: /run/user/1000/crun
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +LIBKRUN +WASM:wasmedge +YAJL
  os: linux
  remoteSocket:
    path: /run/user/1000/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: false
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.2.0-8.fc37.x86_64
    version: |-
      slirp4netns version 1.2.0
      commit: 656041d45cfca7a4176f6b7eed9e4fe6c11e8383
      libslirp: 4.7.0
      SLIRP_CONFIG_VERSION_MAX: 4
      libseccomp: 2.5.3
  swapFree: 3389247488
  swapTotal: 8589930496
  uptime: 191h 58m 10.00s (Approximately 7.96 days)
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  - ipvlan
  volume:
  - local
registries:
  search:
  - registry.fedoraproject.org
  - registry.access.redhat.com
  - docker.io
  - quay.io
store:
  configFile: /home/leo8a/.config/containers/storage.conf
  containerStore:
    number: 1
    paused: 0
    running: 1
    stopped: 0
  graphDriverName: overlay
  graphOptions: {}
  graphRoot: /home/leo8a/.local/share/containers/storage
  graphRootAllocated: 254339448832
  graphRootUsed: 149914431488
  graphStatus:
    Backing Filesystem: btrfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Using metacopy: "false"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 6
  runRoot: /run/user/1000/containers
  transientStore: false
  volumePath: /home/leo8a/.local/share/containers/storage/volumes
version:
  APIVersion: 4.5.0
  Built: 1681486976
  BuiltTime: Fri Apr 14 17:42:56 2023
  GitCommit: ""
  GoVersion: go1.19.7
  Os: linux
  OsArch: linux/amd64
  Version: 4.5.0

Podman in a container

No

Privileged Or Rootless

Rootless

Upstream Latest Release

Yes

Additional environment details

No response

Additional information

No response

@leo8a leo8a added the kind/bug Categorizes issue or PR as related to a bug. label May 24, 2023
@Luap99
Copy link
Member

Luap99 commented May 24, 2023

This is by design as we do not really know what to complete, container, image, pod, network, etc...
but I think you make a good point when a user types podman inspect <name> -f {{. we can lookup the name and get the correct type so we know what struct to auto complete.
Also I guess we could just assume it is a container when no name was given.

Are you interested in contributing a PR to fix it? I can point you at the right location.

@Luap99 Luap99 added the Good First Issue This issue would be a good issue for a first time contributor to undertake. label May 24, 2023
@leo8a
Copy link
Contributor Author

leo8a commented May 24, 2023

Sure, pls provide the pointers and I can pick it up during my free cycles (and reach out if needed), thanks.

@Luap99
Copy link
Member

Luap99 commented May 24, 2023

This is the place were you add a completion function for this option:
https://github.com/containers/podman/blob/main/cmd/podman/inspect/inspect.go#L31
here is how it is done for container inspect:

_ = inspectCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&define.InspectContainerData{}))

This were the autocomplete function for the --format options is defined:
https://github.com/containers/podman/blob/main/cmd/podman/common/completion.go#L1167

the args[] argument can then be used to get the <container> part.

@cgiradkar
Copy link
Collaborator

/assign

@github-actions
Copy link

github-actions bot commented Jul 9, 2023

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

@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 Oct 18, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 18, 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. stale-issue
Projects
None yet
3 participants