jupyterhub / binderhub

Run your code in the cloud, with technology so advanced, it feels like magic!
https://binderhub.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.57k stars 390 forks source link

binder url request accessible to hub singleuser initContainers #1429

Open ltetrel opened 3 years ago

ltetrel commented 3 years ago

Proposed change

Adding the BINDER_REF_URL environment variable accessible to a hub singleuser initContainers. Although this env is accessible to the singleuser server pod, its init containers does not have it.

Here is an example of a singleuser pod in our cluster:

Name:         jupyter-ltetrel-2dnha2020-2dnilearn-2dggzfdpzu
Namespace:    binderhub
Priority:     0
(...)
Start Time:   Fri, 05 Nov 2021 14:55:10 -0400
Labels:       app=jupyterhub
              chart=jupyterhub-1.1.2
              component=singleuser-server
              heritage=jupyterhub
              hub.jupyter.org/network-access-hub=true
              hub.jupyter.org/servername=
              hub.jupyter.org/username=ltetrel-2dnha2020-2dnilearn-2dggzfdpzu
              release=binderhub
Annotations:  hub.jupyter.org/username: ltetrel-nha2020-nilearn-ggzfdpzu
(...)
Init Containers:
  init-repo2data:
    Container ID:  docker://364e06b026506c067ced6dd892856f258b92b409f86df4556043dfc60ed19ed7
    Image:         binder-registry.conp.cloud/repo2data:v2.5.2
    Image ID:      docker-pullable://binder-registry.conp.cloud/repo2data@sha256:376c033d7efa5d13ef8fd3d56f2add4fc7415694798d13e075264b17060dd175
    Port:          <none>
    Host Port:     <none>
    Command:
      /bin/sh
      -c
      env
    State:          Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Fri, 05 Nov 2021 14:55:19 -0400
      Finished:     Fri, 05 Nov 2021 14:55:19 -0400
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /data from shared-data (rw)
  block-cloud-metadata:
    Container ID:  docker://5622d9988940e173b5071ca8ffc6dcd9b5c02452b577fa2152b9528a097f0a04
    Image:         jupyterhub/k8s-network-tools:1.1.2
    Image ID:      docker-pullable://jupyterhub/k8s-network-tools@sha256:5238f5fc8281cb6e27ca22b5887fe6af97780a3696bf304fad35d207b2114c66
    Port:          <none>
    Host Port:     <none>
    Command:
      iptables
      -A
      OUTPUT
      -d
      169.254.169.254
      -j
      DROP
    State:          Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Fri, 05 Nov 2021 14:55:23 -0400
      Finished:     Fri, 05 Nov 2021 14:55:23 -0400
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:         <none>
Containers:
  notebook:
    (...)
    Environment:
      BINDER_LAUNCH_HOST:             https://binder.conp.cloud/
      BINDER_PERSISTENT_REQUEST:      v2/gh/ltetrel/nha2020-nilearn/8a0d951c4fe97160730e73bcdbe920b1d0d92871
      BINDER_REF_URL:                 https://github.com/ltetrel/nha2020-nilearn/tree/8a0d951c4fe97160730e73bcdbe920b1d0d92871
(...)

As you can see, BINDER_REF_URL is in the scope of Containers but not in scope Init Containers.

Who would use this feature?

Administrators of a binderhub cluster, to further increase the customization (like pulling the user github repo and doing work).

(Optional): Suggest a solution

Adding BINDER_REF_URL in the list of pod labels (Labels field), to be able to create a new env using:

singleuser:
  env:
  - name: BINDER_REF_URL
    valueFrom:
      fieldRef:
        fieldPath: metadata.labels['BINDER_REF_URL']

(k8s limits pod fields exposition to just few metadata: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#envvarsource-v1-core)

ltetrel commented 3 years ago

Partly related to this PR: https://github.com/jupyterhub/binderhub/pull/1081

meeseeksmachine commented 3 years ago

This issue has been mentioned on Jupyter Community Forum. There might be relevant details there:

https://discourse.jupyter.org/t/feature-idea-jupyterhub-binderhub-jupyter-book-as-a-publishing-platform/8359/8