Skip to content

Commit 66ca304

Browse files
authored
Merge pull request #1179 from consideRatio/pr/merge-config-sources
Reduce complexity by merging configmap/secret into secret
2 parents 26df09a + 51b7354 commit 66ca304

File tree

4 files changed

+25
-79
lines changed

4 files changed

+25
-79
lines changed

helm-chart/binderhub/files/binderhub_config.py

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,21 @@
1-
import os
2-
from collections.abc import Mapping
31
from functools import lru_cache
42
from urllib.parse import urlparse
53

64
from ruamel.yaml import YAML
75

86
yaml = YAML(typ="safe")
97

10-
11-
def _merge_dictionaries(a, b):
12-
"""Merge two dictionaries recursively.
13-
14-
Simplified From https://stackoverflow.com/a/7205107
15-
"""
16-
merged = a.copy()
17-
for key in b:
18-
if key in a:
19-
if isinstance(a[key], Mapping) and isinstance(b[key], Mapping):
20-
merged[key] = _merge_dictionaries(a[key], b[key])
21-
else:
22-
merged[key] = b[key]
23-
else:
24-
merged[key] = b[key]
25-
return merged
26-
27-
288
# memoize so we only load config once
299
@lru_cache()
3010
def _load_values():
3111
"""Load configuration from disk
3212
3313
Memoized to only load once
3414
"""
35-
cfg = {}
36-
for source in ("config", "secret"):
37-
path = f"/etc/binderhub/{source}/values.yaml"
38-
if os.path.exists(path):
39-
print(f"Loading {path}")
40-
with open(path) as f:
41-
values = yaml.load(f)
42-
cfg = _merge_dictionaries(cfg, values)
43-
else:
44-
print(f"No config at {path}")
45-
return cfg
15+
path = "/etc/binderhub/config/values.yaml"
16+
print(f"Loading {path}")
17+
with open(path) as f:
18+
return yaml.load(f)
4619

4720

4821
def get_value(key, default=None):

helm-chart/binderhub/templates/configmap.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

helm-chart/binderhub/templates/deployment.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ spec:
2727
{{- . | toYaml | nindent 8 }}
2828
{{- end }}
2929
annotations:
30-
# This lets us autorestart when the configmap changes!
31-
checksum/config-map: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
32-
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
30+
# This lets us autorestart when the secret's pass-through config changes
31+
checksum/config: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
3332
{{- with .Values.podAnnotations }}
3433
{{- . | toYaml | nindent 8 }}
3534
{{- end }}
@@ -44,9 +43,6 @@ spec:
4443
{{- end }}
4544
volumes:
4645
- name: config
47-
configMap:
48-
name: binder-config
49-
- name: secret-config
5046
secret:
5147
secretName: binder-secret
5248
{{- if .Values.config.BinderHub.use_registry }}
@@ -74,8 +70,7 @@ spec:
7470
volumeMounts:
7571
- mountPath: /etc/binderhub/config/
7672
name: config
77-
- mountPath: /etc/binderhub/secret/
78-
name: secret-config
73+
readOnly: true
7974
{{- if .Values.config.BinderHub.use_registry }}
8075
- mountPath: /root/.docker
8176
name: docker-secret

helm-chart/binderhub/templates/secret.yaml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1+
{{- /*
2+
Note that changes to the rendered version of this
3+
file will trigger a restart of the BinderHub pod
4+
through a annotation containing a hash of this
5+
file rendered.
6+
*/ -}}
17
kind: Secret
28
apiVersion: v1
39
metadata:
410
name: binder-secret
511
type: Opaque
6-
data:
7-
{{- $values := dict "config" dict }}
8-
{{- $cfg := .Values.config }}
9-
{{- /* every 'pick' here should be matched with a corresponding 'omit' in secret.yaml */ -}}
10-
{{- if $cfg.GitHubRepoProvider }}
11-
{{- $_ := set $values.config "GitHubRepoProvider" (pick $cfg.GitHubRepoProvider "client_id" "client_secret" "access_token") }}
12-
{{- end }}
13-
{{- if $cfg.GitLabRepoProvider }}
14-
{{- $_ := set $values.config "GitLabRepoProvider" (pick $cfg.GitLabRepoProvider "access_token" "private_token") }}
15-
{{- end }}
16-
values.yaml: {{ $values | toYaml | b64enc | quote }}
12+
stringData:
13+
{{- /*
14+
Stash away relevant Helm template values for
15+
the BinderHub Python application to read from
16+
in binderhub_config.py.
17+
*/}}
18+
values.yaml: |
19+
{{- pick .Values "config" "cors" "dind" "extraConfig" | toYaml | nindent 4 }}
20+
21+
{{- /* Glob files to allow them to be mounted by the binderhub pod */}}
22+
{{- /* key=filename: value=content */}}
23+
{{- (.Files.Glob "files/*").AsConfig | nindent 2 }}
1724
---
1825
{{- if or .Values.config.BinderHub.use_registry .Values.config.BinderHub.buildDockerConfig }}
1926
kind: Secret

0 commit comments

Comments
 (0)