containers / podlet

Generate Podman Quadlet files from a Podman command, compose file, or existing object
https://crates.io/crates/podlet
Mozilla Public License 2.0
318 stars 10 forks source link

Networks are added to the quadlet file with ".network" appended #48

Closed NjlsShade closed 5 months ago

NjlsShade commented 6 months ago

When creating a quadlet from a compose file containing one or more network definitions, it will output the resulting container structure with ".network" appended to the end of all networks configured. This is not the correct syntax and will fail.

Given the compose file below:

services:
    test:
        container_name: test
        image: test/test:latest
        networks:
            - main

The output will be:

# test.container
[Container]
ContainerName=test
Image=test/test:latest
Network=main.network

[Install]
WantedBy=default.target

This issue does not occur if you provide podlet with podman run arguments insead of a compose file:

Given the command:

podlet --install podman run --network main test/test:latest

The output will be:

# test.container
[Container]
Image=test/test:latest
Network=main

[Install]
WantedBy=default.target
k9withabone commented 6 months ago

For compose files, podlet assumes that networks listed for a service are also listed under the top-level networks: key. Per the compose spec, that should always be the case. Technically, the snippet you gave is not a valid compose file.

Podlet will also generate a .network quadlet file for each network in the top-level networks: key (however, podlet doesn't support external networks for compose files). This is why podlet is adding .network to the name of the network for the Network= option. If you look at the quadlet docs for the option, they say you can reference a .network quadlet file to use.

For example, to complete your snippet above, if you give podlet the following compose file:

services:
    test:
        container_name: test
        image: test/test:latest
        networks:
            - main
networks:
    main:

It will produce the output:

# test.container
[Container]
ContainerName=test
Image=test/test:latest
Network=main.network

---

# main.network
[Network]

Representing two quadlet files to be used together.

As a side note, if your goal is to group all containers defined in a compose file into a separate network, this is better achieved with pods. All containers in a pod share a network namespace. First, remove or comment out the network definitions in the compose file. Then use podlet compose --pod <pod> which will generate a .kube quadlet file and a Kubernetes YAML file.

NjlsShade commented 5 months ago

Pods won't work in my use case, however, you have cleared up some confusion for me and the info will help out a lot. This was obviously my lack of knowledge, not an issue with the project. Thanks! Closing.

k9withabone commented 5 months ago

I'm glad I was able to help. I just mentioned pods because they solve a pretty common use case and people coming from docker may not know about them.