cassinyio / SwarmSpawner

This repo is deprecated. A spawner for JupyterHub
BSD 3-Clause "New" or "Revised" License
23 stars 36 forks source link

name must be valid as a DNS name component #5

Closed MAliNaqvi closed 7 years ago

MAliNaqvi commented 7 years ago

@barrachri

Issue: Starting the notebook service via swarmspawner results in:

jupyterhub.1.ox704kq02e01@moby    | [I 2017-03-16 19:11:34.117 JupyterHub log:100] 200 GET /hub/login?next=%2Fhub%2Fuser%2Fanaqvi%2Fapi%2Fsessions%3F_%3D1489688263779 (@::ffff:10.255.0.3) 3.45ms
jupyterhub.1.ox704kq02e01@moby    | [I 2017-03-16 19:11:42.975 JupyterHub log:100] 302 GET / (@::ffff:10.255.0.3) 0.83ms
jupyterhub.1.ox704kq02e01@moby    | [I 2017-03-16 19:11:42.982 JupyterHub log:100] 302 GET /hub (@::ffff:10.255.0.3) 0.60ms
jupyterhub.1.ox704kq02e01@moby    | [I 2017-03-16 19:11:42.999 JupyterHub log:100] 302 GET /hub/ (@::ffff:10.255.0.3) 1.18ms
jupyterhub.1.ox704kq02e01@moby    | [I 2017-03-16 19:11:43.017 JupyterHub log:100] 200 GET /hub/login (@::ffff:10.255.0.3) 2.14ms
jupyterhub.1.ox704kq02e01@moby    | [I 2017-03-16 19:11:47.273 JupyterHub swarmspawner:260] Service 'jupyter-77e417a2b692b459f1deaac61b3bf5ba-1' is gone
jupyterhub.1.ox704kq02e01@moby    | [W 2017-03-16 19:11:47.273 JupyterHub swarmspawner:221] Service not found
jupyterhub.1.ox704kq02e01@moby    | [W 2017-03-16 19:11:47.810 JupyterHub swarmspawner:285] self.use_user_options:
jupyterhub.1.ox704kq02e01@moby    | [W 2017-03-16 19:11:47.810 JupyterHub swarmspawner:286] {}
jupyterhub.1.ox704kq02e01@moby    | [I 2017-03-16 19:11:47.819 JupyterHub swarmspawner:260] Service 'jupyter-77e417a2b692b459f1deaac61b3bf5ba-' is gone
jupyterhub.1.ox704kq02e01@moby    | [E 2017-03-16 19:11:48.738 JupyterHub user:282] Unhandled error starting anaqvi's server: 500 Server Error: Internal Server Error for url: http+docker://localunixsocket/v1.26/services/create ("rpc error: code = 3 desc = name must be valid as a DNS name component")

Explanation: The hub can't find the service jupyter-77e417a2b692b459f1deaac61b3bf5ba-1 associated with a username anaqvi. It checks user options for a server_name:

https://github.com/cassinyio/SwarmSpawner/blob/master/cassinyspawner/swarmspawner.py#L292-L293

however it doesn't assign a value to server_name if there are no user options. That is if the c.SwarmSpawner.use_user_options = False in jupyterhub_config.py then it doesn't assign the server_name anything. This results in the DNS name to be:

jupyter-77e417a2b692b459f1deaac61b3bf5ba-

which is against the regex for DNS names in Docker ^[a-zA-Z0-9](?:[-_]*[A-Za-z0-9]+)*$ as it contains a dash at the end.

This can be confirmed by changing this line: https://github.com/cassinyio/SwarmSpawner/blob/master/cassinyspawner/swarmspawner.py#L156

from

        return "{}-{}-{}".format(self.service_prefix,

to

        return "{}-{}{}".format(self.service_prefix,

Possible solution: I have a minor commit that fixes this issue by assigning the value of 1 to self.server_name after the if statement: https://github.com/MAliNaqvi/SwarmSpawner/commit/49fb55b328ccd01020267cbd76c0a1fefa23a1ca

barrachri commented 7 years ago

Hi @MAliNaqvi, thanks for the issue.

The case where server_name is not specified should be handled inside https://github.com/cassinyio/SwarmSpawner/blob/master/cassinyspawner/swarmspawner.py#L142

I just updated the master branch with a new commit.

Can you check if it works?

MAliNaqvi commented 7 years ago

Hi @barrachri thank you for the quick response.

The change doesn't work.

https://www.dropbox.com/s/wv8lxyqlryg52yh/Screenshot%202017-03-16%2019.00.15.png?dl=0 the left terminal the server logs with the error right terminal I show the docker container which is running the hub, as well as the latest incorporated code

MAliNaqvi commented 7 years ago

@barrachri A colleague of mine @evgeniwk tracked the problem to this line:

https://github.com/jupyterhub/jupyterhub/blob/95dc4713f48be2cdc7b28b71447ab3e91ce3befc/jupyterhub/user.py#L224

This section relates to allowing multiple servers per user. If we set c.JupyterHub.allow_multiple_servers = False to JupyterHub.allow_multiple_servers = True

The server_name appears correctly: https://www.dropbox.com/s/snn9reyg0cvj1a8/Screenshot%202017-03-16%2019.13.50.png?dl=0

but there is a 404.

barrachri commented 7 years ago

So the problem was that 'self.server_name' always exists and is not none but '' that is False.

You can remove 'c.JupyterHub.allow_multiple_servers = False' because we are still working on this feature.

With the last commit this problem should be resolved.

If you get a 404 error:

  1. Check from docker if the service is running
  2. Check if you created an overlay network between the jupyterhub and the new service, otherwise jupyterhub cannot reach the service

https://github.com/cassinyio/SwarmSpawner#networks

MAliNaqvi commented 7 years ago

@barrachri

The new change https://github.com/cassinyio/SwarmSpawner/blob/254f07899fb6a18fe1ff235a0e91acc485509942/cassinyspawner/swarmspawner.py#L150-L153

gives an attribute error:

jupyterhub.1.mpvej68c1wtx@moby    |       File "/srv/jupyterhub/src/swarmspawner/cassinyspawner/swarmspawner.py", line 150, in service_name
jupyterhub.1.mpvej68c1wtx@moby    |         if self.server_name:
jupyterhub.1.mpvej68c1wtx@moby    |     AttributeError: 'SwarmSpawner' object has no attribute 'server_name'

We can solve it either by:

        if hasattr(self, 'server_name'):
            if self.server_name:
                server_name = self.server_name
            else:
                server_name = 1
        else:
            server_name = 1

or a simpler version would be:

        server_name = 1
        if hasattr(self, 'server_name'):
            if self.server_name:
                server_name = self.server_name

I have tested both and they work.

barrachri commented 7 years ago

Hi @MAliNaqvi thanks for the patient.

So service_name is also called outside def start() this why we get AttributeError. With the last version of the spawner it works.

I am waiting for a feedback to close this issue.

MAliNaqvi commented 7 years ago

@barrachri yes the latest code works. This issue can be closed.