quadlet: add default network dependencies to all units

There is no good reason for the special case, kube and pod units
definitely need it. Volume and network units maybe not but for
consistency we add it there as well. This makes the docs much easier to
write and understand for users as the behavior will not differ.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-10-18 11:52:59 +02:00
parent 57b022782b
commit 67e0fa8b89
13 changed files with 26 additions and 21 deletions

View File

@ -732,11 +732,11 @@ func process() error {
service, err = quadlet.ConvertContainer(unit, isUserFlag, unitsInfoMap)
case strings.HasSuffix(unit.Filename, ".volume"):
warnIfAmbiguousName(unit, quadlet.VolumeGroup)
service, err = quadlet.ConvertVolume(unit, unit.Filename, unitsInfoMap)
service, err = quadlet.ConvertVolume(unit, unit.Filename, unitsInfoMap, isUserFlag)
case strings.HasSuffix(unit.Filename, ".kube"):
service, err = quadlet.ConvertKube(unit, unitsInfoMap, isUserFlag)
case strings.HasSuffix(unit.Filename, ".network"):
service, err = quadlet.ConvertNetwork(unit, unit.Filename, unitsInfoMap)
service, err = quadlet.ConvertNetwork(unit, unit.Filename, unitsInfoMap, isUserFlag)
case strings.HasSuffix(unit.Filename, ".image"):
warnIfAmbiguousName(unit, quadlet.ImageGroup)
service, err = quadlet.ConvertImage(unit, unitsInfoMap, isUserFlag)

View File

@ -238,9 +238,9 @@ that limit the output to only the units you are debugging.
### Implicit network dependencies
In the case of Container, Image and Build units, Quadlet will add dependencies on the `network-online.target` (as root)
or `podman-user-wait-network-online.service` (as user) by adding `After=` and `Wants=` properties to the unit.
This is to ensure that the network is reachable if an image needs to be pulled and by the time the container is started.
Quadlet will add dependencies on the `network-online.target` (as root) or `podman-user-wait-network-online.service`
(as user) by adding `After=` and `Wants=` properties to the unit. This is to ensure that the network is reachable
if an image needs to be pulled and by the time the container is started.
The special case `podman-user-wait-network-online.service` unit is needed as user because user units are unable to wait
for system (root) units so `network-online.target` doesn't do anything there and is instead ignored. As this caused
@ -1796,11 +1796,6 @@ exists on the host, pulling it if needed.
Using image units allows containers and volumes to depend on images being automatically pulled. This is
particularly interesting when using special options to control image pulls.
Note: The generated service have a dependency on `network-online.target` or
`podman-user-wait-network-online.service` assuring the network is reachable if an image needs to be pulled.
If the image service needs to run without available network (e.g. early in boot), this behavior
can be disabled by adding `DefaultDependencies=false` in the `Quadlet` section.
Valid options for `[Image]` are listed below:
| **[Image] options** | **podman image pull equivalent** |

View File

@ -882,7 +882,7 @@ func ConvertContainer(container *parser.UnitFile, isUser bool, unitsInfoMap map[
// The original Network group is kept around as X-Network.
// Also returns the canonical network name, either auto-generated or user-defined via the
// NetworkName key-value.
func ConvertNetwork(network *parser.UnitFile, name string, unitsInfoMap map[string]*UnitInfo) (*parser.UnitFile, error) {
func ConvertNetwork(network *parser.UnitFile, name string, unitsInfoMap map[string]*UnitInfo, isUser bool) (*parser.UnitFile, error) {
unitInfo, ok := unitsInfoMap[network.Filename]
if !ok {
return nil, fmt.Errorf("internal error while processing network %s", network.Filename)
@ -891,6 +891,8 @@ func ConvertNetwork(network *parser.UnitFile, name string, unitsInfoMap map[stri
service := network.Dup()
service.Filename = unitInfo.ServiceFileName()
addDefaultDependencies(service, isUser)
if network.Path != "" {
service.Add(UnitGroup, "SourcePath", network.Path)
}
@ -992,7 +994,7 @@ func ConvertNetwork(network *parser.UnitFile, name string, unitsInfoMap map[stri
// The original Volume group is kept around as X-Volume.
// Also returns the canonical volume name, either auto-generated or user-defined via the VolumeName
// key-value.
func ConvertVolume(volume *parser.UnitFile, name string, unitsInfoMap map[string]*UnitInfo) (*parser.UnitFile, error) {
func ConvertVolume(volume *parser.UnitFile, name string, unitsInfoMap map[string]*UnitInfo, isUser bool) (*parser.UnitFile, error) {
unitInfo, ok := unitsInfoMap[volume.Filename]
if !ok {
return nil, fmt.Errorf("internal error while processing network %s", volume.Filename)
@ -1001,6 +1003,8 @@ func ConvertVolume(volume *parser.UnitFile, name string, unitsInfoMap map[string
service := volume.Dup()
service.Filename = unitInfo.ServiceFileName()
addDefaultDependencies(service, isUser)
if volume.Path != "" {
service.Add(UnitGroup, "SourcePath", volume.Path)
}
@ -1142,6 +1146,8 @@ func ConvertKube(kube *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, isUse
service := kube.Dup()
service.Filename = unitInfo.ServiceFileName()
addDefaultDependencies(service, isUser)
if kube.Path != "" {
service.Add(UnitGroup, "SourcePath", kube.Path)
}
@ -1532,6 +1538,8 @@ func ConvertPod(podUnit *parser.UnitFile, name string, unitsInfoMap map[string]*
service := podUnit.Dup()
service.Filename = unitInfo.ServiceFileName()
addDefaultDependencies(service, isUser)
if podUnit.Path != "" {
service.Add(UnitGroup, "SourcePath", podUnit.Path)
}

View File

@ -1,7 +1,7 @@
## assert-podman-args --driver image
## assert-podman-args --opt image=localhost/imagename
## assert-key-is "Unit" "Requires" "basic.service"
## assert-key-is "Unit" "After" "basic.service"
## assert-key-is-regex "Unit" "After" "network-online.target|podman-user-wait-network-online.service" "basic.service"
[Volume]
Driver=image

View File

@ -1,7 +1,7 @@
## assert-podman-args --driver image
## assert-podman-args --opt image=localhost/imagename
## assert-key-is "Unit" "Requires" "basic-build.service"
## assert-key-is "Unit" "After" "basic-build.service"
## assert-key-is-regex "Unit" "After" "network-online.target|podman-user-wait-network-online.service" "basic-build.service"
[Volume]
Driver=image

View File

@ -1,7 +1,7 @@
## assert-podman-args --driver image
## assert-podman-args --opt image=localhost/imagename
## assert-key-is "Unit" "Requires" "basic.service"
## assert-key-is "Unit" "After" "basic.service"
## assert-key-is-regex "Unit" "After" "network-online.target|podman-user-wait-network-online.service" "basic.service"
[Volume]
Driver=image

View File

@ -1,7 +1,7 @@
## assert-podman-args --driver image
## assert-podman-args --opt image=localhost/imagename
## assert-key-is "Unit" "Requires" "basic-image.service"
## assert-key-is "Unit" "After" "basic-image.service"
## assert-key-is-regex "Unit" "After" "network-online.target|podman-user-wait-network-online.service" "basic-image.service"
[Volume]
Driver=image

View File

@ -1,6 +1,6 @@
## assert-podman-args "--network" "systemd-basic"
## assert-key-is "Unit" "Requires" "basic-network.service"
## assert-key-is "Unit" "After" "basic-network.service"
## assert-key-is-regex "Unit" "After" "network-online.target|podman-user-wait-network-online.service" "basic-network.service"
[Kube]

View File

@ -1,6 +1,6 @@
## assert-podman-pre-args "--network" "systemd-basic"
## assert-key-is "Unit" "Requires" "basic-network.service"
## assert-key-is "Unit" "After" "basic-network.service"
## assert-key-is-regex "Unit" "After" "network-online.target|podman-user-wait-network-online.service" "basic-network.service"
[Pod]
Network=basic.network

View File

@ -1,6 +1,6 @@
## assert-podman-args "--network" "test-network"
## assert-key-is "Unit" "Requires" "basic.service"
## assert-key-is "Unit" "After" "basic.service"
## assert-key-is-regex "Unit" "After" "network-online.target|podman-user-wait-network-online.service" "basic.service"
[Kube]

View File

@ -1,6 +1,6 @@
## assert-podman-pre-args "--network" "test-network"
## assert-key-is "Unit" "Requires" "basic.service"
## assert-key-is "Unit" "After" "basic.service"
## assert-key-is-regex "Unit" "After" "network-online.target|podman-user-wait-network-online.service" "basic.service"
[Pod]
Network=service-name.network

View File

@ -1,6 +1,6 @@
## assert-podman-pre-args -v test-volume:/container/quadlet
## assert-key-is "Unit" "Requires" "basic.service"
## assert-key-is "Unit" "After" "basic.service"
## assert-key-is-regex "Unit" "After" "network-online.target|podman-user-wait-network-online.service" "basic.service"
[Pod]
Volume=service-name.volume:/container/quadlet

View File

@ -818,6 +818,8 @@ BOGUS=foo
"[X-Kube]",
"Yaml=deployment.yml",
"[Unit]",
"Wants=network-online.target",
"After=network-online.target",
fmt.Sprintf("SourcePath=%s/basic.kube", quadletDir),
"RequiresMountsFor=%t/containers",
"[Service]",