Skip to content

Commit

Permalink
Honor users requests in quadlet files
Browse files Browse the repository at this point in the history
Fixes: containers#24322

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Oct 22, 2024
1 parent 4319fac commit 63ed321
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 26 deletions.
63 changes: 37 additions & 26 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,12 +976,16 @@ func ConvertNetwork(network *parser.UnitFile, name string, unitsInfoMap map[stri

service.AddCmdline(ServiceGroup, "ExecStart", podman.Args)

service.Setv(ServiceGroup,
"Type", "oneshot",
"RemainAfterExit", "yes",

// The default syslog identifier is the exec basename (podman) which isn't very useful here
"SyslogIdentifier", "%N")
// The default syslog identifier is the exec basename (podman) which isn't very useful here
if _, ok := service.Lookup(ServiceGroup, "SyslogIdentifier"); !ok {
service.Set(ServiceGroup, "SyslogIdentifier", "%N")
}
if _, ok := service.Lookup(ServiceGroup, "Type"); !ok {
service.Set(ServiceGroup, "Type", "oneshot")
}
if _, ok := service.Lookup(ServiceGroup, "RemainAfterExit"); !ok {
service.Set(ServiceGroup, "RemainAfterExit", "yes")
}

// Store the name of the created resource
unitInfo.ResourceName = networkName
Expand Down Expand Up @@ -1124,12 +1128,16 @@ func ConvertVolume(volume *parser.UnitFile, name string, unitsInfoMap map[string

service.AddCmdline(ServiceGroup, "ExecStart", podman.Args)

service.Setv(ServiceGroup,
"Type", "oneshot",
"RemainAfterExit", "yes",

// The default syslog identifier is the exec basename (podman) which isn't very useful here
"SyslogIdentifier", "%N")
// The default syslog identifier is the exec basename (podman) which isn't very useful here
if _, ok := service.Lookup(ServiceGroup, "SyslogIdentifier"); !ok {
service.Set(ServiceGroup, "SyslogIdentifier", "%N")
}
if _, ok := service.Lookup(ServiceGroup, "Type"); !ok {
service.Set(ServiceGroup, "Type", "oneshot")
}
if _, ok := service.Lookup(ServiceGroup, "RemainAfterExit"); !ok {
service.Set(ServiceGroup, "RemainAfterExit", "yes")
}

// Store the name of the created resource
unitInfo.ResourceName = volumeName
Expand Down Expand Up @@ -1342,12 +1350,16 @@ func ConvertImage(image *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, isU

service.AddCmdline(ServiceGroup, "ExecStart", podman.Args)

service.Setv(ServiceGroup,
"Type", "oneshot",
"RemainAfterExit", "yes",

// The default syslog identifier is the exec basename (podman) which isn't very useful here
"SyslogIdentifier", "%N")
// The default syslog identifier is the exec basename (podman) which isn't very useful here
if _, ok := service.Lookup(ServiceGroup, "SyslogIdentifier"); !ok {
service.Set(ServiceGroup, "SyslogIdentifier", "%N")
}
if _, ok := service.Lookup(ServiceGroup, "Type"); !ok {
service.Set(ServiceGroup, "Type", "oneshot")
}
if _, ok := service.Lookup(ServiceGroup, "RemainAfterExit"); !ok {
service.Set(ServiceGroup, "RemainAfterExit", "yes")
}

if name, ok := image.Lookup(ImageGroup, KeyImageTag); ok && len(name) > 0 {
imageName = name
Expand Down Expand Up @@ -1475,14 +1487,13 @@ func ConvertBuild(build *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, isU

service.AddCmdline(ServiceGroup, "ExecStart", podman.Args)

service.Setv(ServiceGroup,
"Type", "oneshot",
"RemainAfterExit", "yes",

// The default syslog identifier is the exec basename (podman)
// which isn't very useful here
"SyslogIdentifier", "%N")

// The default syslog identifier is the exec basename (podman) which isn't very useful here
if _, ok := service.Lookup(ServiceGroup, "SyslogIdentifier"); !ok {
service.Set(ServiceGroup, "SyslogIdentifier", "%N")
}
if _, ok := service.Lookup(ServiceGroup, "Type"); !ok {
service.Set(ServiceGroup, "Type", "oneshot")
}
return service, nil
}

Expand Down
2 changes: 2 additions & 0 deletions test/e2e/quadlet/build.multiple-tags.container
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## assert-podman-final-args localhost/imagename:v1
## assert-key-is "Service" "RemainAfterExit" ""

[Container]
Image=multiple-tags.build

5 changes: 5 additions & 0 deletions test/e2e/quadlet/network.build
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
## assert-podman-final-args-regex /.*/podman-e2e-.*/subtest-.*/quadlet
## assert-podman-args "--tag" "localhost/imagename"
## assert-podman-args "--network" "host"
## assert-key-is "Service" "Type" "oneshot"
## assert-key-is "Service" "RemainAfterExit" "no"

[Build]
ImageTag=localhost/imagename
SetWorkingDirectory=unit
Network=host

[Service]
RemainAfterExit=no
2 changes: 2 additions & 0 deletions test/e2e/quadlet/network.kube
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## assert-podman-args --network basic
## assert-key-is "Service" "Type" "oneshot"
## assert-key-is "Service" "RemainAfterExit" "yes"

[Kube]
Yaml=deployment.yml
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/quadlet/volume.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## assert-podman-args -v named:/container/named
## assert-podman-args -v systemd-basic:/container/quadlet
## assert-podman-args -v %h/container:/container/volume4
## assert-key-is "Service" "Type" "notify"

[Build]
ImageTag=localhost/imagename
Expand All @@ -15,3 +16,6 @@ Volume=/container/empty
Volume=named:/container/named
Volume=basic.volume:/container/quadlet
Volume=%h/container:/container/volume4

[Service]
Type=notify
4 changes: 4 additions & 0 deletions test/e2e/quadlet/volume.pod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
## assert-podman-pre-args -v named:/container/named
## assert-podman-pre-args -v systemd-basic:/container/quadlet
## assert-podman-pre-args -v %h/container:/container/volume4
## assert-key-is "Service" "Type" "oneshot"
## assert-key-is "Service" "RemainAfterExit" "yes"

[Pod]
Volume=/host/dir:/container/volume
Expand All @@ -13,3 +15,5 @@ Volume=/container/empty
Volume=named:/container/named
Volume=basic.volume:/container/quadlet
Volume=%h/container:/container/volume4


0 comments on commit 63ed321

Please sign in to comment.