AvitalTamir / cyphernetes

A Kubernetes Query Language
https://cyphernet.es
MIT License
294 stars 4 forks source link

Respect `$KUBECONFIG` #93

Open codekoala opened 2 hours ago

codekoala commented 2 hours ago

I had a very difficult time getting this tool to work. I kept getting this sort of error:

Error creating QueryExecutor instance: failed to create config: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x30 pc=0x10563f870]

goroutine 1 [running]:
main.getCurrentContextFromConfig()
        /Users/josh/dev/go/pkg/mod/github.com/avitaltamir/cyphernetes@v0.11.2/cmd/cyphernetes/shell.go:88 +0x200
main.getCurrentContext(...)
        /Users/josh/dev/go/pkg/mod/github.com/avitaltamir/cyphernetes@v0.11.2/cmd/cyphernetes/shell.go:73
main.init.3()
        /Users/josh/dev/go/pkg/mod/github.com/avitaltamir/cyphernetes@v0.11.2/cmd/cyphernetes/shell.go:567 +0x248

Based on the error message, I manually exported KUBERNETES_MASTER to my cluster's API server, but I continued to get errors.

Eventually I checked the contents of my ~/.kube/config file, and it was "emtpy":

apiVersion: v1
clusters: null
contexts: null
current-context: ""
kind: Config
preferences: {}
users: null

This is because I use a different file for each cluster that I'm interested in connecting to and set $KUBECONFIG to the appropriate path. It pairs well with direnv, automatically changing the context based on the project I'm working on. I have taken for granted the fact that most Kubernetes tooling respects the $KUBECONFIG environment variable.

In order to actually use cyphernetes, I symlinked my config file:

ln -sf $KUBECONFIG ~/.kube/config

After doing this, I was finally able to use the tool! It seems very cool.

I think it would be useful to check that environment variable in case others use k8s tooling the same way I do.

AvitalTamir commented 2 hours ago

@codekoala thanks for reporting! Will add this.