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
397 stars 12 forks source link

Fix `podlet generate pod` to work with older versions of Podman #94

Open Taomyn opened 2 months ago

Taomyn commented 2 months ago

I have downloaded podlet 0.3.0 binary for my Fedora 39 server in order to start converting my pods from using the old "podman generate systemd" to quadlets.

When I run the command "./podlet generate pod ChangeDetection" it shows:

Error:
   0: error creating Quadlet file(s) from an existing object
   1: error inspecting pod `ChangeDetection`
   2: error deserializing from `podman pod inspect ChangeDetection` output
   3: invalid type: map, expected a sequence

Location:
   src/cli/generate.rs:752

Podman Stdout:
   {
        "Id": "e0cc277f3448ab2d00d25524da47a156c0d2944cbf61776b47c375c049c9f7e2",
        "Name": "ChangeDetection",
        "Created": "2024-06-25T09:21:57.99146156+02:00",
        "CreateCommand": [
             "podman",
             "pod",
             "create",
             "--name",
             "ChangeDetection",
             "--publish",
             "5000:5000/tcp"
        ],
        "ExitPolicy": "continue",
        "State": "Running",
        "Hostname": "",
        "CreateCgroup": true,
        "CgroupParent": "machine.slice",
        "CgroupPath": "machine.slice/machine-libpod_pod_e0cc277f3448ab2d00d25524da47a156c0d2944cbf61776b47c375c049c9f7e2.slice",
        "CreateInfra": true,
        "InfraContainerID": "1d260b336658fc429f6fa70a7d89be492d5a100937e72cb43fd99d700c93e024",
        "InfraConfig": {
             "PortBindings": {
                  "5000/tcp": [
                       {
                            "HostIp": "",
                            "HostPort": "5000"
                       }
                  ]
             },
             "HostNetwork": false,
             "StaticIP": "",
             "StaticMAC": "",
             "NoManageResolvConf": false,
             "DNSServer": null,
             "DNSSearch": null,
             "DNSOption": null,
             "NoManageHosts": false,
             "HostAdd": null,
             "Networks": [
                  "podman"
             ],
             "NetworkOptions": null,
             "pid_ns": "private",
             "userns": "host",
             "uts_ns": "private"
        },
        "SharedNamespaces": [
             "ipc",
             "net",
             "uts"
        ],
        "NumContainers": 3,
        "Containers": [
             {
                  "Id": "1d260b336658fc429f6fa70a7d89be492d5a100937e72cb43fd99d700c93e024",
                  "Name": "e0cc277f3448-infra",
                  "State": "running"
             },
             {
                  "Id": "2728e9f367c76988b29929084c8ffc4f5616dc33e25b6c274b722528ca7253cb",
                  "Name": "changedetection",
                  "State": "running"
             },
             {
                  "Id": "49784b115aad5a7b588a9da5a6e5a833dffb93ad3c80948d246153eec9faa173",
                  "Name": "browserless",
                  "State": "running"
             }
        ],
        "LockNumber": 59
   }

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
cuihaoleo commented 1 week ago

Same issue here. I'm using podman 4.9.3 from Ubuntu 24.04 repo. It seems podman pod inspect returns an object directly while podlet expects a list of a single object. Not sure if it's different between versions.

$ sudo podman pod inspect wordpress | head
{
     "Id": "5b0473e939e5aab57a52b22aa5dc4c4777d207ed75ea38d0e02b66027e0f2bea",
     "Name": "wordpress",
     "Created": "2024-09-07T14:12:21.939185473-07:00",
     "CreateCommand": [
          "/usr/bin/podman",
          "pod",
          "create",
          "--infra-conmon-pidfile",
          "/run/pod-wordpress.pid",  
Taomyn commented 1 week ago

I recently updated to Fedora 40, which is running podman v5.2.2, but now when I run the generate I get the following:

Error:
   0: error creating Quadlet file(s) from an existing object
   1: error parsing `podman pod create` command from `["podman", "pod", "create", "--name", "ChangeDetection", "--publish", "5000:5000/tcp"]`
   2: error: unexpected argument '--name' found

        tip: to pass '--name' as a value, use '-- --name'

   2: Usage: create [OPTIONS] <NAME>

      For more information, try '--help'.
   2:

Location:
   src/cli/generate.rs:277

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

Running podman inspect like @cuihaoleo and it returns:

[
     {
          "Id": "01fd7d82e13d9fc67af0d555835352c28b5a1e773ace66cc80581f023328ec44",
          "Name": "ChangeDetection",
          "Created": "2024-08-16T16:02:18.008505774+02:00",
          "CreateCommand": [
               "podman",
               "pod",
               "create",
               "--name",
k9withabone commented 2 days ago

The second error you are hitting is a due to #88. The first is because podman pod inspect changed it's output to always be an array in Podman v5.0.0. It should be changed so that it works with older versions as well.

Taomyn commented 2 days ago

The second error you are hitting is a due to #88. The first is because podman pod inspect changed it's output to always be an array in Podman v5.0.0. It should be changed so that it works with older versions as well.

My second report was for Podman v5.2.2 so what's "older versions"? I can't say what Fedora 39 was running when I first reported my issue which is shame.

k9withabone commented 2 days ago

My second report was for Podman v5.2.2 so what's "older versions"?

Podman versions less than 5.0.0, so v4.9.5 and earlier. You can see the change in the Podman v5.0.0 release notes under "Breaking Changes" in the 7th bullet point.

Taomyn commented 10 hours ago

Should I create a separate issue now that mine has moved on to being with Podman v5.2.2?