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

pass allowed query parameters to spawner via user options #805

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bitnik
Copy link
Collaborator

@bitnik bitnik commented Mar 13, 2019

Firstly, this pull request can wait until a naming scheme for query parameters is decided (#712). I just want to propose a way to pass query parameters from launch url through user_options to spawner.

This PR introduces a new config query_parameter_names which is to be filled with list of allowed query parameter names. With this PR launch url query is appended to build url (/build/<prefix>/<spec>). And BinderHub uses query_parameter_names before launch and checks if they exist in the build url query and passes found ones with their value to spawner's user_options (through JupyterHub's api).

This PR doesn't do anything with spawner, so default BinderSpawner doesn't know how to interpret these new user options. But one can define c.KubeSpawner.pre_spawn_hook similar to jupyterhub/zero-to-jupyterhub-k8s#1178 (comment):

hub:
  extraConfig:
    myExtraConfig: |
      async def my_pre_spawn_hook(spawner):
          value = spawner.user_options.get(<parameter_name>)
          # set a spawner setting according to value
          c.spawner.<any KubeSpawner (or Spawner) setting> = <any value>

      c.KubeSpawner.pre_spawn_hook = my_pre_spawn_hook

I also added an empty hidden input user_options into binder form. When user launches by using form, its value is appended to build url in javascript code. This might be useful when someone has customised binder form template.

When a naming scheme is decided, I can make an update to validate query_parameter_names config.

@bitnik
Copy link
Collaborator Author

bitnik commented Mar 13, 2019

Btw I deployed this version of BinderHub on our staging server (https://notebooks-test.gesis.org) with query_parameter_names: ['run-nbgitpuller'] and a new BinderSpawner which knows how to interpret that option (https://github.com/gesiscss/example-binderhub-deployments/blob/master/persistent_storage/config.yaml). So when user launches a repo from "Your projects" table nbgitpuller is not executed after server start unless user checks "Update" checkbox. And when launching a repo with binder form, nbgitpuller is always executed.

@rochaporto
Copy link
Contributor

I've done something similar to allow custom images directly on the jupyterhub profile selection in a deployment relying on KubeSpawner. Looking at allowing the profile selection from the binderhub it seems the same should work, as it's done in this PR.

Is there an update on how Binder is planning to provide this kind of thing? I saw the tickets regarding the naming scheme for query parameters (#712) but relying on user_options seems to do the job as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants