Skip to content

Commit

Permalink
support custom templates via helm
Browse files Browse the repository at this point in the history
- top-level templates is dict of filename: contents, e.g. "page.html": "{% extends "templates/page.html" %}"
- mount custom templates dir in /etc/binderhub/templates

Existing template config already supports this, so it's just making the files available we need.
  • Loading branch information
minrk committed Apr 25, 2022
1 parent 66ca304 commit 561a5af
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
2 changes: 2 additions & 0 deletions helm-chart/binderhub/files/binderhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def get_value(key, default=None):
value = value[level]
return value

# load custom templates, by default
c.BinderHub.template_path = "/etc/binderhub/templates"

# load config from values.yaml
for section, sub_cfg in get_value("config", {}).items():
Expand Down
11 changes: 10 additions & 1 deletion helm-chart/binderhub/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ required:
- service
- config
- extraConfig
- templates
- jupyterhub
- deployment
- dind
Expand Down Expand Up @@ -260,6 +261,14 @@ 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:
type: object
additionalProperties:
type: string
description: |
Custom HTML page templates for BinderHub,
e.g. page.html.
jupyterhub:
type: object
additionalProperties: true
Expand Down Expand Up @@ -479,7 +488,7 @@ properties:
description: |
The path type to use. The default value is 'Prefix'. Only applies on Kubernetes v1.18+.
See [the Kubernetes documentation](https://kubernetes.io/docs/concepts/services-networking/ingress/#path-types)
See [the Kubernetes documentation](https://kubernetes.io/docs/concepts/services-networking/ingress/#path-types)
for more details about path types.
tls:
type: array
Expand Down
12 changes: 12 additions & 0 deletions helm-chart/binderhub/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ spec:
- name: config
secret:
secretName: binder-secret
- name: templates
secret:
secretName: binder-secret
items:
{{- range $filename, $contents := .Values.templates }}
- key: "templates-{{ $filename }}"
path: {{ $filename | quote }}
{{- end }}
{{- if .Values.config.BinderHub.use_registry }}
- name: docker-secret
secret:
Expand All @@ -54,6 +62,7 @@ spec:
hostPath:
path: /var/run/docker.sock
{{- end }}

{{- with .Values.extraVolumes }}
{{- . | toYaml | nindent 6 }}
{{- end }}
Expand All @@ -71,6 +80,9 @@ spec:
- mountPath: /etc/binderhub/config/
name: config
readOnly: true
- mountPath: /etc/binderhub/templates/
name: templates
readOnly: true
{{- if .Values.config.BinderHub.use_registry }}
- mountPath: /root/.docker
name: docker-secret
Expand Down
6 changes: 6 additions & 0 deletions helm-chart/binderhub/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ 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 }}
Expand Down
8 changes: 4 additions & 4 deletions helm-chart/binderhub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ config:

extraConfig: {}

templates: {}

# Two bits of config need to be set to fully enable cors.
# config.BinderHub.cors_allow_origin controls the allowed origins for the
# binderhub api, and jupyterhub.hub.config.BinderSpawner.cors_allow_origin
Expand Down Expand Up @@ -281,16 +283,14 @@ ingress:
type: kube-lego
hosts: []
ingressClassName:
annotations:
{}
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
pathSuffix:
# Suffix added to Ingress's routing path pattern.
# Specify `*` if your ingress matches path by glob pattern.
pathType: Prefix
tls:
[]
tls: []
# Secrets must be manually created in the namespace.
# - secretName: chart-example-tls
# hosts:
Expand Down
8 changes: 8 additions & 0 deletions testing/k8s-binder-k8s-hub/binderhub-chart-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ config:
log_level: 10
cors_allow_origin: "*"

templates:
page.html: |
{% 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
# used actively in our CI system.
Expand Down

0 comments on commit 561a5af

Please sign in to comment.