Skip to content

Commit

Permalink
binderspawner as configmap
Browse files Browse the repository at this point in the history
  • Loading branch information
bitnik committed Dec 3, 2019
1 parent bcadc59 commit 9142f4e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 48 deletions.
44 changes: 44 additions & 0 deletions helm-chart/binderhub/files/etc/jupyterhub/binder_spawner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import z2jh
from tornado import web
from kubespawner import KubeSpawner

# get cors config from values.custom.cors
cors = z2jh.get_config('custom.cors', {})


class BinderSpawner(KubeSpawner):
def get_args(self):
args = [
'--ip=0.0.0.0',
'--port=%i' % self.port,
'--NotebookApp.base_url=%s' % self.server.base_url,
'--NotebookApp.token=%s' % self.user_options['token'],
'--NotebookApp.trust_xheaders=True',
]
allow_origin = cors.get('allowOrigin')
if allow_origin:
args.append('--NotebookApp.allow_origin=' + allow_origin)
return args + self.args

def start(self):
# image & token are set via spawn options
if 'token' not in self.user_options:
raise web.HTTPError(400, "token required")
if 'image' not in self.user_options:
raise web.HTTPError(400, "image required")

self.image = self.user_options['image']
return super().start()

def get_env(self):
env = super(BinderSpawner, self).get_env()
if 'repo_url' in self.user_options:
env['BINDER_REPO_URL'] = self.user_options['repo_url']
for key in (
'binder_ref_url',
'binder_launch_host',
'binder_persistent_request',
'binder_request'):
if key in self.user_options:
env[key.upper()] = self.user_options[key]
return env
8 changes: 8 additions & 0 deletions helm-chart/binderhub/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ data:
{{- end }}
values.yaml: |
{{- $values | toYaml | nindent 4 }}
---
kind: ConfigMap
apiVersion: v1
metadata:
name: hub-extra-config
data:
binder_spawner.py: |-
{{- .Files.Get "files/etc/jupyterhub/binder_spawner.py" | nindent 4 }}
57 changes: 9 additions & 48 deletions helm-chart/binderhub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,56 +62,17 @@ jupyterhub:
rbac:
enabled: true
hub:
extraVolumes:
- name: hub-extra-config
configMap:
name: hub-extra-config
extraVolumeMounts:
- mountPath: /etc/jupyterhub/binder_spawner.py
subPath: binder_spawner.py
name: hub-extra-config
extraConfig:
binder: |
import os
import sys
import yaml
from tornado import web
# get cors config from values.custom.cors
import z2jh
cors = z2jh.get_config('custom.cors', {})
# image & token are set via spawn options
from kubespawner import KubeSpawner
class BinderSpawner(KubeSpawner):
def get_args(self):
args = [
'--ip=0.0.0.0',
'--port=%i' % self.port,
'--NotebookApp.base_url=%s' % self.server.base_url,
'--NotebookApp.token=%s' % self.user_options['token'],
'--NotebookApp.trust_xheaders=True',
]
allow_origin = cors.get('allowOrigin')
if allow_origin:
args.append('--NotebookApp.allow_origin=' + allow_origin)
return args + self.args
def start(self):
if 'token' not in self.user_options:
raise web.HTTPError(400, "token required")
if 'image' not in self.user_options:
raise web.HTTPError(400, "image required")
self.image = self.user_options['image']
return super().start()
def get_env(self):
env = super(BinderSpawner, self).get_env()
if 'repo_url' in self.user_options:
env['BINDER_REPO_URL'] = self.user_options['repo_url']
for key in (
'binder_ref_url',
'binder_launch_host',
'binder_persistent_request',
'binder_request'):
if key in self.user_options:
env[key.upper()] = self.user_options[key]
return env
from binder_spawner import BinderSpawner
c.JupyterHub.spawner_class = BinderSpawner
services:
binder:
Expand Down

0 comments on commit 9142f4e

Please sign in to comment.