Changing the contents manager

I try to add an s3 folder to the jupyter notebooks, where people would be able to put some shared notebooks there.

I do have the config to put in jupyter_notebook_config.py but i have no clue how to modify that in a kubernetes setup.
The bucket used depend on the environment, so i cannot really change the config in the docker build, since containers are used in multiple environment.

from s3contents import S3ContentsManager
  from hybridcontents import HybridContentsManager
  from notebook.services.contents.largefilemanager import LargeFileManager

  c = get_config()

  c.NotebookApp.contents_manager_class = HybridContentsManager

  c.HybridContentsManager.manager_classes = {
      "shared": S3ContentsManager,
      "": LargeFileManager,
  }

  c.HybridContentsManager.manager_kwargs = {
      "shared": {
          "bucket": "${notebook_bucket}",
          "prefix": os.path.join("jupyter", "shared")
      },
      "": {
          "root_dir": "/home/jovyan/",
      },
  }

Does someone have an idea ?

I did consider the lifecyclehooks but not tried yet.

Can you give us more information on how the chosen bucket is determined? There are several ways of customising your container at runtime e.g. using JupyterHub hooks, kubernetes hooks, dynamically set environment variables, etc, so a bit more information would be useful.

Sure !

The bucket is simply something like my_jupyter_bucket_${env}. Currently i do have a dev and prod env.
The dev kubernetes cluster should deploy containers using the dev bucket. Same for prod.

I did also thing of using config map to override the jupyter_notebook_config.py, but still, it sounds harder than what i would expect.

Quentin

Since your bucket name is static with respect to the deployment I think this should be easy, you could set an environment variable BUCKET_NAME in your Helm chart configuration: Customizing User Environment — Zero to JupyterHub with Kubernetes documentation

and in your jupyter_notebook_config.py have something like

    "bucket": os.getenv('BUCKET_NAME')