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
475 stars 13 forks source link

Not generating absolute paths from relative paths #102

Closed cob-web-corner closed 2 weeks ago

cob-web-corner commented 1 month ago

podlet compose --kube docker-compose.yaml

The compose:

  the_service:
    volumes:
      - /run/user/1001/podman/podman.sock:/var/run/docker.sock
      - ./data:/data
      - ./config.yaml:/config.yaml
    container_name: container_name
    image: container/image:latest

Resulting yaml

  - hostPath:
      path: ./data
    name: container_data
  - hostPath:
      path: ./config.yaml
    name: **container_config.yaml**

Obviously not a whole real-example but just to demonstrate. The only way the resulting kube file can be used in a corresponding .kube service is by using absolute paths. During the podlet run it should convert these paths

Version

$ podlet --version
podlet 0.3.0
cob-web-corner commented 1 month ago

Just found this:

https://github.com/containers/podlet/pull/55

and tried podlet --absolute-host-paths compose --kube but I'm still getting relative paths in the yaml output

I will note, this is translating from relative to absolute paths when using this /usr/lib/systemd/system-generators/podman-system-generator --user --dryrun

k9withabone commented 1 month ago

From podlet --help:

  -a, --absolute-host-paths [<RESOLVE_DIR>]
          Convert relative host paths to absolute paths.

          Relative host paths in generated Quadlet files are resolved using the given directory or the current working
          directory. For `podlet compose`, the parent directory of the compose file is used as the default if the compose file
          is not read from stdin.

          All host paths are also cleaned to remove interior `/../`, `/./`, and `//`.

          When using `podlet compose --pod`, modifying paths in generated Kubernetes YAML files is not supported.

          Note that only host paths not in the `PodmanArgs=` Quadlet option will be modified.

          Podlet will return an error if the current working directory cannot be read, or if the given directory path is not
          absolute.

See that it says "Quadlet files", not Kubernetes YAML. The reason for this is that it would be significantly more complicated to do for Kubernetes YAML files. The types are controlled by the k8s-openapi library, and they are not the correct to work with what I did to get that feature working with Quadlet files (the paths are Strings, not PathBufs). It would also be a lot of additional work to find all the host paths and potentially parse them out from other strings. I would gladly accept a PR that figures out a way around the limitations and does the work, but I don't have the time for it.

Note that Podman does work Kubernetes YAML that has relative paths. The SetWorkingDirectory= option is all about how relative paths should be resolved.

k9withabone commented 1 month ago

Just noticed in the help that it says in the 4th paragraph podlet compose --pod instead of --kube like it should.

cob-web-corner commented 1 month ago

It would also be a lot of additional work to find all the host paths and potentially parse them out from other strings. I would gladly accept a PR that figures out a way around the limitations and does the work, but I don't have the time for it.

I get it, other more important things to work on and this isn't a show stopper and the SetWorkingDirectory option is available

Just noticed in the help that it says in the 4th paragraph podlet compose --pod instead of --kube like it should.

Okay glad I'm not crazy I read that about 20 times before I saw your comment

Thanks for the response!