Merge pull request #20337 from ygalblum/quadlet-kube-oneshot

Quadlet - support oneshot .kube files
This commit is contained in:
openshift-ci[bot]
2023-10-12 16:27:13 +00:00
committed by GitHub
4 changed files with 44 additions and 3 deletions

View File

@ -59,6 +59,19 @@ Adding the following snippet to a Quadlet file extends the systemd timeout to 15
TimeoutStartSec=900 TimeoutStartSec=900
``` ```
### Service Type
By default, the `Type` field of the `Service` section of the Quadlet file does not need to be set.
Quadlet will set it to `notify` for `.container` and `.kube` files and to `oneshot` for `.volume`, `.network` and `.image` files.
However, `Type` may be explicitly set to `oneshot` for `.container` and `.kube` files when no containers are expected
to run once `podman` exits.
Examples for such cases:
- `.container` file with an image that exits after their entrypoint has finished
``
- `.kube` file pointing to a Kubernetes Yaml file that does not define any containers. E.g. PVCs only
### Enabling unit files ### Enabling unit files
The services created by Podman are considered transient by systemd, which means they don't have the same The services created by Podman are considered transient by systemd, which means they don't have the same

View File

@ -1063,9 +1063,17 @@ func ConvertKube(kube *parser.UnitFile, names map[string]string, isUser bool) (*
// Need the containers filesystem mounted to start podman // Need the containers filesystem mounted to start podman
service.Add(UnitGroup, "RequiresMountsFor", "%t/containers") service.Add(UnitGroup, "RequiresMountsFor", "%t/containers")
service.Setv(ServiceGroup, // Allow users to set the Service Type to oneshot to allow resources only kube yaml
"Type", "notify", serviceType, ok := service.Lookup(ServiceGroup, "Type")
"NotifyAccess", "all") if ok && serviceType != "notify" && serviceType != "oneshot" {
return nil, fmt.Errorf("invalid service Type '%s'", serviceType)
}
if serviceType != "oneshot" {
service.Setv(ServiceGroup,
"Type", "notify",
"NotifyAccess", "all")
}
if !kube.HasKey(ServiceGroup, "SyslogIdentifier") { if !kube.HasKey(ServiceGroup, "SyslogIdentifier") {
service.Set(ServiceGroup, "SyslogIdentifier", "%N") service.Set(ServiceGroup, "SyslogIdentifier", "%N")

View File

@ -0,0 +1,19 @@
## assert-podman-args "kube"
## assert-podman-args "play"
## assert-podman-final-args-regex .*/podman_test.*/quadlet/deployment.yml
## assert-podman-args "--replace"
## assert-podman-args "--service-container=true"
## assert-podman-stop-post-args "kube"
## assert-podman-stop-post-args "down"
## assert-podman-stop-post-final-args-regex .*/podman_test.*/quadlet/deployment.yml
## assert-key-is "Unit" "RequiresMountsFor" "%t/containers"
## assert-key-is "Service" "KillMode" "mixed"
## assert-key-is "Service" "Type" "oneshot"
## assert-key-is "Service" "Environment" "PODMAN_SYSTEMD_UNIT=%n"
## assert-key-is "Service" "SyslogIdentifier" "%N"
[Kube]
Yaml=deployment.yml
[Service]
Type=oneshot

View File

@ -764,6 +764,7 @@ BOGUS=foo
Entry("Kube - Working Directory already in Service", "workingdir-service.kube", 0, ""), Entry("Kube - Working Directory already in Service", "workingdir-service.kube", 0, ""),
Entry("Kube - global args", "globalargs.kube", 0, ""), Entry("Kube - global args", "globalargs.kube", 0, ""),
Entry("Kube - Containers Conf Modules", "containersconfmodule.kube", 0, ""), Entry("Kube - Containers Conf Modules", "containersconfmodule.kube", 0, ""),
Entry("Kube - Service Type=oneshot", "oneshot.kube", 0, ""),
Entry("Network - Basic", "basic.network", 0, ""), Entry("Network - Basic", "basic.network", 0, ""),
Entry("Network - Disable DNS", "disable-dns.network", 0, ""), Entry("Network - Disable DNS", "disable-dns.network", 0, ""),