Skip to content

Commit

Permalink
Merge pull request #24334 from rhatdan/quadlet
Browse files Browse the repository at this point in the history
Honor users requests in quadlet files
  • Loading branch information
openshift-merge-bot[bot] authored Nov 5, 2024
2 parents df41725 + c6be5a6 commit c8af2f2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 27 deletions.
45 changes: 19 additions & 26 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,21 @@ func ConvertContainer(container *parser.UnitFile, isUser bool, unitsInfoMap map[
return service, nil
}

func defaultOneshotServiceGroup(service *parser.UnitFile, remainAfterExit bool) {
// 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 remainAfterExit {
if _, ok := service.Lookup(ServiceGroup, "RemainAfterExit"); !ok {
service.Set(ServiceGroup, "RemainAfterExit", "yes")
}
}
}

// Convert a quadlet network file (unit file with a Network group) to a systemd
// service file (unit file with Service group) based on the options in the
// Network group.
Expand Down Expand Up @@ -976,12 +991,7 @@ 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")
defaultOneshotServiceGroup(service, true)

// Store the name of the created resource
unitInfo.ResourceName = networkName
Expand Down Expand Up @@ -1124,12 +1134,7 @@ 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")
defaultOneshotServiceGroup(service, true)

// Store the name of the created resource
unitInfo.ResourceName = volumeName
Expand Down Expand Up @@ -1342,12 +1347,7 @@ 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")
defaultOneshotServiceGroup(service, true)

if name, ok := image.Lookup(ImageGroup, KeyImageTag); ok && len(name) > 0 {
imageName = name
Expand Down Expand Up @@ -1475,14 +1475,7 @@ 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")

defaultOneshotServiceGroup(service, false)
return service, nil
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/quadlet/basic.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## assert-key-is "Unit" "RequiresMountsFor" "%t/containers"
## assert-key-is-regex "Service" "WorkingDirectory" "/.*/podman-e2e-.*/subtest-.*/quadlet"
## assert-key-is "Service" "Type" "oneshot"
## assert-key-is "Service" "RemainAfterExit" "yes"
## !assert-key-is "Service" "RemainAfterExit" "yes"
## assert-key-is "Service" "SyslogIdentifier" "%N"

[Build]
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/quadlet/ipv6.network
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## assert-podman-final-args systemd-ipv6
## assert-podman-args "--ipv6"
## assert-key-is Service Type exec
## assert-key-is Service RemainAfterExit no
## assert-key-contains Service SyslogIdentifier "Modify %N"

[Network]
IPv6=yes

[Service]
Type=exec
RemainAfterExit=no
SyslogIdentifier="Modify %N"
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
7 changes: 7 additions & 0 deletions test/e2e/quadlet/uid.volume
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
## assert-key-contains Service ExecStart " --opt o=uid=0,gid=11 "
## assert-key-is Service Type oneshot
## assert-key-is Service RemainAfterExit no
## assert-key-contains Service SyslogIdentifier "Modify %N"

[Volume]
# Test usernames too
User=root
Group=11

[Service]
RemainAfterExit=no
SyslogIdentifier="Modify %N"
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

1 comment on commit c8af2f2

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.