Skip to content

Commit e220ae0

Browse files
committed
Ability to add env var to chart deployment
1 parent 4438c6a commit e220ae0

5 files changed

Lines changed: 31 additions & 18 deletions

File tree

bert_e/server/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ def setup_server(bert_e):
7878
'WTF_CSRF_SECRET_KEY': secrets.token_hex(24),
7979
})
8080

81-
app.wsgi_app = ReverseProxied(app.wsgi_app)
81+
app_prefix = os.getenv('APP_PREFIX', '/')
82+
83+
app.wsgi_app = ReverseProxied(app.wsgi_app, app_prefix)
8284

8385
app.bert_e = bert_e
8486

bert_e/server/reverse_proxy.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,12 @@ class ReverseProxied(object):
2323
- app: the WSGI application
2424
2525
"""
26-
def __init__(self, app):
26+
def __init__(self, app, prefix=""):
2727
self.app = app
28+
self.prefix = prefix
2829

2930
def __call__(self, environ, start_response):
30-
script_name = environ.get('HTTP_X_SCRIPT_NAME', None)
31-
if script_name is not None:
32-
environ['SCRIPT_NAME'] = script_name
33-
path_info = environ['PATH_INFO']
34-
if path_info.startswith(script_name):
35-
path_info = path_info[len(script_name):]
36-
environ['PATH_INFO'] = path_info
37-
38-
scheme = environ.get('HTTP_X_SCHEME', None)
39-
if scheme is not None:
40-
environ['wsgi_url_scheme'] = scheme
41-
42-
server = environ.get('HTTP_X_FORWARDED_SERVER', None)
43-
if server:
44-
environ['HTTP_HOST'] = server
45-
31+
if environ['PATH_INFO'].startswith(self.prefix):
32+
environ['PATH_INFO'] = environ['PATH_INFO'][len(self.prefix):]
33+
environ['SCRIPT_NAME'] = self.prefix
4634
return self.app(environ, start_response)

charts/bert-e/templates/deployment.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spec:
2222
annotations:
2323
checksum/settings: {{ include (print $.Template.BasePath "/settings.yaml") . | sha256sum }}
2424
checksum/secret: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }}
25+
checksum/env: {{ include (print $.Template.BasePath "/env.yaml") . | sha256sum }}
2526
spec:
2627
{{- if .Values.image.pullSecrets }}
2728
imagePullSecrets:
@@ -36,6 +37,10 @@ spec:
3637
envFrom:
3738
- secretRef:
3839
name: {{ template "fullname" $ }}
40+
{{- if .Values.deployment.env }}
41+
- configMapRef:
42+
name: {{ template "fullname" $ }}-env
43+
{{- end }}
3944
ports:
4045
- name: http
4146
containerPort: {{ .Values.deployment.servicePort }}

charts/bert-e/templates/env.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- if .Values.deployment.env }}
2+
---
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: {{ template "fullname" $ }}-env
7+
labels:
8+
app: {{ template "fullname" $ }}
9+
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
10+
release: "{{ .Release.Name }}"
11+
heritage: "{{ .Release.Service }}"
12+
type: Opaque
13+
data:
14+
{{ .Values.deployment.env | toYaml | indent 2 }}
15+
{{- end }}

charts/bert-e/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ image:
313313

314314
## Kubernetes deployment configuration
315315
deployment:
316+
# Setup env vars on the deployment
317+
env: {}
318+
# MY_VAR: MY_VALUE
316319

317320
## Configure extra options for liveness and readiness probes
318321
livenessProbe:

0 commit comments

Comments
 (0)