mirror of
https://github.com/containers/podman.git
synced 2025-05-20 08:36:23 +08:00
Add Checkpointed bool to Inspect
When inspecting a container, we now report whether the container was stopped by a `podman checkpoint` operation via a new bool in the State portion of inspected, `Checkpointed`. Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
@ -159,6 +159,9 @@ type ContainerState struct {
|
||||
// OOMKilled indicates that the container was killed as it ran out of
|
||||
// memory
|
||||
OOMKilled bool `json:"oomKilled,omitempty"`
|
||||
// Checkpointed indicates that the container was stopped by a checkpoint
|
||||
// operation.
|
||||
Checkpointed bool `json:"checkpointed,omitempty"`
|
||||
// PID is the PID of a running container
|
||||
PID int `json:"pid,omitempty"`
|
||||
// ConmonPID is the PID of the container's conmon
|
||||
|
@ -103,18 +103,19 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver
|
||||
Path: path,
|
||||
Args: args,
|
||||
State: &define.InspectContainerState{
|
||||
OciVersion: ctrSpec.Version,
|
||||
Status: runtimeInfo.State.String(),
|
||||
Running: runtimeInfo.State == define.ContainerStateRunning,
|
||||
Paused: runtimeInfo.State == define.ContainerStatePaused,
|
||||
OOMKilled: runtimeInfo.OOMKilled,
|
||||
Dead: runtimeInfo.State.String() == "bad state",
|
||||
Pid: runtimeInfo.PID,
|
||||
ConmonPid: runtimeInfo.ConmonPID,
|
||||
ExitCode: runtimeInfo.ExitCode,
|
||||
Error: "", // can't get yet
|
||||
StartedAt: runtimeInfo.StartedTime,
|
||||
FinishedAt: runtimeInfo.FinishedTime,
|
||||
OciVersion: ctrSpec.Version,
|
||||
Status: runtimeInfo.State.String(),
|
||||
Running: runtimeInfo.State == define.ContainerStateRunning,
|
||||
Paused: runtimeInfo.State == define.ContainerStatePaused,
|
||||
OOMKilled: runtimeInfo.OOMKilled,
|
||||
Dead: runtimeInfo.State.String() == "bad state",
|
||||
Pid: runtimeInfo.PID,
|
||||
ConmonPid: runtimeInfo.ConmonPID,
|
||||
ExitCode: runtimeInfo.ExitCode,
|
||||
Error: "", // can't get yet
|
||||
StartedAt: runtimeInfo.StartedTime,
|
||||
FinishedAt: runtimeInfo.FinishedTime,
|
||||
Checkpointed: runtimeInfo.Checkpointed,
|
||||
},
|
||||
Image: config.RootfsImageID,
|
||||
ImageName: config.RootfsImageName,
|
||||
|
@ -584,6 +584,7 @@ func resetState(state *ContainerState) {
|
||||
state.StoppedByUser = false
|
||||
state.RestartPolicyMatch = false
|
||||
state.RestartCount = 0
|
||||
state.Checkpointed = false
|
||||
}
|
||||
|
||||
// Refresh refreshes the container's state after a restart.
|
||||
@ -1110,6 +1111,7 @@ func (c *Container) init(ctx context.Context, retainRetries bool) error {
|
||||
c.state.ExecSessions = make(map[string]*ExecSession)
|
||||
}
|
||||
|
||||
c.state.Checkpointed = false
|
||||
c.state.ExitCode = 0
|
||||
c.state.Exited = false
|
||||
c.state.State = define.ContainerStateCreated
|
||||
|
@ -1146,6 +1146,7 @@ func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointO
|
||||
|
||||
if !options.KeepRunning && !options.PreCheckPoint {
|
||||
c.state.State = define.ContainerStateStopped
|
||||
c.state.Checkpointed = true
|
||||
|
||||
// Cleanup Storage and Network
|
||||
if err := c.cleanup(ctx); err != nil {
|
||||
|
@ -189,20 +189,21 @@ type InspectMount struct {
|
||||
// Docker, but here we see more fields that are unused (nonsensical in the
|
||||
// context of Libpod).
|
||||
type InspectContainerState struct {
|
||||
OciVersion string `json:"OciVersion"`
|
||||
Status string `json:"Status"`
|
||||
Running bool `json:"Running"`
|
||||
Paused bool `json:"Paused"`
|
||||
Restarting bool `json:"Restarting"` // TODO
|
||||
OOMKilled bool `json:"OOMKilled"`
|
||||
Dead bool `json:"Dead"`
|
||||
Pid int `json:"Pid"`
|
||||
ConmonPid int `json:"ConmonPid,omitempty"`
|
||||
ExitCode int32 `json:"ExitCode"`
|
||||
Error string `json:"Error"` // TODO
|
||||
StartedAt time.Time `json:"StartedAt"`
|
||||
FinishedAt time.Time `json:"FinishedAt"`
|
||||
Healthcheck HealthCheckResults `json:"Healthcheck,omitempty"`
|
||||
OciVersion string `json:"OciVersion"`
|
||||
Status string `json:"Status"`
|
||||
Running bool `json:"Running"`
|
||||
Paused bool `json:"Paused"`
|
||||
Restarting bool `json:"Restarting"` // TODO
|
||||
OOMKilled bool `json:"OOMKilled"`
|
||||
Dead bool `json:"Dead"`
|
||||
Pid int `json:"Pid"`
|
||||
ConmonPid int `json:"ConmonPid,omitempty"`
|
||||
ExitCode int32 `json:"ExitCode"`
|
||||
Error string `json:"Error"` // TODO
|
||||
StartedAt time.Time `json:"StartedAt"`
|
||||
FinishedAt time.Time `json:"FinishedAt"`
|
||||
Healthcheck HealthCheckResults `json:"Healthcheck,omitempty"`
|
||||
Checkpointed bool `json:"Checkpointed,omitempty"`
|
||||
}
|
||||
|
||||
// HealthCheckResults describes the results/logs from a healthcheck
|
||||
|
@ -93,6 +93,12 @@ var _ = Describe("Podman checkpoint", func() {
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
||||
Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited"))
|
||||
|
||||
inspect := podmanTest.Podman([]string{"inspect", cid})
|
||||
inspect.WaitWithDefaultTimeout()
|
||||
Expect(inspect).Should(Exit(0))
|
||||
inspectOut := inspect.InspectContainerToJSON()
|
||||
Expect(inspectOut[0].State.Checkpointed).To(BeTrue())
|
||||
|
||||
result = podmanTest.Podman([]string{"container", "restore", cid})
|
||||
result.WaitWithDefaultTimeout()
|
||||
|
||||
|
Reference in New Issue
Block a user