Skip to content

Commit

Permalink
quadlet: Support healthy for Notify directives
Browse files Browse the repository at this point in the history
This expands support for the (previously) boolean `Notify` directive, in
support of healthcheck determined SD-NOTIFY event emission, as
supported by Podman with the `--sdnotify=healthy` option.

Closes: #18189
Signed-off-by: Alex Palaistras <[email protected]>
  • Loading branch information
deuill committed Nov 21, 2023
1 parent 149d4f0 commit 6cb2f9b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ starts the child in the container. However, if the container application support
`Notify` to true passes the notification details to the container allowing it to notify
of startup on its own.

In addition, setting `Notify` to `healthy` will postpone startup notifications until such time as
the container is marked healthy, as determined by Podman healthchecks. Note that this requires
setting up a container healthcheck, see the `HealthCmd` option for more.

### `PidsLimit=`

Tune the container's pids limit.
Expand Down
9 changes: 6 additions & 3 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,13 @@ func ConvertContainer(container *parser.UnitFile, names map[string]string, isUse
if serviceType != "oneshot" {
// If we're not in oneshot mode always use some form of sd-notify, normally via conmon,
// but we also allow passing it to the container by setting Notify=yes
notify := container.LookupBooleanWithDefault(ContainerGroup, KeyNotify, false)
if notify {
notify, ok := container.Lookup(ContainerGroup, KeyNotify)
switch {
case ok && strings.EqualFold(notify, "healthy"):
podman.add("--sdnotify=healthy")
case container.LookupBooleanWithDefault(ContainerGroup, KeyNotify, false):
podman.add("--sdnotify=container")
} else {
default:
podman.add("--sdnotify=conmon")
}
service.Setv(ServiceGroup,
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/quadlet/notify-healthy.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## assert-podman-args "--sdnotify=healthy"

[Container]
Image=localhost/imagename
Notify=healthy
1 change: 1 addition & 0 deletions test/e2e/quadlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ BOGUS=foo
Entry("network.quadlet.container", "network.quadlet.container", 0, ""),
Entry("noimage.container", "noimage.container", 1, "converting \"noimage.container\": no Image or Rootfs key specified"),
Entry("notify.container", "notify.container", 0, ""),
Entry("notify-healthy.container", "notify-healthy.container", 0, ""),
Entry("oneshot.container", "oneshot.container", 0, ""),
Entry("other-sections.container", "other-sections.container", 0, ""),
Entry("podmanargs.container", "podmanargs.container", 0, ""),
Expand Down

0 comments on commit 6cb2f9b

Please sign in to comment.