Skip to content

Commit

Permalink
Merge pull request containers#11471 from mheon/checkpointed
Browse files Browse the repository at this point in the history
Add Checkpointed bool to Inspect
  • Loading branch information
openshift-merge-robot authored Sep 8, 2021
2 parents 598d914 + bfcd83e commit ae0a9c6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 26 deletions.
3 changes: 3 additions & 0 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 13 additions & 12 deletions libpod/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 15 additions & 14 deletions libpod/define/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit ae0a9c6

Please sign in to comment.