Skip to content

Commit

Permalink
[Helm] - Allow for customization of release name (apache#9694)
Browse files Browse the repository at this point in the history
* Updated configurations to allow for more customization

* Adding gitignore for requirements.lock

* Moving Helm chart up a level

* Adding bootstrap script / switching image

* Adding bootstrap script / switching image
  • Loading branch information
craig-rueda authored Apr 30, 2020
1 parent 2b59075 commit e24e6ca
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 128 deletions.
4 changes: 4 additions & 0 deletions helm/superset/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
charts

# Don't require this to be pushed, as it will require things to be kept in sync and linted
requirements.lock
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,51 @@ Create chart name and version as used by the chart label.
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "superset-connections.script" }}
{{- define "superset-bootstrap" }}
#!/bin/sh

pip install {{ range .Values.additionalRequirements }}{{ . }} {{ end }}

{{ end -}}

{{- define "superset-config" }}
import os
from werkzeug.contrib.cache import RedisCache
MAPBOX_API_KEY = os.getenv('MAPBOX_API_KEY', '')

def env(key, default=None):
return os.getenv(key, default)

MAPBOX_API_KEY = env('MAPBOX_API_KEY', '')
CACHE_CONFIG = {
'CACHE_TYPE': 'redis',
'CACHE_DEFAULT_TIMEOUT': 300,
'CACHE_KEY_PREFIX': 'superset_',
'CACHE_REDIS_HOST': os.getenv('REDIS_HOST'),
'CACHE_REDIS_PORT': os.getenv('REDIS_PORT'),
'CACHE_REDIS_HOST': env('REDIS_HOST'),
'CACHE_REDIS_PORT': env('REDIS_PORT'),
'CACHE_REDIS_DB': 1,
'CACHE_REDIS_URL': 'redis://%s:%s/1' % (os.getenv('REDIS_HOST'),os.getenv('REDIS_PORT'))}
SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://%s:%s@%s:%s/%s' % (os.getenv('DB_USER'), os.getenv('DB_PASS'), os.getenv('DB_HOST'), os.getenv('DB_PORT'), os.getenv('DB_NAME'))
'CACHE_REDIS_URL': f"redis://{env('REDIS_HOST')}:{env('REDIS_PORT')}/1"
}

SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{env('DB_USER')}:{env('DB_PASS')}@{env('DB_HOST')}:{env('DB_PORT')}/{env('DB_NAME')}"
SQLALCHEMY_TRACK_MODIFICATIONS = True
SECRET_KEY = 'thisISaSECRET_1234'
SECRET_KEY = env('SECRET_KEY', 'thisISaSECRET_1234')

# Flask-WTF flag for CSRF
WTF_CSRF_ENABLED = True
# Add endpoints that need to be exempt from CSRF protection
WTF_CSRF_EXEMPT_LIST = []
# A CSRF token that expires in 1 year
WTF_CSRF_TIME_LIMIT = 60 * 60 * 24 * 365
class CeleryConfig(object):
BROKER_URL = 'redis://%s:%s/0' % (os.getenv('REDIS_HOST'),os.getenv('REDIS_PORT'))
BROKER_URL = f"redis://{env('REDIS_HOST')}:{env('REDIS_PORT')}/0"
CELERY_IMPORTS = ('superset.sql_lab', )
CELERY_RESULT_BACKEND = 'redis://%s:%s/0' % (os.getenv('REDIS_HOST'),os.getenv('REDIS_PORT'))
CELERY_RESULT_BACKEND = f"redis://{env('REDIS_HOST')}:{env('REDIS_PORT')}/0"
CELERY_ANNOTATIONS = {'tasks.add': {'rate_limit': '10/s'}}

CELERY_CONFIG = CeleryConfig
RESULTS_BACKEND = RedisCache(
host= os.getenv('REDIS_HOST'),
port= os.getenv('REDIS_PORT'),
host=env('REDIS_HOST'),
port=env('REDIS_PORT'),
key_prefix='superset_results'
)
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
apiVersion: apps/v1beta2
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "superset.fullname" . }}
Expand All @@ -35,53 +35,36 @@ spec:
app: {{ template "superset.name" . }}
release: {{ .Release.Name }}
spec:
securityContext:
runAsUser: 0 # Needed in order to allow pip install to work in bootstrap
{{- if .Values.supersetNode.initContainers }}
initContainers:
{{- tpl (toYaml .Values.supersetNode.initContainers) . | nindent 6 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: {{ tpl (toJson .Values.supersetNode.command) . }}
env:
- name: REDIS_HOST
valueFrom:
secretKeyRef:
name: superset-secret
key: redis_host
- name: REDIS_PORT
valueFrom:
secretKeyRef:
name: superset-secret
key: redis_port
- name: DB_HOST
valueFrom:
secretKeyRef:
name: superset-secret
key: db_host
- name: DB_PORT
valueFrom:
secretKeyRef:
name: superset-secret
key: db_port
- name: DB_USER
valueFrom:
secretKeyRef:
name: superset-secret
key: db_user
- name: DB_PASS
valueFrom:
secretKeyRef:
name: superset-secret
key: db_pass
- name: DB_NAME
valueFrom:
secretKeyRef:
name: superset-secret
key: db_name
- name: "SUPERSET_PORT"
value: {{ .Values.service.port | quote}}
{{ if .Values.extraEnv }}
{{- range $key, $value := .Values.extraEnv }}
- name: {{ $key | quote}}
value: {{ $value | quote }}
{{- end }}
{{- end }}
envFrom:
- secretRef:
name: {{ tpl .Values.envFromSecret . | quote }}
volumeMounts:
- name: superset-config
mountPath: "/etc/superset"
mountPath: {{ .Values.configMountPath | quote }}
readOnly: true
ports:
- name: http
containerPort: 8088
containerPort: {{ .Values.service.port }}
protocol: TCP
resources:
{{ toYaml .Values.resources | indent 12 }}
Expand All @@ -100,4 +83,4 @@ spec:
volumes:
- name: superset-config
secret:
secretName: superset-config
secretName: {{ tpl .Values.configFromSecret . }}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,44 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
{{- if and ( .Values.initContainers ) ( .Values.init.enabled ) }}
{{- if .Values.init.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ template "superset.name" . }}-init-db
annotations:
spec:
template:
metadata:
name: {{ template "superset.name" . }}-init-db
spec:
securityContext:
runAsUser: 0 # Needed in order to allow pip install to work in bootstrap
{{- if .Values.init.initContainers }}
initContainers:
{{- toYaml .Values.initContainers | nindent 6 }}
{{- tpl (toYaml .Values.init.initContainers) . | nindent 6 }}
{{- end }}
containers:
- name: {{ template "superset.name" . }}-init-db
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
{{ if .Values.extraEnv }}
env:
- name: REDIS_HOST
valueFrom:
secretKeyRef:
name: superset-secret
key: redis_host
- name: REDIS_PORT
valueFrom:
secretKeyRef:
name: superset-secret
key: redis_port
- name: DB_HOST
valueFrom:
secretKeyRef:
name: superset-secret
key: db_host
- name: DB_PORT
valueFrom:
secretKeyRef:
name: superset-secret
key: db_port
- name: DB_USER
valueFrom:
secretKeyRef:
name: superset-secret
key: db_user
- name: DB_PASS
valueFrom:
secretKeyRef:
name: superset-secret
key: db_pass
- name: DB_NAME
valueFrom:
secretKeyRef:
name: superset-secret
key: db_name
{{- range $key, $value := .Values.extraEnv }}
- name: {{ $key | quote }}
value: {{ $value | quote }}
{{- end }}
{{- end }}
envFrom:
- secretRef:
name: {{ tpl .Values.envFromSecret . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: superset-config
mountPath: "/etc/superset"
mountPath: {{ .Values.configMountPath | quote }}
readOnly: true
command: [ "/bin/sh", "-c", "{{ .Values.init.initscript }}" ]
command: {{ tpl (toJson .Values.init.command) . }}
volumes:
- name: superset-config
secret:
secretName: superset-config
secretName: {{ tpl .Values.configFromSecret . }}
restartPolicy: Never
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ template "superset.fullname" . }}-secret
name: {{ template "superset.fullname" . }}-env
labels:
app: {{ template "superset.fullname" . }}
chart: {{ template "superset.chart" . }}
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
type: Opaque
data:
redis_host: {{ .Values.supersetNode.connections.redis_host | b64enc | quote }}
redis_port: {{ .Values.supersetNode.connections.redis_port | b64enc | quote }}
db_host: {{ .Values.supersetNode.connections.db_host | b64enc | quote }}
db_port: {{ .Values.supersetNode.connections.db_port | b64enc | quote }}
db_user: {{ .Values.supersetNode.connections.db_user | b64enc | quote }}
db_pass: {{ .Values.supersetNode.connections.db_pass | b64enc | quote }}
db_name: {{ .Values.supersetNode.connections.db_name | b64enc | quote }}
REDIS_HOST: {{ tpl .Values.supersetNode.connections.redis_host . | b64enc | quote }}
REDIS_PORT: {{ .Values.supersetNode.connections.redis_port | b64enc | quote }}
DB_HOST: {{ tpl .Values.supersetNode.connections.db_host . | b64enc | quote }}
DB_PORT: {{ .Values.supersetNode.connections.db_port | b64enc | quote }}
DB_USER: {{ .Values.supersetNode.connections.db_user | b64enc | quote }}
DB_PASS: {{ .Values.supersetNode.connections.db_pass | b64enc | quote }}
DB_NAME: {{ .Values.supersetNode.connections.db_name | b64enc | quote }}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ metadata:
heritage: "{{ .Release.Service }}"
type: Opaque
data:
superset_config.py: {{ include "superset-connections.script" . | b64enc }}
superset_config.py: {{ include "superset-config" . | b64enc }}
superset_init.sh: {{ tpl .Values.init.initscript . | b64enc }}
superset_bootstrap.sh: {{ include "superset-bootstrap" . | b64enc }}
File renamed without changes.
Loading

0 comments on commit e24e6ca

Please sign in to comment.