Skip to content

Commit 35d1f12

Browse files
committed
make podman pod inspect output a json array
Just like all the other inspect commands that accept multiple args we should just make podman pod inspect output a json array. This makes the code more consistent and removes the extra workaround which was needed before to support this. Signed-off-by: Paul Holzinger <[email protected]>
1 parent daf7a2c commit 35d1f12

File tree

7 files changed

+35
-51
lines changed

7 files changed

+35
-51
lines changed

Diff for: cmd/podman/common/inspect.go

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ const (
1111
NetworkType = "network"
1212
// PodType is the pod type.
1313
PodType = "pod"
14-
// PodLegacyType is the pod type for backwards compatibility with the old pod inspect code.
15-
// This allows us to use the shared inspect code but still provide the correct output format
16-
// when podman pod inspect was called.
17-
PodLegacyType = "pod-legacy"
1814
// VolumeType is the volume type
1915
VolumeType = "volume"
2016
)

Diff for: cmd/podman/inspect/inspect.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
123123
for i := range ctrData {
124124
data = append(data, ctrData[i])
125125
}
126-
case common.PodType, common.PodLegacyType:
126+
case common.PodType:
127127
podData, allErrs, err := i.containerEngine.PodInspect(ctx, namesOrIDs, i.options)
128128
if err != nil {
129129
return err
@@ -163,14 +163,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
163163
var err error
164164
switch {
165165
case report.IsJSON(i.options.Format) || i.options.Format == "":
166-
if i.options.Type == common.PodLegacyType && len(data) == 1 {
167-
// We need backwards compat with the old podman pod inspect behavior.
168-
// https://github.com/containers/podman/pull/15675
169-
// TODO (5.0): consider removing this to better match other commands.
170-
err = printJSON(data[0])
171-
} else {
172-
err = printJSON(data)
173-
}
166+
err = printJSON(data)
174167
default:
175168
// Landing here implies user has given a custom --format
176169
var rpt *report.Formatter

Diff for: cmd/podman/pods/inspect.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ func init() {
4141
}
4242

4343
func inspectExec(cmd *cobra.Command, args []string) error {
44-
// We need backwards compat with the old podman pod inspect behavior.
45-
// https://github.com/containers/podman/pull/15675
46-
inspectOpts.Type = common.PodLegacyType
44+
inspectOpts.Type = common.PodType
4745
return inspect.Inspect(args, *inspectOpts)
4846
}

Diff for: docs/source/markdown/podman-pod-inspect.1.md.in

+26-25
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,32 @@ Valid placeholders for the Go template are listed below:
6262
## EXAMPLE
6363
```
6464
# podman pod inspect foobar
65-
{
66-
67-
"Id": "3513ca70583dd7ef2bac83331350f6b6c47d7b4e526c908e49d89ebf720e4693",
68-
"Name": "foobar",
69-
"Labels": {},
70-
"CgroupParent": "/libpod_parent",
71-
"CreateCgroup": true,
72-
"Created": "2018-08-08T11:15:18.823115347-05:00"
73-
"State": "created",
74-
"Hostname": "",
75-
"SharedNamespaces": [
76-
"uts",
77-
"ipc",
78-
"net"
79-
]
80-
"CreateInfra": false,
81-
"InfraContainerID": "1020dd70583dd7ff2bac83331350f6b6e007de0d026c908e49d89ebf891d4699"
82-
"CgroupPath": ""
83-
"Containers": [
84-
{
85-
"id": "d53f8bf1e9730281264aac6e6586e327429f62c704abea4b6afb5d8a2b2c9f2c",
86-
"state": "configured"
87-
}
88-
]
89-
}
65+
[
66+
{
67+
"Id": "3513ca70583dd7ef2bac83331350f6b6c47d7b4e526c908e49d89ebf720e4693",
68+
"Name": "foobar",
69+
"Labels": {},
70+
"CgroupParent": "/libpod_parent",
71+
"CreateCgroup": true,
72+
"Created": "2018-08-08T11:15:18.823115347-05:00"
73+
"State": "created",
74+
"Hostname": "",
75+
"SharedNamespaces": [
76+
"uts",
77+
"ipc",
78+
"net"
79+
]
80+
"CreateInfra": false,
81+
"InfraContainerID": "1020dd70583dd7ff2bac83331350f6b6e007de0d026c908e49d89ebf891d4699"
82+
"CgroupPath": ""
83+
"Containers": [
84+
{
85+
"id": "d53f8bf1e9730281264aac6e6586e327429f62c704abea4b6afb5d8a2b2c9f2c",
86+
"state": "configured"
87+
}
88+
]
89+
}
90+
]
9091
```
9192

9293
## SEE ALSO

Diff for: test/e2e/common_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,11 @@ func (s *PodmanSessionIntegration) InspectContainerToJSON() []define.InspectCont
695695

696696
// InspectPodToJSON takes the sessions output from a pod inspect and returns json
697697
func (s *PodmanSessionIntegration) InspectPodToJSON() define.InspectPodData {
698-
var i define.InspectPodData
698+
var i []define.InspectPodData
699699
err := jsoniter.Unmarshal(s.Out.Contents(), &i)
700700
Expect(err).ToNot(HaveOccurred())
701-
return i
701+
Expect(i).To(HaveLen(1))
702+
return i[0]
702703
}
703704

704705
// InspectPodToJSON takes the sessions output from an inspect and returns json

Diff for: test/e2e/pod_inspect_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package integration
22

33
import (
4-
"encoding/json"
5-
6-
"github.com/containers/podman/v4/libpod/define"
74
. "github.com/containers/podman/v4/test/utils"
85
. "github.com/onsi/ginkgo/v2"
96
. "github.com/onsi/gomega"
@@ -69,9 +66,7 @@ var _ = Describe("Podman pod inspect", func() {
6966
inspectOut.WaitWithDefaultTimeout()
7067
Expect(inspectOut).Should(ExitCleanly())
7168

72-
inspectJSON := new(define.InspectPodData)
73-
err := json.Unmarshal(inspectOut.Out.Contents(), inspectJSON)
74-
Expect(err).ToNot(HaveOccurred())
69+
inspectJSON := inspectOut.InspectPodToJSON()
7570
Expect(inspectJSON.InfraConfig).To(Not(BeNil()))
7671
Expect(inspectJSON.InfraConfig.PortBindings["80/tcp"]).To(HaveLen(1))
7772
Expect(inspectJSON.InfraConfig.PortBindings["80/tcp"][0]).To(HaveField("HostPort", "8383"))

Diff for: test/system/200-pod.bats

+2-2
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,8 @@ function thingy_with_unique_id() {
716716
podid="$output"
717717
run_podman run -d --pod $podid $IMAGE top -d 2
718718

719-
run_podman pod inspect $podid
720-
result=$(jq -r .CgroupPath <<< $output)
719+
run_podman pod inspect $podid --format "{{.CgroupPath}}"
720+
result="$output"
721721
assert "$result" =~ "/" ".CgroupPath is a valid path"
722722

723723
if is_cgroupsv2; then

0 commit comments

Comments
 (0)