zalando-incubator / kopf

A Python framework to write Kubernetes operators in just few lines of code.
https://kopf.readthedocs.io
MIT License
969 stars 89 forks source link

Minikube with Env KUBECONFIG (different filename) fails to load (no default context) #354

Open styk-tv opened 4 years ago

styk-tv commented 4 years ago

Normally this is not an issue. Everything defaults to ./kube/config and works fine. But what if your configfile is under a different filename? You would set KUBECONFIG environment variable to something like ".kube/config.mini" and kubectl works fine.

However, by default minikube has no default context set. Kubectl is able to deal with this fine, however pykube insist default config to be set.

Minikube produces:

current-context: ""

from piggybacking.py

Screenshot 2020-04-28 at 13 25 56

results with

Screenshot 2020-04-28 at 13 26 38

Maybe this is not an issue of kopf but pykube but I couldn't find the fork. If config file has no default current-context set and if there is only one context in the config file, default behaviour should be to load that context yes?

so this is when using

@kopf.on.login()
def login_fn(**kwargs):
    return kopf.login_via_pykube(**kwargs)

when using just default login, the KUBECONFIG variable is NOT considered at all, i don't really care for pykube much if i could just specify a custom filename for KUBECONFIG

This can be easily fixed by just setting default context right, but fix should live in the code i guess is my point.

I hope this can be useful to someone.

Cheers.