-
Notifications
You must be signed in to change notification settings - Fork 5.1k
test: normalize newline handling in kubeadm YAML #22021
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
base: master
Are you sure you want to change the base?
test: normalize newline handling in kubeadm YAML #22021
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: bobsira 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 |
|
Hi @bobsira. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Can one of the admins verify this patch? |
|
/ok-to-test |
This comment has been minimized.
This comment has been minimized.
nirs
left a comment
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.
Lets understand why it fails first. I assume that the got string may have windows newlines in some cases, so if we normalize it the issue should be fixed.
| // normalizeNewlines converts CRLF -> LF and enforces a single trailing newline. | ||
| func normalizeNewlines(s string) string { | ||
| s = strings.ReplaceAll(s, "\r\n", "\n") | ||
| return strings.TrimRight(s, "\n") + "\n" |
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 don't think we need the last trim - mostly likely the issue is generating yaml using windows newlines (CR LF) when running in the github runner, and replacing "\r\n" with "\n" will fix the issue.
| if err != nil { | ||
| t.Fatalf("unable to read testdata: %v", err) | ||
| } | ||
| normalizedExpected := normalizeNewlines(string(expected)) |
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.
This comes from line 198:
expected, err := os.ReadFile(fmt.Sprintf("testdata/%s/%s.yaml", version, tc.name))
os.ReadFile() cannot change newlines, it will break code computing a checksum of the bytes. You can check it here:
https://cs.opensource.google/go/go/+/refs/tags/go1.25.4:src/os/file.go;l=867
So what we get in expected is the same on any OS, and we don't need to normalize it.
| t.Fatalf("unable to read testdata: %v", err) | ||
| } | ||
| normalizedExpected := normalizeNewlines(string(expected)) | ||
| normalizedGot := normalizeNewlines(string(got)) |
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.
This comes from line 188:
got, err := GenerateKubeadmYAML(cfg, cfg.Nodes[0], runtime)
This may generate windows newlines somehow. If this is the issue, replacing "\r\n" with "\n" will fix the issue.
You can verify this this is the issue by searching for "\r\n" before we compare and logging the result.
This comment has been minimized.
This comment has been minimized.
|
/ok-to-test |
This comment has been minimized.
This comment has been minimized.
|
kvm2 driver with docker runtime Times for minikube (PR 22021) start: 42.8s 39.2s 40.4s 40.4s 41.5s Times for minikube ingress: 15.7s 16.2s 16.2s 15.7s 15.7s docker driver with docker runtime Times for minikube ingress: 10.6s 10.6s 11.6s 11.6s 11.6s Times for minikube start: 22.0s 20.6s 19.4s 20.4s 23.1s docker driver with containerd runtime Times for minikube start: 18.5s 22.4s 18.3s 18.6s 22.5s Times for minikube ingress: 20.1s 20.1s 20.1s 20.1s 20.1s |
|
We’re applying a Git-only fix to stop newline inconsistencies in CI by adding a
This tells Git to:
This change is being tracked in this new PR -> #22026 |
This comment has been minimized.
This comment has been minimized.
|
Here are the number of top 10 failed tests in each environments with lowest flake rate.
Besides the following environments also have failed tests:
To see the flake rates of all tests by environment, click here. |
|
@bobsira: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
In the 54 tests I've listed at the end, all the tests are failing because the golden YAML and the generated YAML differ in invisible whitespace (almost certainly line endings) on Windows, not because the actual kubeadm config content is wrong. Also the tests run successfully when I run them locally on my windows machine but fail when running on GitHub action runner
The test failures appear as the snippet below
It appears that on GitHub Actions, on windows images, git commonly checks out text files with CRLF
(\r\n), while: generated YAML from Go uses LF(\n). Also we might have different comparison in tests, raw string differences, no normalization. This might be producing byte-level mismatches, leading to false negative failures in CI, despite correct behavior locally.I've added and applied a shared
normalizeNewlines()helper to ensure comparisons are based on actual content differencesThere are 54 tests in total that I aim to fix with this change:
kubeadm DNS tests (6)
kubeadm YAML tests (48)
For v1.34
For v1.33
For v1.32
For v1.31
For v1.30
For v1.29