Skip to content

Commit

Permalink
Merge pull request #21514 from Luap99/pod-inspect-output
Browse files Browse the repository at this point in the history
make podman pod inspect output a json array
  • Loading branch information
openshift-merge-bot[bot] authored Feb 8, 2024
2 parents 8a6165e + 35d1f12 commit 4c9bd24
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 51 deletions.
4 changes: 0 additions & 4 deletions cmd/podman/common/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ const (
NetworkType = "network"
// PodType is the pod type.
PodType = "pod"
// PodLegacyType is the pod type for backwards compatibility with the old pod inspect code.
// This allows us to use the shared inspect code but still provide the correct output format
// when podman pod inspect was called.
PodLegacyType = "pod-legacy"
// VolumeType is the volume type
VolumeType = "volume"
)
11 changes: 2 additions & 9 deletions cmd/podman/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
for i := range ctrData {
data = append(data, ctrData[i])
}
case common.PodType, common.PodLegacyType:
case common.PodType:
podData, allErrs, err := i.containerEngine.PodInspect(ctx, namesOrIDs, i.options)
if err != nil {
return err
Expand Down Expand Up @@ -163,14 +163,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
var err error
switch {
case report.IsJSON(i.options.Format) || i.options.Format == "":
if i.options.Type == common.PodLegacyType && len(data) == 1 {
// We need backwards compat with the old podman pod inspect behavior.
// https://github.com/containers/podman/pull/15675
// TODO (5.0): consider removing this to better match other commands.
err = printJSON(data[0])
} else {
err = printJSON(data)
}
err = printJSON(data)
default:
// Landing here implies user has given a custom --format
var rpt *report.Formatter
Expand Down
4 changes: 1 addition & 3 deletions cmd/podman/pods/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ func init() {
}

func inspectExec(cmd *cobra.Command, args []string) error {
// We need backwards compat with the old podman pod inspect behavior.
// https://github.com/containers/podman/pull/15675
inspectOpts.Type = common.PodLegacyType
inspectOpts.Type = common.PodType
return inspect.Inspect(args, *inspectOpts)
}
51 changes: 26 additions & 25 deletions docs/source/markdown/podman-pod-inspect.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,32 @@ Valid placeholders for the Go template are listed below:
## EXAMPLE
```
# podman pod inspect foobar
{

"Id": "3513ca70583dd7ef2bac83331350f6b6c47d7b4e526c908e49d89ebf720e4693",
"Name": "foobar",
"Labels": {},
"CgroupParent": "/libpod_parent",
"CreateCgroup": true,
"Created": "2018-08-08T11:15:18.823115347-05:00"
"State": "created",
"Hostname": "",
"SharedNamespaces": [
"uts",
"ipc",
"net"
]
"CreateInfra": false,
"InfraContainerID": "1020dd70583dd7ff2bac83331350f6b6e007de0d026c908e49d89ebf891d4699"
"CgroupPath": ""
"Containers": [
{
"id": "d53f8bf1e9730281264aac6e6586e327429f62c704abea4b6afb5d8a2b2c9f2c",
"state": "configured"
}
]
}
[
{
"Id": "3513ca70583dd7ef2bac83331350f6b6c47d7b4e526c908e49d89ebf720e4693",
"Name": "foobar",
"Labels": {},
"CgroupParent": "/libpod_parent",
"CreateCgroup": true,
"Created": "2018-08-08T11:15:18.823115347-05:00"
"State": "created",
"Hostname": "",
"SharedNamespaces": [
"uts",
"ipc",
"net"
]
"CreateInfra": false,
"InfraContainerID": "1020dd70583dd7ff2bac83331350f6b6e007de0d026c908e49d89ebf891d4699"
"CgroupPath": ""
"Containers": [
{
"id": "d53f8bf1e9730281264aac6e6586e327429f62c704abea4b6afb5d8a2b2c9f2c",
"state": "configured"
}
]
}
]
```

## SEE ALSO
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,11 @@ func (s *PodmanSessionIntegration) InspectContainerToJSON() []define.InspectCont

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

// InspectPodToJSON takes the sessions output from an inspect and returns json
Expand Down
7 changes: 1 addition & 6 deletions test/e2e/pod_inspect_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package integration

import (
"encoding/json"

"github.com/containers/podman/v4/libpod/define"
. "github.com/containers/podman/v4/test/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -69,9 +66,7 @@ var _ = Describe("Podman pod inspect", func() {
inspectOut.WaitWithDefaultTimeout()
Expect(inspectOut).Should(ExitCleanly())

inspectJSON := new(define.InspectPodData)
err := json.Unmarshal(inspectOut.Out.Contents(), inspectJSON)
Expect(err).ToNot(HaveOccurred())
inspectJSON := inspectOut.InspectPodToJSON()
Expect(inspectJSON.InfraConfig).To(Not(BeNil()))
Expect(inspectJSON.InfraConfig.PortBindings["80/tcp"]).To(HaveLen(1))
Expect(inspectJSON.InfraConfig.PortBindings["80/tcp"][0]).To(HaveField("HostPort", "8383"))
Expand Down
4 changes: 2 additions & 2 deletions test/system/200-pod.bats
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,8 @@ function thingy_with_unique_id() {
podid="$output"
run_podman run -d --pod $podid $IMAGE top -d 2

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

if is_cgroupsv2; then
Expand Down

0 comments on commit 4c9bd24

Please sign in to comment.