Skip to content

Commit

Permalink
extraFiles: accept explicit file name
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jan 27, 2021
1 parent d8abad9 commit 53f7cc4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
10 changes: 6 additions & 4 deletions dev-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ hub:
mountPath: /tmp/
mode: 0666
binaryData: aGVsbG8gd29ybGQhCg==
binaryData2.txt: &binaryData2
binaryData-explicit-name.txt: &binaryData2
name: binaryData.txt
mountPath: /tmp/dir1
mode: 0666
binaryData: aGVsbG8gd29ybGQhCg==
stringData.txt: &stringData
mountPath: /tmp
mode: 0666
stringData: hello world!
stringData2.txt: &stringData2
stringData-explicit-name.txt: &stringData2
name: stringData.txt
mountPath: /tmp/dir1/
mode: 0666
stringData: hello world!
Expand All @@ -81,9 +83,9 @@ hub:
singleuser:
extraFiles:
binaryData.txt: *binaryData
binaryData2.txt: *binaryData2
binaryData-explicit-name.txt: *binaryData2
stringData.txt: *stringData
stringData2.txt: *stringData2
stringData-explicit-name.txt: *stringData2
data.yaml: *data
data.yml: *data
data.json: *data
Expand Down
14 changes: 9 additions & 5 deletions jupyterhub/files/hub/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,13 @@ def camelCaseify(s):
"name": "files",
}
items = []
for file_name, file_details in extra_files.items():
for file_key, file_details in extra_files.items():
# Each item is a mapping of a key in the k8s Secret to a path in this
# abstract volume, the goal is to enable us to set the mode /
# permissions only though so we don't change the mapping.
item = {
"key": file_name,
"path": file_name,
"key": file_key,
"path": file_key,
}
if "mode" in file_details:
item["mode"] = file_details["mode"]
Expand All @@ -302,11 +305,12 @@ def camelCaseify(s):
c.KubeSpawner.volumes.append(volume)

volume_mounts = []
for file_name, file_details in extra_files.items():
for file_key, file_details in extra_files.items():
file_name = file_details.get("name", file_key)
volume_mounts.append(
{
"mountPath": file_details["mountPath"].rstrip("/") + "/" + file_name,
"subPath": file_name,
"subPath": file_key,
"name": "files",
}
)
Expand Down
11 changes: 6 additions & 5 deletions jupyterhub/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ true
binaryData entries.
*/}}
{{- define "jupyterhub.extraFiles.data.withNewLineSuffix" -}}
{{- range $file_name, $file_details := . }}
{{- range $file_key, $file_details := . }}
{{- if $file_details.binaryData }}
{{- $file_name | quote }}: {{ $file_details.binaryData | trimSuffix "\n" | quote }}{{ println }}
{{- $file_key | quote }}: {{ $file_details.binaryData | trimSuffix "\n" | quote }}{{ println }}
{{- end }}
{{- end }}
{{- end }}
Expand All @@ -347,13 +347,14 @@ true
with either data or stringData entries.
*/}}
{{- define "jupyterhub.extraFiles.stringData.withNewLineSuffix" -}}
{{- range $file_name, $file_details := . }}
{{- range $file_key, $file_details := . }}
{{- $file_name := $file_details.name | default $file_key }}
{{- if $file_details.stringData }}
{{- $file_name | quote }}: |
{{- $file_key | quote }}: |
{{- $file_details.stringData | trimSuffix "\n" | nindent 2 }}{{ println }}
{{- end }}
{{- if $file_details.data }}
{{- $file_name | quote }}: |
{{- $file_key | quote }}: |
{{- if or (eq (ext $file_name) ".yaml") (eq (ext $file_name) ".yml") }}
{{- $file_details.data | toYaml | trimSuffix "\n" | nindent 2 }}{{ println }}
{{- else if eq (ext $file_name) ".json" }}
Expand Down
11 changes: 6 additions & 5 deletions jupyterhub/templates/hub/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ spec:
secret:
secretName: {{ include "jupyterhub.hub-secret.fullname" . }}
items:
{{- range $file_name, $file_details := .Values.hub.extraFiles }}
- key: {{ $file_name | quote }}
path: {{ $file_name | quote }}
{{- range $file_key, $file_details := .Values.hub.extraFiles }}
- key: {{ $file_key | quote }}
path: {{ $file_key | quote }}
{{- with $file_details.mode }}
mode: {{ . }}
{{- end }}
Expand Down Expand Up @@ -146,9 +146,10 @@ spec:
name: config
- mountPath: /etc/jupyterhub/secret/
name: secret
{{- range $file_name, $file_details := .Values.hub.extraFiles }}
{{- range $file_key, $file_details := .Values.hub.extraFiles }}
{{- $file_name := $file_details.name | default $file_key }}
- mountPath: {{ $file_details.mountPath | trimSuffix "/" }}/{{ $file_name }}
subPath: {{ $file_name | quote }}
subPath: {{ $file_key | quote }}
name: files
{{- end }}
{{- with .Values.hub.extraVolumeMounts }}
Expand Down
6 changes: 4 additions & 2 deletions tools/templates/lint-and-validate-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ hub:
mountPath: /tmp/
mode: 0666
binaryData: aGVsbG8gd29ybGQhCg== # "hello world!" base64 encoded
binaryData2.txt:
binaryData-explicit-name.txt:
name: binaryData.txt
mountPath: /tmp/dir1
mode: 0666
binaryData: aGVsbG8gd29ybGQhCg== # "hello world!" base64 encoded
stringData.txt:
mountPath: /tmp
mode: 0666
stringData: hello world!
stringData2.txt:
stringData-explicit-name.txt:
name: stringData.txt
mountPath: /tmp/dir1/
mode: 0666
stringData: hello world!
Expand Down

0 comments on commit 53f7cc4

Please sign in to comment.