-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
CRI: Stop following container log when container exited. #44406
CRI: Stop following container log when container exited. #44406
Conversation
if err != nil { | ||
return err | ||
} | ||
// Only keep following container log when it is running. There may be a race condition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the container is not running, we can't tail it anyway. Do we need to care about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we'd only reach this function if the container is running...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK. I tried with docker. docker logs -f
will also return immediately if the container is in created state.
If so, I think we could also return here, we just shouldn't throw out the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// stateCheckPeriod here, it should be rare. | ||
// Even when that happen, user could also retry after the container becomes running. | ||
if s.State != runtimeapi.ContainerState_CONTAINER_RUNNING { | ||
return fmt.Errorf("container %q is not running (state=%q)", id, s.State) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think we need the error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I need to introduce another error to tell waitLogs
not to continue parse log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -196,6 +204,40 @@ func ReadLogs(path string, apiOpts *v1.PodLogOptions, stdout, stderr io.Writer) | |||
} | |||
} | |||
|
|||
// waitLogs wait for the next log write. If the container is not running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this sentence complete? If the container is not running
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, must be distracted by something else at that time...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Can't we continue to tail the logs even if container exited? The log file should be just there, right? |
@mrunalp We can still tail the log of exited container. However, we should not keep waiting for new lines after reading all the logs in following mode, because the container has exited already. |
The behaviour prior to 1.6.0 was to stop following logs as soon as the container exited. With an exit code of 0, at least when a container terminated successfully. I used it to tail containers started by a job until successful completion. |
80a8f75
to
2fbf34f
Compare
@yujuhong Updated the PR and get rid of the error.
|
/lgtm @Random-Liu could you add a release-note so that we can patch 1.6 later. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Random-Liu, yujuhong
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
@k8s-bot gce etcd3 e2e test this |
Automatic merge from submit-queue |
…4406-upstream-release-1.6 Automatic merge from submit-queue Automated cherry pick of #44406 upstream release 1.6 Cherry pick of #44406 on release-1.6. #44406: CRI: Stop following container log when container exited. @enisoc **Release note**: ```release-note `kubectl logs -f` now stops following when container stops. ```
Commit found in the "release-1.6" branch appears to be this PR. Removing the "cherrypick-candidate" label. If this is an error find help to get your PR picked. |
Fixes #44340.
This PR changed kubelet to periodically check whether container is running when following container logs, and stop following when container exited.
I've tried this PR in my local cluster:
The only difference is that
ReadLogs
will return error when container exits during following. I'm not sure whether we should get rid of it or not.@yujuhong @feiskyer @JorritSalverda
/cc @kubernetes/sig-node-bugs
Release note: