Skip to content

Commit

Permalink
import extraFiles wholesale from z2jh
Browse files Browse the repository at this point in the history
more complex, but also more general

helpers are imported from the jupyterhub chart!
  • Loading branch information
minrk committed Apr 26, 2022
1 parent d92f718 commit fa071b4
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 27 deletions.
35 changes: 29 additions & 6 deletions helm-chart/binderhub/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ required:
- service
- config
- extraConfig
- templates
- jupyterhub
- deployment
- dind
- imageCleaner
- ingress
- initContainers
- lifecycle
- extraFiles
- extraVolumes
- extraVolumeMounts
- extraEnv
Expand Down Expand Up @@ -261,13 +261,36 @@ properties:
manifest as either the binder pod going into `Error` or `CrashLoopBackoff` states, or in
some special cases, the binder pod running but... just doing very random things. Be careful!
templates:
extraFiles:
type: object
additionalProperties:
type: string
additionalProperties: false
description: |
Custom HTML page templates for BinderHub,
e.g. page.html.
A dictionary with extra files to be injected into the binder pod's container
on startup. This can for example be used to inject: configuration
files, custom user interface templates, images, and more.
See zero-to-jupyterhub's extraFiles documentation for reference.
patternProperties:
".*":
type: object
additionalProperties: false
required: [mountPath]
oneOf:
- required: [data]
- required: [stringData]
- required: [binaryData]
properties:
mountPath:
type: string
data:
type: object
additionalProperties: true
stringData:
type: string
binaryData:
type: string
mode:
type: number

jupyterhub:
type: object
Expand Down
24 changes: 17 additions & 7 deletions helm-chart/binderhub/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@ spec:
- name: config
secret:
secretName: binder-secret
- name: templates
{{- if .Values.extraFiles }}
- name: files
secret:
secretName: binder-secret
items:
{{- range $filename, $contents := .Values.templates }}
- key: "templates-{{ $filename }}"
path: {{ $filename | quote }}
{{- range $file_key, $file_details := .Values.extraFiles }}
- key: {{ $file_key | quote }}
path: {{ $file_key | quote }}
{{- with $file_details.mode }}
mode: {{ . }}
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.config.BinderHub.use_registry }}
- name: docker-secret
secret:
Expand Down Expand Up @@ -80,9 +85,14 @@ spec:
- mountPath: /etc/binderhub/config/
name: config
readOnly: true
- mountPath: /etc/binderhub/templates/
name: templates
readOnly: true
{{- range $file_key, $file_details := .Values.extraFiles }}
- mountPath: {{ $file_details.mountPath }}
subPath: {{ $file_key | quote }}
{{- with $file_details.mode }}
mode: {{ . }}
{{- end }}
name: files
{{- end }}
{{- if .Values.config.BinderHub.use_registry }}
- mountPath: /root/.docker
name: docker-secret
Expand Down
15 changes: 9 additions & 6 deletions helm-chart/binderhub/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ stringData:
values.yaml: |
{{- pick .Values "config" "cors" "dind" "extraConfig" | toYaml | nindent 4 }}
{{- /* Custom HTML templates */ -}}
{{- range $filename, $contents := .Values.templates }}
templates-{{ $filename }}: |
{{ $contents | nindent 4 }}
{{- end }}

{{- /* Glob files to allow them to be mounted by the binderhub pod */}}
{{- /* key=filename: value=content */}}
{{- (.Files.Glob "files/*").AsConfig | nindent 2 }}

{{- with include "jupyterhub.extraFiles.stringData" .Values.extraFiles }}
{{- . | nindent 2 }}
{{- end }}

{{- with include "jupyterhub.extraFiles.data" .Values.extraFiles }}
data:
{{- . | nindent 2 }}
{{- end }}
---
{{- if or .Values.config.BinderHub.use_registry .Values.config.BinderHub.buildDockerConfig }}
kind: Secret
Expand Down
2 changes: 1 addition & 1 deletion helm-chart/binderhub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ config:

extraConfig: {}

templates: {}
extraFiles: {}

# Two bits of config need to be set to fully enable cors.
# config.BinderHub.cors_allow_origin controls the allowed origins for the
Expand Down
16 changes: 9 additions & 7 deletions testing/k8s-binder-k8s-hub/binderhub-chart-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ config:
log_level: 10
cors_allow_origin: "*"

templates:
page.html: |
{% extends "templates/page.html" %}
{% block footer %}
{{ super() }}
<span>test-template</span>
{% endblock %}
extraFiles:
page.html:
mountPath: /etc/binderhub/templates/page.html
stringData: |
{% extends "templates/page.html" %}
{% block footer %}
{{ super() }}
<span>test-template</span>
{% endblock %}
ingress:
# Enabled to test the creation/update of the k8s Ingress resource, but not
Expand Down

0 comments on commit fa071b4

Please sign in to comment.