mirror of
https://github.com/containers/podman.git
synced 2025-06-22 18:08:11 +08:00
Merge pull request #5890 from sujil02/v2-pod-inspect-fix
Update pod inspect report to hold current pod status.
This commit is contained in:
@ -18,6 +18,8 @@ type InspectPodData struct {
|
|||||||
Namespace string `json:"Namespace,omitempty"`
|
Namespace string `json:"Namespace,omitempty"`
|
||||||
// Created is the time when the pod was created.
|
// Created is the time when the pod was created.
|
||||||
Created time.Time
|
Created time.Time
|
||||||
|
// State represents the current state of the pod.
|
||||||
|
State string `json:"State"`
|
||||||
// Hostname is the hostname that the pod will set.
|
// Hostname is the hostname that the pod will set.
|
||||||
Hostname string
|
Hostname string
|
||||||
// Labels is a set of key-value labels that have been applied to the
|
// Labels is a set of key-value labels that have been applied to the
|
||||||
|
@ -446,6 +446,7 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ctrStatuses := make(map[string]define.ContainerStatus, len(containers))
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
containerStatus := "unknown"
|
containerStatus := "unknown"
|
||||||
// Ignoring possible errors here because we don't want this to be
|
// Ignoring possible errors here because we don't want this to be
|
||||||
@ -459,12 +460,18 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) {
|
|||||||
Name: c.Name(),
|
Name: c.Name(),
|
||||||
State: containerStatus,
|
State: containerStatus,
|
||||||
})
|
})
|
||||||
|
ctrStatuses[c.ID()] = c.state.State
|
||||||
|
}
|
||||||
|
podState, err := CreatePodStatusResults(ctrStatuses)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
inspectData := define.InspectPodData{
|
inspectData := define.InspectPodData{
|
||||||
ID: p.ID(),
|
ID: p.ID(),
|
||||||
Name: p.Name(),
|
Name: p.Name(),
|
||||||
Namespace: p.Namespace(),
|
Namespace: p.Namespace(),
|
||||||
Created: p.CreatedTime(),
|
Created: p.CreatedTime(),
|
||||||
|
State: podState,
|
||||||
Hostname: "",
|
Hostname: "",
|
||||||
Labels: p.Labels(),
|
Labels: p.Labels(),
|
||||||
CreateCgroup: false,
|
CreateCgroup: false,
|
||||||
|
@ -174,8 +174,7 @@ var _ = Describe("Podman pods", func() {
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
response, err := pods.Inspect(bt.conn, newpod)
|
response, err := pods.Inspect(bt.conn, newpod)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
// FIXME sujil please fix this
|
Expect(response.State).To(Equal(define.PodStatePaused))
|
||||||
//Expect(response.Status).To(Equal(define.PodStatePaused))
|
|
||||||
for _, i := range response.Containers {
|
for _, i := range response.Containers {
|
||||||
Expect(define.StringToContainerStatus(i.State)).
|
Expect(define.StringToContainerStatus(i.State)).
|
||||||
To(Equal(define.ContainerStatePaused))
|
To(Equal(define.ContainerStatePaused))
|
||||||
@ -186,8 +185,7 @@ var _ = Describe("Podman pods", func() {
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
response, err = pods.Inspect(bt.conn, newpod)
|
response, err = pods.Inspect(bt.conn, newpod)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
// FIXME sujil please fix this
|
Expect(response.State).To(Equal(define.PodStateRunning))
|
||||||
//Expect(response.State.Status).To(Equal(define.PodStateRunning))
|
|
||||||
for _, i := range response.Containers {
|
for _, i := range response.Containers {
|
||||||
Expect(define.StringToContainerStatus(i.State)).
|
Expect(define.StringToContainerStatus(i.State)).
|
||||||
To(Equal(define.ContainerStateRunning))
|
To(Equal(define.ContainerStateRunning))
|
||||||
@ -219,8 +217,7 @@ var _ = Describe("Podman pods", func() {
|
|||||||
|
|
||||||
response, err := pods.Inspect(bt.conn, newpod)
|
response, err := pods.Inspect(bt.conn, newpod)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
// FIXME sujil please fix this
|
Expect(response.State).To(Equal(define.PodStateRunning))
|
||||||
//Expect(response.State.Status).To(Equal(define.PodStateRunning))
|
|
||||||
for _, i := range response.Containers {
|
for _, i := range response.Containers {
|
||||||
Expect(define.StringToContainerStatus(i.State)).
|
Expect(define.StringToContainerStatus(i.State)).
|
||||||
To(Equal(define.ContainerStateRunning))
|
To(Equal(define.ContainerStateRunning))
|
||||||
@ -234,8 +231,7 @@ var _ = Describe("Podman pods", func() {
|
|||||||
_, err = pods.Stop(bt.conn, newpod, nil)
|
_, err = pods.Stop(bt.conn, newpod, nil)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
response, _ = pods.Inspect(bt.conn, newpod)
|
response, _ = pods.Inspect(bt.conn, newpod)
|
||||||
// FIXME sujil please fix this
|
Expect(response.State).To(Equal(define.PodStateExited))
|
||||||
//Expect(response.State.Status).To(Equal(define.PodStateExited))
|
|
||||||
for _, i := range response.Containers {
|
for _, i := range response.Containers {
|
||||||
Expect(define.StringToContainerStatus(i.State)).
|
Expect(define.StringToContainerStatus(i.State)).
|
||||||
To(Equal(define.ContainerStateStopped))
|
To(Equal(define.ContainerStateStopped))
|
||||||
@ -248,8 +244,7 @@ var _ = Describe("Podman pods", func() {
|
|||||||
_, err = pods.Restart(bt.conn, newpod)
|
_, err = pods.Restart(bt.conn, newpod)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
response, _ = pods.Inspect(bt.conn, newpod)
|
response, _ = pods.Inspect(bt.conn, newpod)
|
||||||
// FIXME sujil please fix this
|
Expect(response.State).To(Equal(define.PodStateRunning))
|
||||||
//Expect(response.State.Status).To(Equal(define.PodStateRunning))
|
|
||||||
for _, i := range response.Containers {
|
for _, i := range response.Containers {
|
||||||
Expect(define.StringToContainerStatus(i.State)).
|
Expect(define.StringToContainerStatus(i.State)).
|
||||||
To(Equal(define.ContainerStateRunning))
|
To(Equal(define.ContainerStateRunning))
|
||||||
@ -277,15 +272,15 @@ var _ = Describe("Podman pods", func() {
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
response, err := pods.Inspect(bt.conn, newpod)
|
response, err := pods.Inspect(bt.conn, newpod)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
// FIXME sujil please fix this
|
Expect(response.State).To(Equal(define.PodStateExited))
|
||||||
//Expect(response.State.Status).To(Equal(define.PodStateExited))
|
|
||||||
pruneResponse, err = pods.Prune(bt.conn)
|
pruneResponse, err = pods.Prune(bt.conn)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
// Validate status and record pod id of pod to be pruned
|
// Validate status and record pod id of pod to be pruned
|
||||||
//Expect(response.State.Status).To(Equal(define.PodStateExited))
|
Expect(response.State).To(Equal(define.PodStateExited))
|
||||||
//podID := response.Config.ID
|
podID := response.ID
|
||||||
// Check if right pod was pruned
|
// Check if right pod was pruned
|
||||||
Expect(len(pruneResponse)).To(Equal(1))
|
Expect(len(pruneResponse)).To(Equal(1))
|
||||||
|
Expect(pruneResponse[0].Id).To(Equal(podID))
|
||||||
// One pod is pruned hence only one pod should be active.
|
// One pod is pruned hence only one pod should be active.
|
||||||
podSummary, err = pods.List(bt.conn, nil)
|
podSummary, err = pods.List(bt.conn, nil)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
@ -301,8 +296,7 @@ var _ = Describe("Podman pods", func() {
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
response, err = pods.Inspect(bt.conn, newpod)
|
response, err = pods.Inspect(bt.conn, newpod)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
// FIXME sujil please fix this
|
Expect(response.State).To(Equal(define.PodStateExited))
|
||||||
//Expect(response.State.Status).To(Equal(define.PodStateExited))
|
|
||||||
for _, i := range response.Containers {
|
for _, i := range response.Containers {
|
||||||
Expect(define.StringToContainerStatus(i.State)).
|
Expect(define.StringToContainerStatus(i.State)).
|
||||||
To(Equal(define.ContainerStateStopped))
|
To(Equal(define.ContainerStateStopped))
|
||||||
@ -311,8 +305,7 @@ var _ = Describe("Podman pods", func() {
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
response, err = pods.Inspect(bt.conn, newpod2)
|
response, err = pods.Inspect(bt.conn, newpod2)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
// FIXME sujil please fix this
|
Expect(response.State).To(Equal(define.PodStateExited))
|
||||||
//Expect(response.State.Status).To(Equal(define.PodStateExited))
|
|
||||||
for _, i := range response.Containers {
|
for _, i := range response.Containers {
|
||||||
Expect(define.StringToContainerStatus(i.State)).
|
Expect(define.StringToContainerStatus(i.State)).
|
||||||
To(Equal(define.ContainerStateStopped))
|
To(Equal(define.ContainerStateStopped))
|
||||||
|
Reference in New Issue
Block a user