This repository has been archived by the owner on Mar 17, 2023. It is now read-only.
forked from jupyter-on-openshift/jupyterhub-quickstart
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
819 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# Authenticate users against OpenShift OAuth provider. | ||
|
||
c.JupyterHub.authenticator_class = "openshift" | ||
|
||
from oauthenticator.openshift import OpenShiftOAuthenticator | ||
OpenShiftOAuthenticator.scope = ['user:full'] | ||
|
||
client_id = '%s-%s-users' % (application_name, namespace) | ||
client_secret = os.environ['OAUTH_CLIENT_SECRET'] | ||
|
||
c.OpenShiftOAuthenticator.client_id = client_id | ||
c.OpenShiftOAuthenticator.client_secret = client_secret | ||
c.Authenticator.enable_auth_state = True | ||
|
||
c.CryptKeeper.keys = [ client_secret.encode('utf-8') ] | ||
|
||
c.OpenShiftOAuthenticator.oauth_callback_url = ( | ||
'https://%s/hub/oauth_callback' % public_hostname) | ||
|
||
# Add any additional JupyterHub configuration settings. | ||
|
||
c.KubeSpawner.extra_labels = { | ||
'spawner': 'workspace', | ||
'class': 'session', | ||
'user': '{username}' | ||
} | ||
|
||
# Set up list of registered users and any users nominated as admins. | ||
|
||
if os.path.exists('/opt/app-root/configs/admin_users.txt'): | ||
with open('/opt/app-root/configs/admin_users.txt') as fp: | ||
content = fp.read().strip() | ||
if content: | ||
c.Authenticator.admin_users = set(content.split()) | ||
|
||
if os.path.exists('/opt/app-root/configs/user_whitelist.txt'): | ||
with open('/opt/app-root/configs/user_whitelist.txt') as fp: | ||
c.Authenticator.whitelist = set(fp.read().strip().split()) | ||
|
||
# For workshops we provide each user with a persistent volume so they | ||
# don't loose their work. This is mounted on /opt/app-root, so we need | ||
# to copy the contents from the image into the persistent volume the | ||
# first time using an init container. | ||
|
||
volume_size = os.environ.get('JUPYTERHUB_VOLUME_SIZE') | ||
|
||
if volume_size: | ||
c.KubeSpawner.pvc_name_template = c.KubeSpawner.pod_name_template | ||
|
||
c.KubeSpawner.storage_pvc_ensure = True | ||
|
||
c.KubeSpawner.storage_capacity = volume_size | ||
|
||
c.KubeSpawner.storage_access_modes = ['ReadWriteOnce'] | ||
|
||
c.KubeSpawner.volumes.extend([ | ||
{ | ||
'name': 'data', | ||
'persistentVolumeClaim': { | ||
'claimName': c.KubeSpawner.pvc_name_template | ||
} | ||
} | ||
]) | ||
|
||
c.KubeSpawner.volume_mounts.extend([ | ||
{ | ||
'name': 'data', | ||
'mountPath': '/opt/app-root', | ||
'subPath': 'workspace' | ||
} | ||
]) | ||
|
||
c.KubeSpawner.init_containers.extend([ | ||
{ | ||
'name': 'setup-volume', | ||
'image': '%s' % c.KubeSpawner.image_spec, | ||
'command': [ | ||
'/opt/app-root/bin/setup-volume.sh', | ||
'/opt/app-root', | ||
'/mnt/workspace' | ||
], | ||
"resources": { | ||
"limits": { | ||
"memory": os.environ.get('NOTEBOOK_MEMORY', '128Mi') | ||
}, | ||
"requests": { | ||
"memory": os.environ.get('NOTEBOOK_MEMORY', '128Mi') | ||
} | ||
}, | ||
'volumeMounts': [ | ||
{ | ||
'name': 'data', | ||
'mountPath': '/mnt' | ||
} | ||
] | ||
} | ||
]) | ||
|
||
# Make modifications to pod based on user and type of session. | ||
|
||
from tornado import gen | ||
|
||
@gen.coroutine | ||
def modify_pod_hook(spawner, pod): | ||
pod.spec.automount_service_account_token = True | ||
|
||
# Grab the OpenShift user access token from the login state. | ||
|
||
auth_state = yield spawner.user.get_auth_state() | ||
access_token = auth_state['access_token'] | ||
|
||
# Set the session access token from the OpenShift login. | ||
|
||
pod.spec.containers[0].env.append( | ||
dict(name='OPENSHIFT_TOKEN', value=access_token)) | ||
|
||
# See if a template for the project name has been specified. | ||
# Try expanding the name, substituting the username. If the | ||
# result is different then we use it, not if it is the same | ||
# which would suggest it isn't unique. | ||
|
||
project = os.environ.get('OPENSHIFT_PROJECT') | ||
|
||
if project: | ||
name = project.format(username=spawner.user.name) | ||
if name != project: | ||
pod.spec.containers[0].env.append( | ||
dict(name='PROJECT_NAMESPACE', value=name)) | ||
|
||
# Ensure project is created if it doesn't exist. | ||
|
||
pod.spec.containers[0].env.append( | ||
dict(name='OPENSHIFT_PROJECT', value=name)) | ||
|
||
return pod | ||
|
||
c.KubeSpawner.modify_pod_hook = modify_pod_hook | ||
|
||
# Setup culling of terminal instances if timeout parameter is supplied. | ||
|
||
idle_timeout = os.environ.get('JUPYTERHUB_IDLE_TIMEOUT') | ||
|
||
if idle_timeout and int(idle_timeout): | ||
cull_idle_servers_cmd = ['/opt/app-root/bin/cull-idle-servers'] | ||
|
||
cull_idle_servers_cmd.append('--timeout=%s' % idle_timeout) | ||
|
||
c.JupyterHub.services.extend([ | ||
{ | ||
'name': 'cull-idle', | ||
'admin': True, | ||
'command': cull_idle_servers_cmd, | ||
} | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
KUBERNETES_SERVER_URL="https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT" | ||
OAUTH_METADATA_URL="$KUBERNETES_SERVER_URL/.well-known/oauth-authorization-server" | ||
OAUTH_ISSUER_ADDRESS=`curl -ks $OAUTH_METADATA_URL | grep '"issuer":' | sed -e 's%.*https://%https://%' -e 's%",%%'` | ||
|
||
export OPENSHIFT_URL=$OAUTH_ISSUER_ADDRESS | ||
export OPENSHIFT_REST_API_URL=$KUBERNETES_SERVER_URL | ||
export OPENSHIFT_AUTH_API_URL=$OAUTH_ISSUER_ADDRESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
kubernetes==9.0.1 | ||
jupyterhub==0.9.6 | ||
jupyterhub==1.0.0 | ||
#jupyterhub-kubespawner==0.10.1 | ||
git+https://github.com/jupyter-on-openshift/kubespawner.git@055f6f29fd4d7ee56d1e9cca1aacdd6f5fd19507#egg=jupyterhub-kubespawner | ||
git+https://github.com/jupyterhub/kubespawner.git@a945ef01410867b39e0c174d362a8702bbaa15e9#egg=jupyterhub-kubespawner | ||
git+https://github.com/jupyterhub/wrapspawner.git@5f2b7075f77d0c1c49066682a8e8adad0dab76db | ||
jupyterhub-tmpauthenticator==0.6 | ||
oauthenticator==0.9.0 | ||
jupyterhub-ldapauthenticator==1.2.2 | ||
psycopg2==2.8.3 | ||
openshift==0.9.2 | ||
psycopg2==2.8.4 | ||
openshift==0.10.0 | ||
wrapt==1.11.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.