Hello everyone,
for some time now, the configuration ‘extra_handlers’ to register additional HTTP endpoints has been deprecated.
Before the configuration can no longer be used in a future update, I am currently trying to convert all created handlers to services.
As an example, I first wanted to test the whoami service. Unfortunately, I am already failing to get the service to run.
Since I am using Kubernetes, it seems to be much more complex to get this simple example running.
I tried to rebuild whoami using the example Hub-managed services in z2jh.
If I then click on the service I will be redirected from /service/whoami → to /hub/login?next=%2Fservices%2Fwhoami%2F → to /hub.
Here is the customised code:
jupyterhub_config.py
import sys
c.JupyterHub.services += [
{
'name': 'whoami',
'url': 'http://hub:8181',
'command': [sys.executable, '/services/whoami.py'],
'display': True,
}
]
c.JupyterHub.load_roles += [
{
"name": "user",
# grant all users access to all services
"scopes": ["access:services", "self"],
}
]
whoami.py
class WhoAmIHandler(HubAuthenticated, RequestHandler):
@authenticated
def get(self):
user_model = self.get_current_user()
self.set_header('content-type', 'application/json')
self.write(json.dumps(user_model, indent=1, sort_keys=True))
def main():
app = Application(
[
(os.environ['JUPYTERHUB_SERVICE_PREFIX'] + '/?', WhoAmIHandler),
(r'.*', WhoAmIHandler),
]
)
http_server = HTTPServer(app)
http_server.listen(port=8181, address="0.0.0.0")
IOLoop.current().start()
if __name__ == '__main__':
main()
config.yaml
proxy:
chp:
networkPolicy:
egress:
- to:
- podSelector:
matchLabels:
app.kubernetes.io/name: jupyterhub
app.kubernetes.io/component: hub
ports:
- port: 8181
...
hub:
...
networkPolicy:
ingress:
- ports:
- port: 8181
from:
- podSelector:
matchLabels:
hub.jupyter.org/network-access-hub: "true"
service:
extraPorts:
- port: 8181
targetPort: 8181
name: whoami
...
Log
Waiting 1s for server at http://hub:8181/services/whoami/
Server at http://hub:8181/services/whoami/ responded with 302
And I see that render_template from BaseHandler in this post then seems to cause other unresolved? problems.
But I won’t be able to take care of that until I get whoami up and running.
In any case, thanks for any help.