Update notebook spawner
@@ -43,6 +43,32 @@ class NotebookSpawner(ProjectJobSpawner):
port = random.randint(*settings.NOTEBOOK_PORT_RANGE)
return port
+ def get_notebook_args(self, deployment_name, ports):
+ notebook_token = self.get_notebook_token()
+ notebook_url = self._get_proxy_url(
+ namespace=self.namespace,
+ job_name=self.NOTEBOOK_JOB_NAME,
+ deployment_name=deployment_name,
+ port=ports[0])
+
+ notebook_dir = get_project_repos_path(self.project_name)
+ notebook_dir = '{}/{}'.format(notebook_dir, notebook_dir.split('/')[-1])
+
+ return [
+ "jupyter notebook "
+ "--no-browser "
+ "--port={port} "
+ "--ip=0.0.0.0 "
+ "--allow-root "
+ "--NotebookApp.token={token} "
+ "--NotebookApp.trust_xheaders=True "
+ "--NotebookApp.base_url={base_url} "
+ "--NotebookApp.notebook_dir={notebook_dir} ".format(
+ port=self.PORT,
+ token=notebook_token,
+ base_url=notebook_url,
+ notebook_dir=notebook_dir)]
+
def start_notebook(self, image, resources=None, node_selectors=None):
ports = [self.request_notebook_port()]
target_ports = [self.PORT]
@@ -52,14 +78,6 @@ class NotebookSpawner(ProjectJobSpawner):
volume_mounts.append(code_volume_mount)
deployment_name = constants.JOB_NAME.format(name=self.NOTEBOOK_JOB_NAME,
job_uuid=self.job_uuid)
- notebook_token = self.get_notebook_token()
- notebook_url = self._get_proxy_url(
- namespace=self.namespace,
- job_name=self.NOTEBOOK_JOB_NAME,
- deployment_name=deployment_name,
- port=ports[0])
- notebook_dir = get_project_repos_path(self.project_name)
- notebook_dir = '{}/{}'.format(notebook_dir, notebook_dir.split('/')[-1])
deployment = deployments.get_deployment(
namespace=self.namespace,
app=settings.APP_LABELS_NOTEBOOK,
@@ -72,20 +90,7 @@ class NotebookSpawner(ProjectJobSpawner):
volumes=volumes,
image=image,
command=["/bin/sh", "-c"],
- args=[
- "jupyter notebook "
- "--no-browser "
- "--port={port} "
- "--ip=0.0.0.0 "
- "--allow-root "
- "--NotebookApp.token={token} "
- "--NotebookApp.trust_xheaders=True "
- "--NotebookApp.base_url={base_url} "
- "--NotebookApp.notebook_dir={notebook_dir} ".format(
- port=self.PORT,
- token=notebook_token,
- base_url=notebook_url,
- notebook_dir=notebook_dir)],
+ args=self.get_notebook_args(deployment_name=deployment_name, ports=ports),
ports=target_ports,
container_name=settings.CONTAINER_NAME_PLUGIN_JOB,
resources=resources,
