Error loading config file
See original GitHub issueProblem
The extension is spewing out the following error (appears to be around once every minute):
error: Error loading config file "/home/d4nyll/.kube/config": read /home/d4nyll/.kube/config: is a directory
It is throwing the error because /home/d4nyll/.kube/config
is a directory, and not a configuration file. However, this should not be an error because Kubernetes allows the configuration files to be split into multiple files. Indeed, from the documentation:
The
KUBECONFIG
environment variable is a list of paths to configuration files. The list is colon-delimited for Linux and Mac, and semicolon-delimited for Windows.
I have set up my KUBECONFIG
environment variable to be a colon-separated list.
$ echo $KUBECONFIG | tr ':' '\n'
/home/d4nyll/.kube/config/k8s-dev
/home/d4nyll/.kube/config/k8s-admin
/home/d4nyll/.kube/config/minikube
/home/d4nyll/.kube/config/do-lon1-ghost
/home/d4nyll/.kube/config/do-lon1-bud
$ node
Welcome to Node.js v12.5.0.
> console.log(process.env.KUBECONFIG.replace(/:/g, "\n"));
/home/d4nyll/.kube/config/k8s-dev
/home/d4nyll/.kube/config/k8s-admin
/home/d4nyll/.kube/config/minikube
/home/d4nyll/.kube/config/do-lon1-ghost
/home/d4nyll/.kube/config/do-lon1-bud
Solution
- Check
process.env.KUBECONFIG
before using the default of$HOME/.kube/config
- Merge the configuration files together
Proposal
N.B. I haven’t read the entire codebase in detail, so this may be the wrong place to implement it. Advice welcomed.
Right now, the configuration is first read from the workspace configuration.
export function getActiveKubeconfig(): string {
return vscode.workspace.getConfiguration(EXTENSION_CONFIG_KEY)[KUBECONFIG_PATH_KEY];
}
If this is not found, then it will try to read from a default path
function getDefaultKubeconfig(): string {
return path.join((process.env['HOME'] || process.env['USERPROFILE'] || '.'), ".kube", "config");
}
I propose to add an additional check to kubeconfigPath()
to also check the environment variable KUBECONFIG
and read and merge all those files together as one before passing the configuration object to downstream functions.
function kubeconfigPath(): string {
return getActiveKubeconfig() || getEnvKubeConfig() || getDefaultKubeconfig();
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:14
Top GitHub Comments
Yes,
loadFromDefault
probably makes more sense (unless the user has set a non-default kubeconfig in their VS Code settings). And I should dig into that to see how it handles the multi-file case so we can support that in the settings override case. Thanks!I’m travelling at the moment, but will hopefully get to this in a couple of weeks when I get back. Sorry for the delay, and thanks for all the digging.
Oh no! Thank you for closing the loop on this one - I’m almost disappointed that it turned out to be a configuration error at your end - it would have been a very satisfying bug to fix! But having it working for you is the most important thing!