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
322 stars 10 forks source link

improve compose `network_mode` error message #38

Closed trijpstra-fourlights closed 6 months ago

trijpstra-fourlights commented 6 months ago

Hi, thanks for your hard work on this!

I noticed that the network_mode: 'service:xyz' is not supported, but network_mode: 'container:xyz' is.

The difference between the two:

* container: shares the networking stack and IP address of an existing container
* service: connects to the network of an existing service to enable communication, but containers maintain separate IP addresses and networking stacks

The service: network mode is useful for inter-container communication within a service. The container: mode can be used to join the networking namespace of an infrastructure container like a proxy or router to share its networking stack.

So service: keeps containers more isolated and portable, while container: ties them more directly to another container's network configuration.

I used the following patch to build the PKGBUILD with support for service:xyz and that seems to work.

diff --color --unified --recursive --text package.orig/podlet-0.2.2/src/cli/container/quadlet.rs package.new/podlet-0.2.2/src/cli/container/quadlet.rs
--- package.orig/podlet-0.2.2/src/cli/container/quadlet.rs      2023-12-16 00:32:56.000000000 +0100
+++ package.new/podlet-0.2.2/src/cli/container/quadlet.rs       2023-12-17 17:08:41.788103927 +0100
@@ -449,6 +449,7 @@
             .map(|mode| match mode.as_str() {
                 "bridge" | "host" | "none" => Ok(mode),
                 s if s.starts_with("container") => Ok(mode),
+                s if s.starts_with("service") => Ok(mode),
                 _ => Err(eyre::eyre!("network_mode `{mode}` is unsupported")),
             })
             .transpose()?

which can be applied by adding the following to the PKGBUILD

// ...

source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz" "add_network_mode_service.patch")
sha256sums=('70834d2143c2c06059cb424f9cc7cff0ef48c77d3a5938c4b97ecf257c3ff4f6'
            'eb4d9a538fbc03c5804ce94761d8a1950a05df4457813568c79783c4e511b91f')

// ....

prepare() {
  cd "$pkgname-$pkgver"
  patch --forward --strip=2 --input="${srcdir}/add_network_mode_service.patch"
}

// ...

I'll try to create a PR later

k9withabone commented 6 months ago

As discussed in #39, I think the best way to handle the service network_mode is to provide a better error message suggesting the use of the container network_mode and linking to the podman docs. Other suggestions are welcome.