Open WolfByttner opened 3 years ago
After some debugging I found the cause of the problem. The offending line is 112
in kubeprod/cmd/install.go
.
If I hardcode the string value, the program loads the file just fine.
c.PlatformConfigPath = "C:/Users/wolfb/test/my-kubeprod-autogen.json" //platformConfigURL.Path
Looking in the debugger, c.PlatformConfigPath
takes the value /C:/Users/wolfb/test/my-kubeprod-autogen.json
- the leading slash breaks the Windows path recognition.
I understand the intention here, but I doubt that the assumption that file paths are URLs is universally valid. This problem looks similar to a core language issue that was identified (#https://github.com/golang/go/issues/13276).
I found a silly workaround. If on windows, strip the first character. This likely works if the user has specified the full file path, since Go cannot resolve the scheme without the file://
prefix (see #https://github.com/golang/go/issues/13276). Thus the user will likely have a leading slash, that has to be removed.
if platformConfigURL.Scheme != "file" {
return nil, fmt.Errorf("platform config path must be a file:// URL")
}
c.PlatformConfigPath = platformConfigURL.Path
if runtime.GOOS == "windows" {
c.PlatformConfigPath = c.PlatformConfigPath[1:]
}
However, I'd struggle to call this an optimal solution. Have we hit on a deeper assumption here - one that is ultimately not correct? And how can we go about resolving this issue in the codebase?
There is an additional downstream error with kubeprod-manifest.jsonnet
. This time the URL is used directly with undesirable results.
Updating platform gke
Error: Could not get candidate URLs for when importing file://C:%5CUsers%5Cwolfb%5Cgit%5Ckube-prod-runtime/kubeprod-manifest.jsonnet (imported from file://C:%5CUsers%5Cwolfb%5Cgit%5Ckube-prod-runtime/): Import path "file://C:%5CUsers%5Cwolfb%5Cgit%5Ckube-prod-runtime/kubeprod-manifest.jsonnet" is not valid
The root cause here (after applying our URL slicing) is that backslashes get encoded into %5C
rather than a more helpful forward slash.
On a positive note - the previous solution works whether one specifies a config explicitly or not. The file name does look strange (C:\\Users\\wolfb\\git\\test/kubeprod-autogen.json
) but the os module resolves the filename correctly.
Kubeprod will not correctly resolve the path to
kubeprod-autogen.json
. When I try, I get various strange error messages or weird file paths. I have attempted all file format paths that I can think of (see below for outputs).System Info
Steps to reproduce
Test script:
Let us start with no --config flag. You get the following output.
With git bash's way of writing things;
"/c/Users/wolfb/test/my-manifest-file.json"
; you instead get the error:With the (canonical) filepath
"C:\\Users\\wolfb\\test\\my-kubeprod-autogen.json"
you get the same error again:The path
"file:///C:/Users/wolfb/test/my-kubeprod-autogen.json"
can be visited in a browser. It seems like kubeprod expects this format.Removing the colon,
"file:///C:/Users/wolfb/test/my-kubeprod-autogen.json"
:Removing one of the slashes (your web browser will add a slash when you paste the link) we get:
With lowercase "c" (a Hail Mary approach)
"file//c:/Users/wolfb/test/my-kubeprod-autogen.json"
we get:Debugging
I am working on a test script, however I have yet to find the root cause of the issue: Below is a work in progress:
We get the following output:
You can see how go successfully converts the file to a URL and back to a legible string. However, at some point after that, the string is mangled beyond recognition.