Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(helm): Helm template for Celery beat (for reporting and alerting) #13116

Merged
merged 14 commits into from
Feb 16, 2021
95 changes: 95 additions & 0 deletions helm/superset/templates/deployment-beat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{{- if .Values.supersetBeat.enabled -}}
Yann-J marked this conversation as resolved.
Show resolved Hide resolved
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "superset.fullname" . }}-beat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially named the pods the same way you did, but some colleague said that beat is kind of generic, and it would be better naming it {{ template "superset.fullname" . }}-celerybeat.
I let you judge 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense...

labels:
app: {{ template "superset.name" . }}-beat
chart: {{ template "superset.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
# This must be a singleton
replicas: 1
selector:
matchLabels:
app: {{ template "superset.name" . }}-beat
release: {{ .Release.Name }}
template:
metadata:
annotations:
checksum/superset_config.py: {{ include "superset-config" . | sha256sum }}
checksum/connections: {{ .Values.supersetNode.connections | toYaml | sha256sum }}
checksum/extraConfigs: {{ .Values.extraConfigs | toYaml | sha256sum }}
checksum/extraSecretEnv: {{ .Values.extraSecretEnv | toYaml | sha256sum }}
checksum/configOverrides: {{ .Values.configOverrides | toYaml | sha256sum }}
{{ if .Values.supersetBeat.forceReload }}
Yann-J marked this conversation as resolved.
Show resolved Hide resolved
# Optionally force the thing to reload
force-reload: {{ randAlphaNum 5 | quote }}
{{ end }}
labels:
app: {{ template "superset.name" . }}-beat
release: {{ .Release.Name }}
spec:
securityContext:
runAsUser: 0 # Needed in order to allow pip install to work in bootstrap
{{- if .Values.supersetBeat.initContainers }}
Yann-J marked this conversation as resolved.
Show resolved Hide resolved
initContainers:
{{- tpl (toYaml .Values.supersetBeat.initContainers) . | nindent 6 }}
Yann-J marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: {{ tpl (toJson .Values.supersetBeat.command) . }}
Yann-J marked this conversation as resolved.
Show resolved Hide resolved
env:
- 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: {{ .Values.configMountPath | quote }}
readOnly: true
resources:
{{ toYaml .Values.resources | indent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
volumes:
- name: superset-config
secret:
secretName: {{ tpl .Values.configFromSecret . }}
{{- end -}}
9 changes: 7 additions & 2 deletions helm/superset/templates/deployment-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ spec:
release: {{ .Release.Name }}
template:
metadata:
{{ if .Values.supersetWorker.forceReload }}
annotations:
checksum/superset_config.py: {{ include "superset-config" . | sha256sum }}
checksum/connections: {{ .Values.supersetNode.connections | toYaml | sha256sum }}
checksum/extraConfigs: {{ .Values.extraConfigs | toYaml | sha256sum }}
checksum/extraSecretEnv: {{ .Values.extraSecretEnv | toYaml | sha256sum }}
checksum/configOverrides: {{ .Values.configOverrides | toYaml | sha256sum }}
Comment on lines +35 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[K8S newbie] What's the point of those annotations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since those values will change on any content updates of the source values, this will force a patch of the Deployment, and a restart of the pods whenever we publish an update to these (otherwise, updates to a ConfigMap does not automatically force the pods mounting them to restart).

{{ if .Values.supersetWorker.forceReload }}
# Optionally force the thing to reload
force-reload: {{ randAlphaNum 5 | quote }}
{{ end }}
{{ end }}
labels:
app: {{ template "superset.name" . }}-worker
release: {{ .Release.Name }}
Expand Down
6 changes: 4 additions & 2 deletions helm/superset/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ spec:
checksum/superset_bootstrap.sh: {{ include "superset-bootstrap" . | sha256sum }}
checksum/connections: {{ .Values.supersetNode.connections | toYaml | sha256sum }}
checksum/extraConfigs: {{ .Values.extraConfigs | toYaml | sha256sum }}
checksum/extraSecretEnv: {{ .Values.extraSecretEnv | toYaml | sha256sum }}
checksum/configOverrides: {{ .Values.configOverrides | toYaml | sha256sum }}
{{- if .Values.supersetNode.forceReload }}
# Optionally force the thing to reload unconditionally
# Optionally force the thing to reload
force-reload: {{ randAlphaNum 5 | quote }}
{{- end }}
{{- end }}
labels:
app: {{ template "superset.name" . }}
release: {{ .Release.Name }}
Expand Down
19 changes: 19 additions & 0 deletions helm/superset/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ supersetWorker:
name: '{{ tpl .Values.envFromSecret . }}'
command: [ "/bin/sh", "-c", "until nc -zv $DB_HOST $DB_PORT -w1; do echo 'waiting for db'; sleep 1; done" ]

##
## Superset beat configuration (to trigger scheduled jobs like reports)
supersetBeat:
Yann-J marked this conversation as resolved.
Show resolved Hide resolved
# this is only required if you intend to use reports and alerts (?)
Yann-J marked this conversation as resolved.
Show resolved Hide resolved
enabled: false
command:
- "/bin/sh"
- "-c"
- ". {{ .Values.configMountPath }}/superset_bootstrap.sh; celery beat --app=superset.tasks.celery_app:app --pidfile /tmp/celerybeat.pid --schedule /tmp/celerybeat-schedule"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no trace of flower in the master chart in fact 😮 To add it, we should do something really similar to this PR, plus a service dedicated to flower.
I think this is out of the scope of this PR, my team will switch back to the master charts, and we will open PR to add what's missing, but not sure when this will be. 😕
If you have some time to do it, I would gladly help!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, different PR... and probably not high prio...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, but flower by default does not support auth, and it exposes dangerous functionality and sensitive info. May be a bit out of scope

forceReload: false # If true, forces deployment to reload on each upgrade
initContainers:
- name: wait-for-postgres
image: busybox:latest
imagePullPolicy: IfNotPresent
envFrom:
- secretRef:
name: '{{ tpl .Values.envFromSecret . }}'
command: [ "/bin/sh", "-c", "until nc -zv $DB_HOST $DB_PORT -w1; do echo 'waiting for db'; sleep 1; done" ]

##
## Init job configuration
init:
Expand Down