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

Conversation

Iceber
Copy link
Contributor

@Iceber Iceber commented Mar 1, 2021

Signed-off-by: Iceber Gu wei.cai-nat@daocloud.io

What type of PR is this?

/kind bug

What this PR does / why we need it:

Finished time is always 1754-08-31T06:49:24.128654848+08:05 in the run and create states, because FinishedAt is -6795364578871345152

[root@iceber-3 ~]# crictl inspect 587444fc34ec9
{
  "status": {
    "id": "587444fc34ec9846c163d0c74bbf985ac73662817a89e16b7328b955a03ef902",
    "metadata": {
      "attempt": 6,
      "name": "dx-arch-stolon-sentinel"
    },
    "state": "CONTAINER_RUNNING",
    "createdAt": "2021-03-01T16:45:23.390180141+08:00",
    "startedAt": "2021-03-01T16:45:23.544299436+08:00",
    "finishedAt": "1754-08-31T06:49:24.128654848+08:05",
    "exitCode": 0,

Which issue(s) this PR fixes:

Special notes for your reviewer:

Fixed output in the running state:

[root@iceber-3 ~]# ./crictl inspect 587444fc34ec9
{
  "status": {
    "id": "587444fc34ec9846c163d0c74bbf985ac73662817a89e16b7328b955a03ef902",
    "metadata": {
      "attempt": 6,
      "name": "dx-arch-stolon-sentinel"
    },
    "state": "CONTAINER_RUNNING",
    "createdAt": "2021-03-01T16:45:23.390180141+08:00",
    "startedAt": "2021-03-01T16:45:23.544299436+08:00",
    "finishedAt": "0001-01-01T00:00:00Z",
    "exitCode": 0,

Does this PR introduce a user-facing change?

Fixed `StartedAt` and `FinishedAt` of the container status

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 1, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @Iceber!

It looks like this is your first PR to kubernetes-sigs/cri-tools 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cri-tools has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 1, 2021
@Iceber Iceber force-pushed the fix-finished-at branch from 47df01e to 75ea797 Compare March 1, 2021 14:14
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 1, 2021
@Iceber Iceber changed the title fix FinishedAt of the container status fix StartedAt and FinishedAt of the container status Mar 1, 2021
cmd/crictl/container.go Outdated Show resolved Hide resolved
Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which container runtime did you use for the tests? I did a local test with CRI-O (master) and the resulting dates for a created container were:

"startedAt": "1970-01-01T01:00:00+01:00",
"finishedAt": "1970-01-01T01:00:00+01:00",

I think we're good to move forward with that change. We could say that it's a breaking change but I would not expect someone to rely on the date parsing output if the container state does not match.

@Iceber
Copy link
Contributor Author

Iceber commented Mar 2, 2021

Which container runtime did you use for the tests? I did a local test with CRI-O (master) and the resulting dates for a created container were:

"startedAt": "1970-01-01T01:00:00+01:00",
"finishedAt": "1970-01-01T01:00:00+01:00",

I think we're good to move forward with that change. We could say that it's a breaking change but I would not expect someone to rely on the date parsing output if the container state does not match.

I did the tests with the dockershim.
You get the 1970-01-01T01:00:00+01:00 because the started and finished timestamp is 0 (zero value)

https://github.com/cri-o/cri-o/blob/6ee8d68771c24a045aef1f5372eae377928a3530/server/container_status.go#L68-L84

The dockershim is use time.Time{}.UnixNano()(-6795364578871345152) as the default timestamp
You can take a look at kubernetes/kubernetes#99585

You can use --debug to see the returned data

@Iceber
Copy link
Contributor Author

Iceber commented Mar 2, 2021

And kubernetes sometimes ignores startedAt and finishedAt when dealing with CRI container status, as seen here

I'm thinking about whether to show "" or 0001-01-01T00:00:00Z(time.Time{}.Format(time.RFC3339Nano)) for empty startedAt and finishedAt
0001-01-01T00:00:00Z has the advantage that it can be parsed by time.Parse without returning errors. And result.IsZero() is true

@Iceber Iceber force-pushed the fix-finished-at branch from 75ea797 to ae908a4 Compare March 2, 2021 16:28
@Iceber Iceber requested a review from saschagrunert March 2, 2021 16:29
@saschagrunert
Copy link
Member

saschagrunert commented Mar 2, 2021

I'm thinking about whether to show "" or 0001-01-01T00:00:00Z(time.Time{}.Format(time.RFC3339Nano)) for empty startedAt and finishedAt
0001-01-01T00:00:00Z has the advantage that it can be parsed by time.Parse without returning errors. And result.IsZero() is true

In that case it would't be a "breaking change". I like that. 👍

@Iceber Iceber force-pushed the fix-finished-at branch from ae908a4 to 838175b Compare March 3, 2021 02:19
@Iceber
Copy link
Contributor Author

Iceber commented Mar 3, 2021

@saschagrunert update to show 0001-01-01T00:00:00Z.
PTAL, Thanks

Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/hold for the tests

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 3, 2021
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 3, 2021
@saschagrunert
Copy link
Member

/hold cancel

the CI failures are not related to this change, I'll follow-up on those.

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 3, 2021
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
@Iceber Iceber force-pushed the fix-finished-at branch from 838175b to 791ddab Compare March 4, 2021 09:32
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 4, 2021
Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 4, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Iceber, saschagrunert

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit b28b61b into kubernetes-sigs:master Mar 4, 2021
@Iceber Iceber deleted the fix-finished-at branch March 4, 2021 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants