Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix StartedAt and FinishedAt of the container status #724

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions cmd/crictl/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,22 @@ func marshalContainerStatus(cs *pb.ContainerStatus) (string, error) {
if err != nil {
return "", err
}

jsonMap["createdAt"] = time.Unix(0, cs.CreatedAt).Format(time.RFC3339Nano)
jsonMap["startedAt"] = time.Unix(0, cs.StartedAt).Format(time.RFC3339Nano)
jsonMap["finishedAt"] = time.Unix(0, cs.FinishedAt).Format(time.RFC3339Nano)
var startedAt, finishedAt time.Time
if cs.State != pb.ContainerState_CONTAINER_CREATED {
// If container is not in the created state, we have tried and
// started the container. Set the startedAt.
startedAt = time.Unix(0, cs.StartedAt)
}
if cs.State == pb.ContainerState_CONTAINER_EXITED ||
(cs.State == pb.ContainerState_CONTAINER_UNKNOWN && cs.FinishedAt > 0) {
// If container is in the exit state, set the finishedAt.
// Or if container is in the unknown state and FinishedAt > 0, set the finishedAt
finishedAt = time.Unix(0, cs.FinishedAt)
}
jsonMap["startedAt"] = startedAt.Format(time.RFC3339Nano)
jsonMap["finishedAt"] = finishedAt.Format(time.RFC3339Nano)
return marshalMapInOrder(jsonMap, *cs)
}

Expand Down