Skip to content

Commit

Permalink
extraFiles: Locate to /usr/local/etc and jupyterhub_config.d
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jan 27, 2021
1 parent 0cc6842 commit f1ca325
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion dev-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ hub:
cpu: 0
extraFiles:
my_config:
mountPath: /etc/jupyterhub.d/my_config.py
mountPath: /usr/local/etc/jupyterhub/jupyterhub_config.d/my_config.py
stringData: |
with open("/tmp/created-by-extra-files-config.txt", "w") as f:
f.write("hello world!")
Expand Down
2 changes: 1 addition & 1 deletion images/hub/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ ARG PIP_TOOLS=
RUN test -z "$PIP_TOOLS" || pip install --no-cache pip-tools==$PIP_TOOLS

USER ${NB_USER}
CMD ["jupyterhub", "--config", "/etc/jupyterhub/jupyterhub_config.py"]
CMD ["jupyterhub", "--config", "/usr/local/etc/jupyterhub/jupyterhub_config.py"]
4 changes: 2 additions & 2 deletions jupyterhub/files/hub/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ def camelCaseify(s):
c.JupyterHub.log_level = "DEBUG"
c.Spawner.debug = True

# load /etc/jupyterhub.d config files
config_dir = "/etc/jupyterhub.d"
# load /usr/local/etc/jupyterhub/jupyterhub_config.d config files
config_dir = "/usr/local/etc/jupyterhub/jupyterhub_config.d"
if os.path.isdir(config_dir):
for file_name in sorted(os.listdir(config_dir)):
print(f"Loading {config_dir} config: {file_name}")
Expand Down
6 changes: 3 additions & 3 deletions jupyterhub/files/hub/z2jh.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _load_config():
"""Load the Helm chart configuration used to render the Helm templates of
the chart from a mounted k8s Secret."""

path = f"/etc/jupyterhub/secret/values.yaml"
path = f"/usr/local/etc/jupyterhub/secret/values.yaml"
if os.path.exists(path):
print(f"Loading {path}")
with open(path) as f:
Expand All @@ -28,7 +28,7 @@ def _load_config():
def _get_config_value(key):
"""Load value from the k8s ConfigMap given a key."""

path = f"/etc/jupyterhub/config/{key}"
path = f"/usr/local/etc/jupyterhub/config/{key}"
if os.path.exists(path):
with open(path) as f:
return f.read()
Expand All @@ -40,7 +40,7 @@ def _get_config_value(key):
def get_secret_value(key):
"""Load value from the k8s Secret given a key."""

path = f"/etc/jupyterhub/secret/{key}"
path = f"/usr/local/etc/jupyterhub/secret/{key}"
if os.path.exists(path):
with open(path) as f:
return f.read()
Expand Down
23 changes: 12 additions & 11 deletions jupyterhub/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ properties:
my_image:
mountPath: /usr/local/share/jupyterhub/static/my_image.png
# Files in /etc/jupyterhub.d are automatically loaded in
# alphabetical order of the final file name when JupyterHub
# starts.
# Files in /usr/local/etc/jupyterhub/jupyterhub_config.d are
# automatically loaded in alphabetical order of the final file
# name when JupyterHub starts.
my_config:
mountPath: /etc/jupyterhub.d/my_jupyterhub_config.py
mountPath: /usr/local/etc/jupyterhub/jupyterhub_config.d/my_jupyterhub_config.py
```
```bash
Expand Down Expand Up @@ -307,8 +307,9 @@ properties:
Instead of embedding JupyterHub python configuration as a string
within a YAML file through
[`hub.extraConfig`](schema_hub.extraConfig), you can inject a
standalone .py file into `/etc/jupyterhub.d` that is automatically
loaded.
standalone .py file into
`/usr/local/etc/jupyterhub/jupyterhub_config.d` that is
automatically loaded.
1. **Flexible configuration**
Expand Down Expand Up @@ -371,10 +372,10 @@ properties:
```{warning}
By replacing the entire configuration file, which is mounted to
`/etc/jupyterhub/jupyterhub_config.py` by the Helm chart, instead of
appending to it with `hub.extraConfig`, you expose your deployment for
issues stemming from getting out of sync with the Helm chart's config
file.
`/usr/local/etc/jupyterhub/jupyterhub_config.py` by the Helm chart,
instead of appending to it with `hub.extraConfig`, you expose your
deployment for issues stemming from getting out of sync with the Helm
chart's config file.
These kind of issues will be significantly harder to debug and
diagnose, and can due to this could cause a lot of time expenditure
Expand All @@ -396,7 +397,7 @@ properties:
args:
- "jupyterhub"
- "--config"
- "/etc/jupyterhub/jupyterhub_config.py"
- "/usr/local/etc/jupyterhub/jupyterhub_config.py"
- "--debug"
- "--upgrade-db"
```
Expand Down
10 changes: 5 additions & 5 deletions jupyterhub/templates/hub/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ spec:
{{- else }}
- jupyterhub
- --config
- /etc/jupyterhub/jupyterhub_config.py
- /usr/local/etc/jupyterhub/jupyterhub_config.py
{{- if .Values.debug.enabled }}
- --debug
{{- end }}
Expand All @@ -136,15 +136,15 @@ spec:
{{- end }}
{{- end }}
volumeMounts:
- mountPath: /etc/jupyterhub/jupyterhub_config.py
- mountPath: /usr/local/etc/jupyterhub/jupyterhub_config.py
subPath: jupyterhub_config.py
name: config
- mountPath: /etc/jupyterhub/z2jh.py
- mountPath: /usr/local/etc/jupyterhub/z2jh.py
subPath: z2jh.py
name: config
- mountPath: /etc/jupyterhub/config/
- mountPath: /usr/local/etc/jupyterhub/config/
name: config
- mountPath: /etc/jupyterhub/secret/
- mountPath: /usr/local/etc/jupyterhub/secret/
name: secret
{{- range $file_key, $file_details := .Values.hub.extraFiles }}
- mountPath: {{ $file_details.mountPath }}
Expand Down
7 changes: 4 additions & 3 deletions tests/test_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ def test_hub_mounted_extra_files():

def test_hub_etc_jupyterhub_d_folder():
"""
Tests that the extra jupyterhub config file put into /etc/jupyterhub.d by
the hub.extraFiles configuration was loaded.
Tests that the extra jupyterhub config file put into
/usr/local/etc/jupyterhub/jupyterhub_config.d by the hub.extraFiles
configuration was loaded.
"""
c = subprocess.run(
[
Expand All @@ -171,7 +172,7 @@ def test_hub_etc_jupyterhub_d_folder():
)
assert (
c.returncode == 0
), f"The hub.extraFiles configuration should have mounted a config file to /etc/jupyterhub.d which should have been loaded to write a dummy file for us!"
), f"The hub.extraFiles configuration should have mounted a config file to /usr/local/etc/jupyterhub/jupyterhub_config.d which should have been loaded to write a dummy file for us!"


def test_hub_api_request_user_spawn(
Expand Down
2 changes: 1 addition & 1 deletion tools/templates/lint-and-validate-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ imagePullSecrets: [a, b]
hub:
extraFiles:
my_config:
mountPath: /etc/jupyterhub.d/my_config.py
mountPath: /usr/local/etc/jupyterhub/jupyterhub_config.d/my_config.py
stringData: |
with open("/tmp/created-by-extra-files-config.txt", "w") as f:
f.write("hello world!")
Expand Down

0 comments on commit f1ca325

Please sign in to comment.