Skip to content

Commit 15ae67a

Browse files
author
Riccardo Castellotti
committed
customization for binder/swan interoperability
1 parent 8160363 commit 15ae67a

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

swan-cern/files/swan_config_cern.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os, subprocess
1+
22

33
from kubernetes import client
44
from kubernetes.client.rest import ApiException
@@ -190,6 +190,19 @@ def _init_eos_containers(self, eos_secret_name):
190190
)
191191
)
192192

193+
#the notebook container needs to run as root as it needs to
194+
#add an user and switch to that user
195+
#it also need to set command and args to none in order to
196+
#run the systemuser.sh script as defined in the image
197+
#(we set jupyterhub-singleuser in the values as that is what
198+
#is needed for authenticated binder)
199+
200+
run_as_root=client.V1SecurityContext(run_as_user=0)
201+
202+
notebook_container.security_context=run_as_root
203+
notebook_container.command=None
204+
notebook_container.args=None
205+
193206
# add the base containers after side container (to start after side container)
194207
existing_containers = self.pod.spec.containers
195208
pod_spec_containers.extend(existing_containers)
@@ -200,11 +213,11 @@ def _init_eos_containers(self, eos_secret_name):
200213
# https://jupyterhub-kubespawner.readthedocs.io/en/latest/spawner.html
201214
# This is defined in the configuration to allow overring iindependently
202215
# of which config file is loaded first
203-
# c.SwanKubeSpawner.modify_pod_hook = swan_pod_hook
216+
# c.SwanSpawner.modify_pod_hook = swan_pod_hook
204217
def swan_pod_hook_prod(spawner, pod):
205218
"""
206219
:param spawner: Swan Kubernetes Spawner
207-
:type spawner: swanspawner.SwanKubeSpawner
220+
:type spawner: swanspawner.SwanSpawner
208221
:param pod: default pod definition set by jupyterhub
209222
:type pod: client.V1Pod
210223
@@ -219,7 +232,4 @@ def swan_pod_hook_prod(spawner, pod):
219232
# Get configuration parameters from environment variables
220233
swan_container_namespace = os.environ.get('POD_NAMESPACE', 'default')
221234

222-
c.SwanKubeSpawner.modify_pod_hook = swan_pod_hook_prod
223-
224-
# Required for swan systemuser.sh
225-
c.SwanKubeSpawner.cmd = None
235+
c.SwanSpawner.modify_pod_hook = swan_pod_hook_prod

swan-cern/files/swan_spark_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class SwanSparkPodHookHandler(SwanPodHookHandlerProd):
1414

1515
def get_swan_user_pod(self):
1616

17+
18+
if 'binder_ref_url' in self.spawner.user_options.keys():
19+
# we don't need any customization if running within binder
20+
return self.pod
21+
1722
super().get_swan_user_pod()
1823

1924
# get hadoop token

swan/files/swan_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ def __init__(self, spawner, pod):
1818

1919
def get_swan_user_pod(self):
2020

21+
if 'binder_ref_url' in self.spawner.user_options.keys():
22+
# we don't need any customization if running within binder
23+
return self.pod
24+
25+
2126
# pod labels
2227
pod_labels = dict(
2328
lcg_release = self.spawner.user_options[self.spawner.lcg_rel_field].split('/')[0],

0 commit comments

Comments
 (0)