mirror of
https://github.com/containers/podman.git
synced 2025-07-15 03:02:52 +08:00
Merge pull request #21514 from Luap99/pod-inspect-output
make podman pod inspect output a json array
This commit is contained in:
@ -11,10 +11,6 @@ const (
|
|||||||
NetworkType = "network"
|
NetworkType = "network"
|
||||||
// PodType is the pod type.
|
// PodType is the pod type.
|
||||||
PodType = "pod"
|
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 is the volume type
|
||||||
VolumeType = "volume"
|
VolumeType = "volume"
|
||||||
)
|
)
|
||||||
|
@ -123,7 +123,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
|
|||||||
for i := range ctrData {
|
for i := range ctrData {
|
||||||
data = append(data, ctrData[i])
|
data = append(data, ctrData[i])
|
||||||
}
|
}
|
||||||
case common.PodType, common.PodLegacyType:
|
case common.PodType:
|
||||||
podData, allErrs, err := i.containerEngine.PodInspect(ctx, namesOrIDs, i.options)
|
podData, allErrs, err := i.containerEngine.PodInspect(ctx, namesOrIDs, i.options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -163,14 +163,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
|
|||||||
var err error
|
var err error
|
||||||
switch {
|
switch {
|
||||||
case report.IsJSON(i.options.Format) || i.options.Format == "":
|
case report.IsJSON(i.options.Format) || i.options.Format == "":
|
||||||
if i.options.Type == common.PodLegacyType && len(data) == 1 {
|
err = printJSON(data)
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
// Landing here implies user has given a custom --format
|
// Landing here implies user has given a custom --format
|
||||||
var rpt *report.Formatter
|
var rpt *report.Formatter
|
||||||
|
@ -41,8 +41,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func inspectExec(cmd *cobra.Command, args []string) error {
|
func inspectExec(cmd *cobra.Command, args []string) error {
|
||||||
// We need backwards compat with the old podman pod inspect behavior.
|
inspectOpts.Type = common.PodType
|
||||||
// https://github.com/containers/podman/pull/15675
|
|
||||||
inspectOpts.Type = common.PodLegacyType
|
|
||||||
return inspect.Inspect(args, *inspectOpts)
|
return inspect.Inspect(args, *inspectOpts)
|
||||||
}
|
}
|
||||||
|
@ -62,31 +62,32 @@ Valid placeholders for the Go template are listed below:
|
|||||||
## EXAMPLE
|
## EXAMPLE
|
||||||
```
|
```
|
||||||
# podman pod inspect foobar
|
# podman pod inspect foobar
|
||||||
{
|
[
|
||||||
|
{
|
||||||
"Id": "3513ca70583dd7ef2bac83331350f6b6c47d7b4e526c908e49d89ebf720e4693",
|
"Id": "3513ca70583dd7ef2bac83331350f6b6c47d7b4e526c908e49d89ebf720e4693",
|
||||||
"Name": "foobar",
|
"Name": "foobar",
|
||||||
"Labels": {},
|
"Labels": {},
|
||||||
"CgroupParent": "/libpod_parent",
|
"CgroupParent": "/libpod_parent",
|
||||||
"CreateCgroup": true,
|
"CreateCgroup": true,
|
||||||
"Created": "2018-08-08T11:15:18.823115347-05:00"
|
"Created": "2018-08-08T11:15:18.823115347-05:00"
|
||||||
"State": "created",
|
"State": "created",
|
||||||
"Hostname": "",
|
"Hostname": "",
|
||||||
"SharedNamespaces": [
|
"SharedNamespaces": [
|
||||||
"uts",
|
"uts",
|
||||||
"ipc",
|
"ipc",
|
||||||
"net"
|
"net"
|
||||||
]
|
]
|
||||||
"CreateInfra": false,
|
"CreateInfra": false,
|
||||||
"InfraContainerID": "1020dd70583dd7ff2bac83331350f6b6e007de0d026c908e49d89ebf891d4699"
|
"InfraContainerID": "1020dd70583dd7ff2bac83331350f6b6e007de0d026c908e49d89ebf891d4699"
|
||||||
"CgroupPath": ""
|
"CgroupPath": ""
|
||||||
"Containers": [
|
"Containers": [
|
||||||
{
|
{
|
||||||
"id": "d53f8bf1e9730281264aac6e6586e327429f62c704abea4b6afb5d8a2b2c9f2c",
|
"id": "d53f8bf1e9730281264aac6e6586e327429f62c704abea4b6afb5d8a2b2c9f2c",
|
||||||
"state": "configured"
|
"state": "configured"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
## SEE ALSO
|
## SEE ALSO
|
||||||
|
@ -695,10 +695,11 @@ func (s *PodmanSessionIntegration) InspectContainerToJSON() []define.InspectCont
|
|||||||
|
|
||||||
// InspectPodToJSON takes the sessions output from a pod inspect and returns json
|
// InspectPodToJSON takes the sessions output from a pod inspect and returns json
|
||||||
func (s *PodmanSessionIntegration) InspectPodToJSON() define.InspectPodData {
|
func (s *PodmanSessionIntegration) InspectPodToJSON() define.InspectPodData {
|
||||||
var i define.InspectPodData
|
var i []define.InspectPodData
|
||||||
err := jsoniter.Unmarshal(s.Out.Contents(), &i)
|
err := jsoniter.Unmarshal(s.Out.Contents(), &i)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
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
|
// InspectPodToJSON takes the sessions output from an inspect and returns json
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/containers/podman/v4/libpod/define"
|
|
||||||
. "github.com/containers/podman/v4/test/utils"
|
. "github.com/containers/podman/v4/test/utils"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@ -69,9 +66,7 @@ var _ = Describe("Podman pod inspect", func() {
|
|||||||
inspectOut.WaitWithDefaultTimeout()
|
inspectOut.WaitWithDefaultTimeout()
|
||||||
Expect(inspectOut).Should(ExitCleanly())
|
Expect(inspectOut).Should(ExitCleanly())
|
||||||
|
|
||||||
inspectJSON := new(define.InspectPodData)
|
inspectJSON := inspectOut.InspectPodToJSON()
|
||||||
err := json.Unmarshal(inspectOut.Out.Contents(), inspectJSON)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
Expect(inspectJSON.InfraConfig).To(Not(BeNil()))
|
Expect(inspectJSON.InfraConfig).To(Not(BeNil()))
|
||||||
Expect(inspectJSON.InfraConfig.PortBindings["80/tcp"]).To(HaveLen(1))
|
Expect(inspectJSON.InfraConfig.PortBindings["80/tcp"]).To(HaveLen(1))
|
||||||
Expect(inspectJSON.InfraConfig.PortBindings["80/tcp"][0]).To(HaveField("HostPort", "8383"))
|
Expect(inspectJSON.InfraConfig.PortBindings["80/tcp"][0]).To(HaveField("HostPort", "8383"))
|
||||||
|
@ -716,8 +716,8 @@ function thingy_with_unique_id() {
|
|||||||
podid="$output"
|
podid="$output"
|
||||||
run_podman run -d --pod $podid $IMAGE top -d 2
|
run_podman run -d --pod $podid $IMAGE top -d 2
|
||||||
|
|
||||||
run_podman pod inspect $podid
|
run_podman pod inspect $podid --format "{{.CgroupPath}}"
|
||||||
result=$(jq -r .CgroupPath <<< $output)
|
result="$output"
|
||||||
assert "$result" =~ "/" ".CgroupPath is a valid path"
|
assert "$result" =~ "/" ".CgroupPath is a valid path"
|
||||||
|
|
||||||
if is_cgroupsv2; then
|
if is_cgroupsv2; then
|
||||||
|
Reference in New Issue
Block a user