Skip to content

Commit

Permalink
Quadlet Network - Fix the name of the required network service
Browse files Browse the repository at this point in the history
The name of the network service does not start with systemd only the
podman network name

Signed-off-by: Ygal Blum <[email protected]>
  • Loading branch information
ygalblum committed Jan 2, 2023
1 parent e9417a9 commit a061d79
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,13 +811,13 @@ func addNetworks(quadletUnitFile *parser.UnitFile, groupName string, serviceUnit
networks := quadletUnitFile.LookupAll(groupName, KeyNetwork)
for _, network := range networks {
if len(network) > 0 {
networkName, options, found := strings.Cut(network, ":")
if strings.HasSuffix(networkName, ".network") {
quadletNetworkName, options, found := strings.Cut(network, ":")
if strings.HasSuffix(quadletNetworkName, ".network") {
// the podman network name is systemd-$name
networkName = replaceExtension(networkName, "", "systemd-", "")
networkName := replaceExtension(quadletNetworkName, "", "systemd-", "")

// the systemd unit name is $name-network.service
networkServiceName := replaceExtension(networkName, ".service", "", "-network")
networkServiceName := replaceExtension(quadletNetworkName, ".service", "", "-network")

serviceUnitFile.Add(UnitGroup, "Requires", networkServiceName)
serviceUnitFile.Add(UnitGroup, "After", networkServiceName)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/quadlet/network.quadlet.container
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## assert-podman-args "--network=systemd-basic"
## assert-key-is "Unit" "Requires" "systemd-basic-network.service"
## assert-key-is "Unit" "After" "systemd-basic-network.service"
## assert-key-is "Unit" "Requires" "basic-network.service"
## assert-key-is "Unit" "After" "basic-network.service"

[Container]
Image=localhost/imagename
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/quadlet/network.quadlet.kube
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## assert-podman-args "--network=systemd-basic"
## assert-key-is "Unit" "Requires" "systemd-basic-network.service"
## assert-key-is "Unit" "After" "systemd-basic-network.service"
## assert-key-is "Unit" "Requires" "basic-network.service"
## assert-key-is "Unit" "After" "basic-network.service"


[Kube]
Expand Down

0 comments on commit a061d79

Please sign in to comment.