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

windows: Fixes following container log rotation #124444

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

claudiubelu
Copy link
Contributor

@claudiubelu claudiubelu commented Apr 22, 2024

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?

Fixed issue where following Windows container logs would prevent container log rotation.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. sig/windows Categorizes an issue or PR as relevant to SIG Windows. sig/testing Categorizes an issue or PR as relevant to SIG Testing. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. labels Apr 22, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: claudiubelu
Once this PR has been reviewed and has the lgtm label, please assign mrunalp for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@claudiubelu
Copy link
Contributor Author

/test pull-ci-kubernetes-unit-windows

@claudiubelu claudiubelu force-pushed the windows/fix-container-log-rotation branch 4 times, most recently from 085c9ed to 1571613 Compare April 22, 2024 16:18
@bart0sh
Copy link
Contributor

bart0sh commented Apr 23, 2024

/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 23, 2024
@bart0sh bart0sh moved this from Triage to Needs Reviewer in SIG Node PR Triage Apr 23, 2024
@SergeyKanzhelev SergeyKanzhelev moved this from Triage to PRs - Needs Reviewer in SIG Node CI/Test Board Apr 24, 2024
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
@claudiubelu claudiubelu force-pushed the windows/fix-container-log-rotation branch from 1571613 to 96f62df Compare May 1, 2024 16:10
@claudiubelu
Copy link
Contributor Author

All Windows unit tests passed btw. So, this fixed the issue.

@bart0sh
Copy link
Contributor

bart0sh commented May 10, 2024

/lgtm

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

LGTM label has been added.

Git tree hash: 6015586a00ce03d790ad84986d2408228bcf304e

@bart0sh
Copy link
Contributor

bart0sh commented May 10, 2024

/assign @mrunalp @derekwaynecarr @dchen1107
for approval

@bart0sh bart0sh moved this from Needs Reviewer to Needs Approver in SIG Node PR Triage May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. sig/windows Categorizes an issue or PR as relevant to SIG Windows. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
SIG Node CI/Test Board
PRs - Needs Reviewer
SIG Node PR Triage
Needs Approver
Status: No status
Development

Successfully merging this pull request may close these issues.

Windows: Container log rotation may fail if the container logs are followed
6 participants