jupyterhub / kubespawner

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

KubeIngressProxy NoneType exception while expand hub route labels #723

Closed ealyn closed 1 year ago

ealyn commented 1 year ago

Bug description

I can not startup z2jh with KubeIngressProxy(4.3.0), the hub pod is CrashLoopBackOff, and got these log:

[I 2023-04-23 09:24:38.866 JupyterHub proxy:477] Adding route for Hub: /jupyterhub/ => http://hub:8081
[W 2023-04-23 09:24:38.866 JupyterHub proxy:468] Deleting stale route /
[I 2023-04-23 09:24:38.866 JupyterHub reflector:274] watching for ingresses with label selector='component=singleuser-server,hub.jupyter.org/proxy-route=true' in namespace jupyterhub
[E 2023-04-23 09:24:38.872 JupyterHub app:3377]
    Traceback (most recent call last):
      File "/usr/local/lib/python3.9/site-packages/jupyterhub/app.py", line 3375, in launch_instance_async
        await self.start()
      File "/usr/local/lib/python3.9/site-packages/jupyterhub/app.py", line 3222, in start
        await self.proxy.check_routes(self.users, self._service_map)
      File "/usr/local/lib/python3.9/site-packages/jupyterhub/proxy.py", line 72, in locked_method
        return await method(*args, **kwargs)
      File "/usr/local/lib/python3.9/site-packages/jupyterhub/proxy.py", line 471, in check_routes
        await asyncio.gather(*futures)
      File "/usr/local/lib/python3.9/site-packages/kubespawner/proxy.py", line 320, in add_route
        common_labels = self._expand_all(self.common_labels, routespec, data)
      File "/usr/local/lib/python3.9/site-packages/kubespawner/proxy.py", line 299, in _expand_all
        return {k: self._expand_all(v, routespec, data) for k, v in src.items()}
      File "/usr/local/lib/python3.9/site-packages/kubespawner/proxy.py", line 299, in <dictcomp>
        return {k: self._expand_all(v, routespec, data) for k, v in src.items()}
      File "/usr/local/lib/python3.9/site-packages/kubespawner/proxy.py", line 301, in _expand_all
        return self._expand_user_properties(src, routespec, data)
      File "/usr/local/lib/python3.9/site-packages/kubespawner/proxy.py", line 268, in _expand_user_properties
        safe_username = escapism.escape(
      File "/usr/local/lib/python3.9/site-packages/escapism.py", line 81, in escape
        for c in to_escape:
    TypeError: 'NoneType' object is not iterable

Expected behaviour

Actual behaviour

It seems that hub route data is {"hub": true}, but function KubeIngressProxy:_expand_user_properties try to get user from it.

How to reproduce

Just set c.JupyterHub.proxy_class = "kubespawner.proxy.KubeIngressProxy" and then helm install jupyterhub.

Your personal set up

Full environment ``` # paste output of `pip freeze` or `conda list` here ```
Configuration ```python # jupyterhub_config.py ```
Logs ``` # paste relevant logs here, if any ```
consideRatio commented 1 year ago

Check if you reproduce this using the main branch, we have quite a few changes since last release i think.

KubeIngressProxy isn't something we have capacity to maintain well :/

ealyn commented 1 year ago

Check if you reproduce this using the main branch, we have quite a few changes since last release i think.

KubeIngressProxy isn't something we have capacity to maintain well :/

Related code that add_route calling _expand_user_properties are same between 4.3.0 and main. I know KubeIngressProxy is not the focus, but I prefer ingress-nginx than CHP. After solved some little problems, KubeIngressProxy 1.1.0 (in z2jh 1.5.0) works very well in a couple of month. Now I'm trying upgrade to newest z2jh 2.0.0.

dolfinus commented 1 year ago

731 should fix that

consideRatio commented 1 year ago

Closed by #731, will be released in 6.0.0 to be released soonish