-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Go] kubens not resolving file paths relative to config file #229
Comments
Preliminary investigation indicates the errors occurs when calling Line 61 in 401188f
So perhaps this actually is a bug for https://github.com/kubernetes/client-go/? |
Does the same kubeconfig file work with kubectl? My guess also would be that this is a client-go issue. That said I have never seen file paths in kubeconfig file. So I am not sure what you’re trying to do is valid. |
Yes, works fine with
|
Yeah I am suspecting client-go must have a knob for this. But I have not seen it. |
Opened an duplicate since experiencing the same issue, but question is why kubectl works in this case ? Does it use other GO libraries ? |
This was reported by couple more folks using mingw/msys2 systems (similar to git bash) in #233. I'm now trying to figure out if this reproduces outside these shells (natively on windows). @Skymirrh @eshepelyuk Is it possible you move these kubeconfig file + cert files to %USERPROFILE%.kube\ and run
I'm guessing because kubectl determines which kubeconfig files to parse itself, so it can save where it has read the file from. in our case, we do custom yaml parsing to prevent the node structure in the document, so we pass client-go library a "parsed YAML", and we need to investigate if I personally don't have any files referenced from my kubeconfig file so I don’t run into this, but I can see many others do have this. |
@ahmetb Well, what you suggested to use But I did run cmd.exe and executed kubens - and I received exactly the same error
|
May I ask everyone in this issue: Where do these manifests with relative file paths come from? Is it from a particular cloud-provider, or is it hand-crafted? (The result won't change anything, I’m just curious.) |
In my case - those configs are created by the scripts thaat are provided by our infrastructure engineers. I've looked into the script they gave and this config is created by pure
So, it seems this format is created by |
I'm not sure I understand the question, but if the question is "what happens if you run
Ow, I missed that during preliminary investigation. My bad, would have obviously been the primary suspect had I seen it!
"Hand-crafted" by replicating examples from the Kubernetes documentation itself, as already linked above. The setup process for the config file includes calls to You may note this interesting bit from the documentation:
|
Yeah the last bit’s certainly valuable. Now we need to go investigate how we can make kubectl use a particular base path when we use the |
I have taken a quick look at There actually is an example provided by Go client: var kubeconfig *string
if home := homeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
} |
It is ––except it double-reads the file. We already read it in-memory once for detailed YAML doc tree parsing, if we use that it’ll parse the file yet again. (Since we open the file for RW, it might cause issues e.g. on windows.) Furthermore we need to be able to work with multiple kubeconfig files, and it's likely we'll implement some of that logic ourselves. I’ll take a closer look later on. Thanks for flagging. |
Note: I am not an expert at all with
FYI, it seems |
FWIW, I use direnv to cleanly separate k8s configs between projects:
Here, using a relative path for the project config seems prudent: it's automatically correctly scoped and will not break when moving the project folder around. Continuing from there, storing certificates in the project folder, for instance, seems a natural choice, so |
Hi,
Just switched from bash version to Go version on a Windows environment (Git Bash).
It looks like
kubens
does not treat relative file paths in.kube/config
as relative to the config file, but rather as relative to current working directory:Current workaround is to use absolute file paths in config file by prefixing all paths with
C:\Users\USERNAME\.kube\
, but that kinda defeats the purpose of having a.kube
directory :DI did not have a chance to play with Go yet, but if nobody picks this up and I have some time this weekend, I'll have a try at it.
Thanks for the awesome work by the way! 👍
The text was updated successfully, but these errors were encountered: