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

hub.extraEnv / singleuser.extraEnv in dict format to support k8s EnvVar spec #1757

Merged

Conversation

consideRatio
Copy link
Member

@consideRatio consideRatio commented Aug 26, 2020

Background

In short, specifying an environment variable for the JupyterHub pod or the user pods could only be done in a limited fashion that excluded specifying an environment variable that got its value from some Kubernetes ConfigMap/Secret or similar. This has only been only possible with intrusive workarounds. This PR closes #1103 and an associated KubeSpawner PR has already closed jupyterhub/kubespawner#306 (comment).

hub.extraEnv advanced syntax support

This PR enables hub.extraEnv to function with a format either exactly like Kubernetes EnvVar specification or a shorthand where a name: ... is implied. This format is now also documented in the configuration reference (docs preview).

singleuser.extraEnv advanced syntax support

This PR doesn't fully close #1103 because this only enables the new syntax support for hub.extraEnv but not also for singleuser.extraEnv. jupyterhub/kubespawner#426 is now merged which takes care of the singleuser.extraEnv part.

Technical breakdown regarding singleuser.extraEnv

The Helm chart configuration singleuser.extraEnv propegates without issues to c.KubeSpawner.environment which is defined in the Spawner base class, so it turned out that no changes were needed in this repo. Below are still some of the notes I made along the way to ensure that was the case and to develop the PR (jupyterhub/kubespawner#426) in KubeSpawner that fixed it over there.

  1. Either directly configuring c.KubeSpawner.environment or doing it through singleuser.extraEnv should be fine even if we use the new syntax.
  2. KubeSpawner references the environment traitlet from the end of the jupyterhub.Spawner.get_env function.
  3. The get_env function is then called to provide the env argument to the make_pod function.
  4. The make_pod function use the the passed env vars once, that assuming support for new syntax should be able to get a dummyKey1 with a value of {name: "MY_ENV", value: "my-value"} passed to it.
  5. The V1EnvVar constructor allows for name/value/value_from, but is only used to pass a name/value combination rather than the possible name/valueFrom combination.
  6. The issue found in the point above is fixed in Support EnvVar's with 'valueFrom' as well as with 'value' kubespawner#426
  7. Documentation is also added in this PR to use singleuser.extraEnv with this new syntax.

Relevant references for this tech breakdown are the k8s api specs and the Python API for Kubernetes.

Discussion

Todo

Related

@consideRatio consideRatio force-pushed the pr/extra-env-with-envvar-objects branch from 527104c to 9d1ad08 Compare August 26, 2020 13:52
Note this commit relies on a KubeSpawner PR currently not merged. See
jupyterhub/kubespawner#426.
@consideRatio consideRatio force-pushed the pr/extra-env-with-envvar-objects branch from a316b05 to fd8c65d Compare September 1, 2020 17:29
@consideRatio consideRatio changed the title hub.extraEnv in dict format to support k8s EnvVar spec hub.extraEnv / singleuser.extraEnv in dict format to support k8s EnvVar spec Sep 3, 2020
Copy link
Member

@manics manics left a comment

Choose a reason for hiding this comment

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

Thanks, I think this is a good compromise!

I made some minor formatting suggestions based on https://zero-to-jupyterhub--1757.org.readthedocs.build/en/1757/reference/reference.html

jupyterhub/schema.yaml Outdated Show resolved Hide resolved
jupyterhub/schema.yaml Outdated Show resolved Hide resolved
jupyterhub/schema.yaml Outdated Show resolved Hide resolved
Co-authored-by: Simon Li <orpheus+devel@gmail.com>
@consideRatio
Copy link
Member Author

Thanks @manics!

@consideRatio
Copy link
Member Author

I consider this PR now ready for merge. @yuvipanda since you just looked at the KubeSpawner equivalent PR, perhaps you could have a look at this as well? Thank you @manics and @yuvipanda for the attention! ❤️

@yuvipanda yuvipanda merged commit 079fe5a into jupyterhub:master Sep 4, 2020
@yuvipanda
Copy link
Collaborator

Thanks a lot for working on this, @consideRatio!

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