-
Notifications
You must be signed in to change notification settings - Fork 5.1k
kubeconfig: normalize generated cert paths to forward slashes #21845
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?
kubeconfig: normalize generated cert paths to forward slashes #21845
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? |
| func populateCerts(kcs *Settings, cfg api.Config, contextName string) { | ||
| lp := localpath.Profile(contextName) | ||
| gp := localpath.MiniPath() | ||
| gp := filepath.ToSlash(localpath.MiniPath()) |
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.
@bobsira I am curious have you explored or investigated that if we can just add filepath.ToSlash to the "localpath" funcs ? would that break anything ?
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 have no exlopred this but I believe adding filepath.ToSlash inside the localpath functions would introduce new mixed‑separator paths elsewhere and could re‑break the kubeconfig tests.
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 prever we do it inside MiniPath, so in the future if we have to add more things for windows we dont forget to use ToSLash
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.
@medyagh I've done a bit of investigation and testing and I'd recommend we don't move this to MiniPath()
MiniPath() is a general internal path constructor used widely; forcing filepath.ToSlash there would globally change separator style and risk mixed // when other callers use filepath.Join, creating new inconsistencies.
The test failure concerns kubeconfig serialization and comparison of cert/key/CA paths; that boundary is exactly where a stable, cross‑platform representation is needed.
Normalizing in populateCerts targets only the kubeconfig fields being written or reused, fixing the test without widening blast radius or altering unrelated path consumers.
Keeping MiniPath() native preserves expected OS behavior for file operations; applying ToSlash only at serialization avoids regressions while delivering the needed consistent text form for comparisons.
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.
Since we already have filepath.Clean fix in MiniPath in one of our PRs, I did a bit of investigation on the differences between Clean and ToSlash
filepath.Clean(path):
- Removes redundant elements: . segments, collapses multiple separators, resolves .. where possible (without following symlinks).
- Eliminates trailing slash (except root).
- Preserves OS-native separator (\ on Windows, / on Unix).
- Returns "." for empty string.
filepath.ToSlash(path):
- Pure separator translation: replaces every OS-native separator (\ on Windows) with /.
- Does NOT remove . or .., does NOT collapse duplicate separators, does NOT trim trailing slashes.
- Leaves drive letters intact (C:\a\b → C:/a/b), does not touch UNC prefix beyond separator change.
Examples
Windows input: C:\foo\bar\..\baz\
- Clean → C:\foo\baz
- ToSlash → C:/foo/bar/../baz/
- ToSlash(Clean(...)) → C:/foo/baz
Unix input: /foo//bar/./../baz/
- Clean → /foo/baz
- ToSlash → /foo//bar/./../baz/ (unchanged except redundant slashes remain)
- ToSlash(Clean(...)) → /foo/baz
Use Cases
- Use Clean when you need a canonical, shortest equivalent path under OS rules.
- Use ToSlash when you need uniform forward slashes for serialization, logging, config files, or cross-platform string comparison.
- Combine: filepath.ToSlash(filepath.Clean(p)) for canonical + portable.
Edge Notes
- Clean will not resolve symlinks or verify existence.
- ToSlash is safe on already-forward-slash paths (no-op on Unix).
- Ordering matters: do Clean first, then ToSlash; reversing can leave redundant pieces.
Summary
- Clean normalizes structural path syntax; ToSlash normalizes only separator characters. They solve different problems and are complementary, not interchangeable.
| func populateCerts(kcs *Settings, cfg api.Config, contextName string) { | ||
| lp := localpath.Profile(contextName) | ||
| gp := localpath.MiniPath() | ||
| gp := filepath.ToSlash(localpath.MiniPath()) |
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 prever we do it inside MiniPath, so in the future if we have to add more things for windows we dont forget to use ToSLash
This PR normalizes generated kubeconfig certificate paths by converting any Windows backslashes to forward slashes when building new entries in
populateCerts (kubeconfig.go). Prior logic mixedfilepath.Join(producing \ on Windows) withpath.Join(always /), creating hybrid paths like\home\user\.minikube\profiles\minikube/client.crt. The tests (TestUpdateIPandTestMissingContext) compare kubeconfig objects via raw string equality (configEquals), so those mixed separators caused mismatches only on Windows.It Fixes These Two Tests:
TestUpdateIP: When adding or updating the minikube cluster/user entries, normalized paths now match the forward‑slash fixtures (kubeConfigWithoutHTTPSUpdated, etc.), eliminating false diffs.TestMissingContext: Rewriting the missing context also regenerates cluster/user entries; normalized paths prevent separator differences from triggering a failure.Scope:
minikube/pkg/minikube/kubeconfig/kubeconfig_test.go
Line 399 in 87ccec3
minikube/pkg/minikube/kubeconfig/kubeconfig_test.go
Line 494 in 87ccec3