Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basehub: add singleuserAdmin.serviceAccountName config and small refactoring #3039

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions helm-charts/basehub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -577,27 +577,35 @@ jupyterhub:
memory: 2Gi
extraConfig:
01-custom-theme: |
# adds a JupyterHub template path and updates template variables

from z2jh import get_config
c.JupyterHub.template_paths.insert(0,'/usr/local/share/jupyterhub/custom_templates')
c.JupyterHub.template_vars.update({
'custom': get_config('custom.homepage.templateVars')
})
02-custom-admin: |
# adjusts the spawner to add config specific to admin users

from z2jh import get_config
from kubespawner import KubeSpawner
from jupyterhub_configurator.mixins import ConfiguratorSpawnerMixin

class CustomSpawner(ConfiguratorSpawnerMixin, KubeSpawner):
def start(self, *args, **kwargs):
custom_admin = get_config('custom.singleuserAdmin', {})
if custom_admin and self.user.admin:
extra_init_containers = custom_admin.get('initContainers', [])
consideRatio marked this conversation as resolved.
Show resolved Hide resolved
extra_volume_mounts = custom_admin.get('extraVolumeMounts', [])
extra_env = custom_admin.get('extraEnv', {})

self.init_containers += [container for container in extra_init_containers if container not in self.init_containers]
self.volume_mounts += [volume for volume in extra_volume_mounts if volume not in self.volume_mounts]
self.environment.update(extra_env)
if not (self.user.admin and custom_admin):
return super().start(*args, **kwargs)
Comment on lines +597 to +598
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is opinionated refactoring to have us avoid nesting into if statements and make the code a bit flatter.


admin_volume_mounts = custom_admin.get('extraVolumeMounts', [])
self.volume_mounts += [vm for vm in admin_volume_mounts if vm not in self.volume_mounts]

admin_environment = custom_admin.get('extraEnv', {})
self.environment.update(admin_environment)

admin_service_account = custom_admin.get('serviceAccountName'):
if admin_service_account:
self.service_account = admin_service_account

return super().start(*args, **kwargs)

Expand Down