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
windows: Fixes following container log rotation #124444
base: master
Are you sure you want to change the base?
windows: Fixes following container log rotation #124444
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: claudiubelu The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/test pull-ci-kubernetes-unit-windows |
085c9ed
to
1571613
Compare
/triage accepted |
If we're following a file, that file will remain open, and we continue to read data from it when new data becomes available. On Windows, this can be an issue if the container logs needs to be rotated. Log rotation is done by renaming the file, but this action may fail if the file is already opened. Setting the FILE_SHARE_DELETE flag when opening the file will prevent this issue, as documented: "Delete access allows both delete and rename operations" [1]. In golang, there's no way to set this flag [2], the sharemode is always set to: sharemode := uint32(FILE_SHARE_READ | FILE_SHARE_WRITE) Thus, we need to open the file ourselves with the right flags. [1] https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea?redirectedfrom=MSDN [2] https://cs.opensource.google/go/go/+/refs/tags/go1.22.2:src/syscall/syscall_windows.go;l=366
1571613
to
96f62df
Compare
All Windows unit tests passed btw. So, this fixed the issue. |
/lgtm |
LGTM label has been added. Git tree hash: 6015586a00ce03d790ad84986d2408228bcf304e
|
/assign @mrunalp @derekwaynecarr @dchen1107 |
What type of PR is this?
/kind bug
/kind failing-test
/sig windows
/sig testing
What this PR does / why we need it:
If we're following a file, that file will remain open, and we continue to read data from it when new data becomes available.
On Windows, this can be an issue if the container logs needs to be rotated. Log rotation is done by renaming the file, but this action may fail if the file is already opened.
Setting the
FILE_SHARE_DELETE
flag when opening the file will prevent this issue, as documented:"Delete access allows both delete and rename operations"
[1].In golang, there's no way to set this flag [2], the
sharemode
is always set to:sharemode := uint32(FILE_SHARE_READ | FILE_SHARE_WRITE)
Thus, we need to open the file ourselves with the right flags.
[1] https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea?redirectedfrom=MSDN
[2] https://cs.opensource.google/go/go/+/refs/tags/go1.22.2:src/syscall/syscall_windows.go;l=366
Which issue(s) this PR fixes:
Fixes #124443
Related: #51540
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: