Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/markdown/podman-quadlet-list.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Print results with a Go template.
| .App | Name of application if Quadlet is part of an app |
| .Name | Name of the Quadlet file |
| .Path | Quadlet file path on disk |
| .Pod | Pod name (if the quadlet is part of a pod - only applicable to .container files)|
| .Status | Quadlet status corresponding to systemd unit |
| .UnitName | Systemd unit name corresponding to quadlet |

Expand Down
2 changes: 2 additions & 0 deletions pkg/domain/entities/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type ListQuadlet struct {
// If multiple quadlets were installed together they will belong
// to common App.
App string
// Pod is the name of the pod this quadlet belongs to
Pod string
}

// QuadletRemoveOptions contains parameters for removing Quadlets
Expand Down
11 changes: 11 additions & 0 deletions pkg/domain/infra/abi/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,21 @@ func (ic *ContainerEngine) QuadletList(ctx context.Context, options entities.Qua
if ok {
appName = value
}

// Parse the unit file to extract Pod= from the [Container] section
podName := ""
unitFile, err := parser.ParseUnitFile(path)
if err == nil {
// LookupLast returns the last value if Pod= is specified multiple times
value, _ := unitFile.LookupLast("Container", "Pod")
podName = value
}

report := entities.ListQuadlet{
Name: filepath.Base(path),
Path: path,
App: appName,
Pod: podName,
}

serviceName, err := getQuadletServiceName(path)
Expand Down
39 changes: 39 additions & 0 deletions test/system/253-podman-quadlet.bats
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,43 @@ EOF
run_podman quadlet rm alpine-quadlet.container
}

@test "quadlet verb - list shows Pod field" {
# Create a pod quadlet
local pod_file=$PODMAN_TMPDIR/test-pod.pod
cat > $pod_file <<EOF
[Pod]
EOF
# Create a container quadlet that joins the pod
local container_file=$PODMAN_TMPDIR/pod-member.container
cat > $container_file <<EOF
[Container]
Image=$IMAGE
Pod=test-pod
Exec=sh -c "echo STARTED CONTAINER IN POD; trap 'exit' SIGTERM; while :; do sleep 0.1; done"
EOF
# Create a standalone container (no pod)
local standalone_file=$PODMAN_TMPDIR/standalone.container
cat > $standalone_file <<EOF
[Container]
Image=$IMAGE
Exec=sh -c "echo STARTED STANDALONE; trap 'exit' SIGTERM; while :; do sleep 0.1; done"
EOF
# Install all quadlets
run_podman quadlet install $pod_file $container_file $standalone_file

# Test that Pod field appears in custom format
run_podman quadlet list --format '{{.Name}} {{.Pod}}'
assert "$output" =~ "pod-member.container test-pod" "container in pod should show pod name"
assert "$output" =~ $'standalone.container[[:space:]]*($|\n)' "standalone container should have empty pod field"
assert "$output" =~ $'test-pod.pod[[:space:]]*($|\n)' "pod itself should have empty pod field"

# Test that Pod field works in JSON output
run_podman quadlet list --format json
assert "$output" =~ '"Name".*"pod-member.container"' "JSON should contain pod-member"
assert "$output" =~ '"Pod".*"test-pod"' "JSON should show Pod field with value"

# Clean up
run_podman quadlet rm test-pod.pod pod-member.container standalone.container
}

# vim: filetype=sh