Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/minikube/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ func configIssues(cfg *api.Config, contextName string, address string) []error {

// populateCerts retains certs already defined in kubeconfig or sets default ones for those missing.
func populateCerts(kcs *Settings, cfg api.Config, contextName string) {
lp := localpath.Profile(contextName)
gp := localpath.MiniPath()
gp := filepath.ToSlash(localpath.MiniPath())
Copy link
Member

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 ?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

lp := filepath.ToSlash(localpath.Profile(contextName))

kcs.CertificateAuthority = path.Join(gp, "ca.crt")
if cluster, ok := cfg.Clusters[contextName]; ok {
Expand Down
Loading