Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
NjlsShade opened this issue Jan 7, 2024 · 3 comments
Closed

Comments

@NjlsShade
Copy link

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants