From 6611735aeb30ad7617ca527804f6137309793297 Mon Sep 17 00:00:00 2001 From: Ygal Blum Date: Sun, 4 Jun 2023 09:05:36 +0300 Subject: [PATCH] Quadlet - add support for Pull key in .container Update code, doc and test Remove doc comment on pull policy Signed-off-by: Ygal Blum --- docs/source/markdown/podman-systemd.unit.5.md | 9 +++++++-- pkg/systemd/quadlet/quadlet.go | 7 +++++++ test/e2e/quadlet/pull.container | 6 ++++++ test/e2e/quadlet_test.go | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/e2e/quadlet/pull.container diff --git a/docs/source/markdown/podman-systemd.unit.5.md b/docs/source/markdown/podman-systemd.unit.5.md index 7c0677a063..e1856762d2 100644 --- a/docs/source/markdown/podman-systemd.unit.5.md +++ b/docs/source/markdown/podman-systemd.unit.5.md @@ -121,6 +121,7 @@ Valid options for `[Container]` are listed below: | Notify=true | --sdnotify container | | PodmanArgs=--add-host foobar | --add-host foobar | | PublishPort=true | --publish | +| Pull=never | --pull=never | | ReadOnly=true | --read-only | | RunInit=true | --init | | SeccompProfile=/tmp/s.json | --security-opt seccomp=/tmp/s.json | @@ -283,8 +284,7 @@ Equivalent to the Podman `--hostname` option. ### `Image=` -The image to run in the container. This image must be locally installed for the service to work -when it is activated, because the generated service file never tries to download images. +The image to run in the container. It is recommended to use a fully qualified image name rather than a short name, both for performance and robustness reasons. @@ -391,6 +391,11 @@ allocated port can be found with the `podman port` command. This key can be listed multiple times. +### `Pull=` + +Set the image pull policy. +This is equivalent to the Podman `--pull` option + ### `ReadOnly=` (defaults to `no`) If enabled, makes image read-only, with /var/tmp, /tmp and /run a tmpfs (unless disabled by `VolatileTmp=no`).r diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index 27f337aaeb..25719d2289 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -81,6 +81,7 @@ const ( KeyOptions = "Options" KeyPodmanArgs = "PodmanArgs" KeyPublishPort = "PublishPort" + KeyPull = "Pull" KeyReadOnly = "ReadOnly" KeyRemapGID = "RemapGid" KeyRemapUID = "RemapUid" @@ -143,6 +144,7 @@ var ( KeyNotify: true, KeyPodmanArgs: true, KeyPublishPort: true, + KeyPull: true, KeyReadOnly: true, KeyRemapGID: true, KeyRemapUID: true, @@ -625,6 +627,11 @@ func ConvertContainer(container *parser.UnitFile, isUser bool) (*parser.UnitFile podman.add("--hostname", hostname) } + pull, ok := container.Lookup(ContainerGroup, KeyPull) + if ok && len(pull) > 0 { + podman.add("--pull", pull) + } + handlePodmanArgs(container, ContainerGroup, podman) if len(image) > 0 { diff --git a/test/e2e/quadlet/pull.container b/test/e2e/quadlet/pull.container new file mode 100644 index 0000000000..2b84887962 --- /dev/null +++ b/test/e2e/quadlet/pull.container @@ -0,0 +1,6 @@ +## assert-podman-final-args localhost/imagename +## assert-podman-args --pull never + +[Container] +Image=localhost/imagename +Pull=never diff --git a/test/e2e/quadlet_test.go b/test/e2e/quadlet_test.go index 4eb059e6a5..224d25bdb7 100644 --- a/test/e2e/quadlet_test.go +++ b/test/e2e/quadlet_test.go @@ -578,6 +578,7 @@ var _ = Describe("quadlet system generator", func() { Entry("mount.container", "mount.container"), Entry("health.container", "health.container"), Entry("hostname.container", "hostname.container"), + Entry("pull.container", "pull.container"), Entry("basic.volume", "basic.volume"), Entry("label.volume", "label.volume"),