jupyterhub / kubespawner

Kubernetes spawner for JupyterHub
https://jupyterhub-kubespawner.readthedocs.io
BSD 3-Clause "New" or "Revised" License
549 stars 305 forks source link

Invalid kube-config file error with _mock: True #609

Open fbaier-fn opened 2 years ago

fbaier-fn commented 2 years ago

Bug description

The mock mode comes in very handy for a variety of tests and used to be easily enabled by setting _mock to True. This behavior broke and we see a lot of errors suddenly in our tests relating the kubeconfig such as:

kubernetes_asyncio.config.config_exception.ConfigException: Invalid kube-config file. Expected key current-context in kube-config 

Something about mock test behavior changed from 2.0.1 to 3.0.0 so that we see the issues with kubernetes_asyncio not able to find the kube-config file. After looking further into this I think this roots in the change that in 2.0.1 we were not loading the config if in mock mode versus starting with 3.0.0 we do.

Particular https://github.com/jupyterhub/kubespawner/blob/main/kubespawner/spawner.py#L195-L200 should just happen when we are not in mock mode - but there it happens regardless. Can we move this in a if not _mock: block. Wdyt?

Relating PRs jupyterhub/kubespawner#563 jupyterhub/kubespawner#576

Expected behaviour

Kubespawner in mock mode should not try to load kube-config file.

Actual behaviour

Even in mock mode the config is attempted to be loaded and fails, breaking mock tests. I think this just hasn't been noted because tests we run here are done after we do set up k3s that does create a kube-config file with the proper context vs. in mocks we don't actually bring up a k3s cluster nor should we rely on that step run as a dependency imo.

How to reproduce

Try to run mocks without k3s being setup, particular https://github.com/jupyterhub/kubespawner/blob/main/.github/workflows/test.yaml#L77 with https://github.com/jupyterhub/action-k3s-helm/blob/main/action.yml#L118-L126

welcome[bot] commented 2 years ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

aberey commented 2 years ago

+1

This just broke all our tests when upgrading.