Skip to content

Commit

Permalink
Fix broken podman generate systemd --new with pods
Browse files Browse the repository at this point in the history
The unit generation accidentally escaped the %t in the pod id file path.
This is a regression caused by containers#9178. This was not caught by the tests
because the test itself was wrong. It used a full path instead of the
systemd variable %t like the actual code does.

Fixes containers#9373

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Paul Holzinger authored and mheon committed Feb 18, 2021
1 parent 538ced1 commit d78030d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/systemd/generate/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type containerInfo struct {

// If not nil, the container is part of the pod. We can use the
// podInfo to extract the relevant data.
pod *podInfo
Pod *podInfo
}

const containerTemplate = headerTemplate + `
Expand Down Expand Up @@ -215,8 +215,8 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst
)
// If the container is in a pod, make sure that the
// --pod-id-file is set correctly.
if info.pod != nil {
podFlags := []string{"--pod-id-file", info.pod.PodIDFile}
if info.Pod != nil {
podFlags := []string{"--pod-id-file", "{{{{.Pod.PodIDFile}}}}"}
startCommand = append(startCommand, podFlags...)
info.CreateCommand = filterPodFlags(info.CreateCommand)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/systemd/generate/containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=always
TimeoutStopSec=70
ExecStartPre=/bin/rm -f %t/jadda-jadda.pid %t/jadda-jadda.ctr-id
ExecStart=/usr/bin/podman run --conmon-pidfile %t/jadda-jadda.pid --cidfile %t/jadda-jadda.ctr-id --cgroups=no-conmon --pod-id-file /tmp/pod-foobar.pod-id-file --replace -d --name jadda-jadda --hostname hello-world awesome-image:latest command arg1 ... argN
ExecStart=/usr/bin/podman run --conmon-pidfile %t/jadda-jadda.pid --cidfile %t/jadda-jadda.ctr-id --cgroups=no-conmon --pod-id-file %t/pod-foobar.pod-id-file --replace -d --name jadda-jadda --hostname hello-world awesome-image:latest command arg1 ... argN
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/jadda-jadda.ctr-id -t 10
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/jadda-jadda.ctr-id
PIDFile=%t/jadda-jadda.pid
Expand Down Expand Up @@ -487,8 +487,8 @@ WantedBy=multi-user.target default.target
PodmanVersion: "CI",
CreateCommand: []string{"I'll get stripped", "run", "-d", "--name", "jadda-jadda", "--hostname", "hello-world", "awesome-image:latest", "command", "arg1", "...", "argN"},
EnvVariable: EnvVariable,
pod: &podInfo{
PodIDFile: "/tmp/pod-foobar.pod-id-file",
Pod: &podInfo{
PodIDFile: "%t/pod-foobar.pod-id-file",
},
},
goodNameNewWithPodFile,
Expand Down
2 changes: 1 addition & 1 deletion pkg/systemd/generate/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func PodUnits(pod *libpod.Pod, options entities.GenerateSystemdOptions) (map[str
}
units[podInfo.ServiceName] = out
for _, info := range containerInfos {
info.pod = podInfo
info.Pod = podInfo
out, err := executeContainerTemplate(info, options)
if err != nil {
return nil, err
Expand Down

0 comments on commit d78030d

Please sign in to comment.