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 generate systemd doesn't work as expected while using --new flag and container with log-opt tag set #9034

Closed
sixeela opened this issue Jan 20, 2021 · 8 comments · Fixed by #9035
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

@sixeela
Copy link

sixeela commented Jan 20, 2021

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

/kind bug

Description

While creating a container with --log-driver=journald and --log-opt=tag={{.Name}} specified, we're unable to generate a systemd file while forcing --new.
Facing an error: "Error: template: container_template:15:162: executing "container_template" at <.Name>: can't evaluate field Name in type *generate.containerInfo"

Steps to reproduce the issue:

  1. Create a random container (in this example, nginx): sudo podman run -d --log-driver=journald --log-opt=tag={{.Name}} --name=nginx nginx

  2. Try to generate systemd file sudo podman generate systemd --name nginx --new

Describe the results you received:

Error: template: container_template:15:162: executing "container_template" at <.Name>: can't evaluate field Name in type *generate.containerInfo

Describe the results you expected:

Systemd file generated with log-opt option set correctly.

Output of podman version:

Version:      2.2.1
API Version:  2.1.0
Go Version:   go1.15.5
Built:        Tue Dec  8 15:37:50 2020
OS/Arch:      linux/amd64

Output of podman info --debug:

host:
  arch: amd64
  buildahVersion: 1.18.0
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.0.21-3.fc33.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.21, commit: 0f53fb68333bdead5fe4dc5175703e22cf9882ab'
  cpus: 2
  distribution:
    distribution: fedora
    version: "33"
  eventLogger: journald
  hostname: fedora
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 5.10.7-200.fc33.x86_64
  linkmode: dynamic
  memFree: 157720576
  memTotal: 2040107008
  ociRuntime:
    name: crun
    package: crun-0.16-3.fc33.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 0.16
      commit: eb0145e5ad4d8207e84a327248af76663d4e50dd
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +YAJL
  os: linux
  remoteSocket:
    path: /run/podman/podman.sock
  rootless: false
  slirp4netns:
    executable: ""
    package: ""
    version: ""
  swapFree: 756019200
  swapTotal: 1019211776
  uptime: 3h 20m 2.33s (Approximately 0.12 days)
registries:
  search:
  - registry.fedoraproject.org
  - registry.access.redhat.com
  - registry.centos.org
  - docker.io
store:
  configFile: /etc/containers/storage.conf
  containerStore:
    number: 2
    paused: 0
    running: 1
    stopped: 1
  graphDriverName: overlay
  graphOptions:
    overlay.mountopt: nodev,metacopy=on
  graphRoot: /var/lib/containers/storage
  graphStatus:
    Backing Filesystem: btrfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "true"
  imageStore:
    number: 4
  runRoot: /var/run/containers/storage
  volumePath: /var/lib/containers/storage/volumes
version:
  APIVersion: 2.1.0
  Built: 1607438270
  BuiltTime: Tue Dec  8 15:37:50 2020
  GitCommit: ""
  GoVersion: go1.15.5
  OsArch: linux/amd64
  Version: 2.2.1

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

podman-2.2.1-1.fc33.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.):

Tried on a Fedora 33 virtual machine

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jan 20, 2021
@vrothberg vrothberg self-assigned this Jan 20, 2021
@vrothberg
Copy link
Member

Thanks for reaching out, @sixeIa! The tricky part is the {{.Name}} in the command line which is overlapping with the fields of the internal generator.

I will play with it a bit and check what we can do.

@Luap99
Copy link
Member

Luap99 commented Jan 20, 2021

The easiest thing might be changing the delimiter for the internal template https://golang.org/pkg/text/template/#Template.Delims

@vrothberg
Copy link
Member

EDIT: the problem is that we're also using Go templating to generate the container, so {{ .Name }} cannot work.

What you can do as a workaround_ is to remove --log-driver=journald from the command, generate the .service files and add --log-driver=journald to the file.

@sixeela
Copy link
Author

sixeela commented Jan 20, 2021

And it could not exist something to escape the {{ .Name }} ?

Yes that's what we're doing now.

@vrothberg
Copy link
Member

The easiest thing might be changing the delimiter for the internal template https://golang.org/pkg/text/template/#Template.Delims

@Luap99 got time to tackle it?

@Luap99
Copy link
Member

Luap99 commented Jan 20, 2021

@vrothberg Yes. I will tackle it.

@Luap99 Luap99 assigned Luap99 and unassigned vrothberg Jan 20, 2021
@vrothberg
Copy link
Member

Thanks, @Luap99 !

@Luap99
Copy link
Member

Luap99 commented Jan 20, 2021

PR #9035 to fix

Luap99 pushed a commit to Luap99/libpod that referenced this issue Jan 20, 2021
If the container create command contains an argument with double
curly braces the golang template parsing can fail since it tries
to interpret the value as variable. To fix this change the default
delimiter for the internal template to `{{{{`.

Fixes containers#9034

Signed-off-by: Paul Holzinger <[email protected]>
iwita pushed a commit to iwita/podman that referenced this issue Jan 26, 2021
If the container create command contains an argument with double
curly braces the golang template parsing can fail since it tries
to interpret the value as variable. To fix this change the default
delimiter for the internal template to `{{{{`.

Fixes containers#9034

Signed-off-by: Paul Holzinger <[email protected]>
mheon pushed a commit to mheon/libpod that referenced this issue Jan 29, 2021
If the container create command contains an argument with double
curly braces the golang template parsing can fail since it tries
to interpret the value as variable. To fix this change the default
delimiter for the internal template to `{{{{`.

Fixes containers#9034

Signed-off-by: Paul Holzinger <[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 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.

4 participants