From f0db8e435739e9f6082213d837aaba2f628cf0bf Mon Sep 17 00:00:00 2001 From: Min RK Date: Mon, 25 Apr 2022 12:38:46 +0200 Subject: [PATCH] support custom templates via helm - 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. --- helm-chart/binderhub/files/binderhub_config.py | 3 +++ helm-chart/binderhub/schema.yaml | 11 ++++++++++- helm-chart/binderhub/templates/deployment.yaml | 12 ++++++++++++ helm-chart/binderhub/templates/secret.yaml | 6 ++++++ helm-chart/binderhub/values.yaml | 2 ++ .../k8s-binder-k8s-hub/binderhub-chart-config.yaml | 8 ++++++++ 6 files changed, 41 insertions(+), 1 deletion(-) diff --git a/helm-chart/binderhub/files/binderhub_config.py b/helm-chart/binderhub/files/binderhub_config.py index 2a21602f4..ce270e4cd 100644 --- a/helm-chart/binderhub/files/binderhub_config.py +++ b/helm-chart/binderhub/files/binderhub_config.py @@ -39,6 +39,9 @@ def get_value(key, default=None): 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(): c[section].update(sub_cfg) diff --git a/helm-chart/binderhub/schema.yaml b/helm-chart/binderhub/schema.yaml index f9426845b..e9058b2b9 100644 --- a/helm-chart/binderhub/schema.yaml +++ b/helm-chart/binderhub/schema.yaml @@ -25,6 +25,7 @@ required: - service - config - extraConfig + - templates - jupyterhub - deployment - dind @@ -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 @@ -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 diff --git a/helm-chart/binderhub/templates/deployment.yaml b/helm-chart/binderhub/templates/deployment.yaml index 146e8c057..e3b86a83e 100644 --- a/helm-chart/binderhub/templates/deployment.yaml +++ b/helm-chart/binderhub/templates/deployment.yaml @@ -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: @@ -54,6 +62,7 @@ spec: hostPath: path: /var/run/docker.sock {{- end }} + {{- with .Values.extraVolumes }} {{- . | toYaml | nindent 6 }} {{- end }} @@ -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 diff --git a/helm-chart/binderhub/templates/secret.yaml b/helm-chart/binderhub/templates/secret.yaml index 10905101d..ee905dcee 100644 --- a/helm-chart/binderhub/templates/secret.yaml +++ b/helm-chart/binderhub/templates/secret.yaml @@ -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 }} diff --git a/helm-chart/binderhub/values.yaml b/helm-chart/binderhub/values.yaml index f761505cb..3520a9ff3 100644 --- a/helm-chart/binderhub/values.yaml +++ b/helm-chart/binderhub/values.yaml @@ -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 diff --git a/testing/k8s-binder-k8s-hub/binderhub-chart-config.yaml b/testing/k8s-binder-k8s-hub/binderhub-chart-config.yaml index eade527e0..5ebc794e2 100644 --- a/testing/k8s-binder-k8s-hub/binderhub-chart-config.yaml +++ b/testing/k8s-binder-k8s-hub/binderhub-chart-config.yaml @@ -14,6 +14,14 @@ config: log_level: 10 cors_allow_origin: "*" +templates: + page.html: | + {% extends "templates/page.html" %} + {% block footer %} + {{ super() }} + test-template + {% endblock %} + ingress: # Enabled to test the creation/update of the k8s Ingress resource, but not # used actively in our CI system.