From 35525ce926305a5250250f6bebc43d57234bcefe Mon Sep 17 00:00:00 2001 From: Sangho Na Date: Wed, 15 May 2024 23:37:32 +1200 Subject: [PATCH] feat: Define cron jobs running mgmt commands in Helm chart (#440) * feat: Define cron jobs running mgmt commands in Helm chart * chore: Use UTC for cron jobs * chore: Prevent cron jobs from overlapping * chore: Disable retries on failed jobs --- helm/templates/cronjob.yaml | 42 +++++++++++++++++++++++++++++++++++++ helm/values.yaml | 25 +++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 helm/templates/cronjob.yaml diff --git a/helm/templates/cronjob.yaml b/helm/templates/cronjob.yaml new file mode 100644 index 00000000..9928ff71 --- /dev/null +++ b/helm/templates/cronjob.yaml @@ -0,0 +1,42 @@ +{{- range .Values.cronjob.crons }} +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ .name | quote }} +spec: + schedule: {{ .schedule | quote }} + timeZone: {{ .timeZone | quote }} + concurrencyPolicy: Forbid + jobTemplate: + spec: + backoffLimit: 0 # No retries + template: + spec: + restartPolicy: Never + volumes: + - name: settings-local-volume + configMap: + name: django-configmap + containers: + - name: {{ .name | quote }} + image: "{{ .image.repository }}:{{ default $.Chart.AppVersion .image.tag }}" + imagePullPolicy: {{ .image.pullPolicy }} + volumeMounts: + - name: settings-local-volume + mountPath: /app/ietf/settings/local.py + subPath: local.py + readOnly: true + {{- if $.Values.env }} + env: + - name: "POD_IP" + valueFrom: + fieldRef: + fieldPath: status.podIP + {{- range $key, $val := $.Values.env }} + - name: {{ $key | quote }} + value: {{ $val | quote }} + {{- end }} + {{- end }} + command: {{ .command | toJson }} +{{- end }} diff --git a/helm/values.yaml b/helm/values.yaml index 0a84c470..0add2a9c 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -24,7 +24,7 @@ wagtail: repository: "ghcr.io/ietf-tools/www" pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. - # tag: "v2.1.3" + # tag: "v2.1.10" imagePullSecrets: [] nameOverride: "" @@ -199,6 +199,29 @@ memcached: affinity: {} +# ------------------------------------------------------------- +# SCHEDULED JOBS +# ------------------------------------------------------------- + +cronjob: + crons: + - name: mgmt-hourly + schedule: "0 * * * *" # "At minute 0." + timeZone: "Etc/UTC" + image: + repository: "ghcr.io/ietf-tools/www" + pullPolicy: IfNotPresent + # tag: "v2.1.10" + command: ["python", "/app/manage.py", "publish_scheduled"] + - name: mgmt-weekly + schedule: "30 0 * * 0" # "At 00:30 on Sunday." + timeZone: "Etc/UTC" + image: + repository: "ghcr.io/ietf-tools/www" + pullPolicy: IfNotPresent + # tag: "v2.1.10" + command: ["python", "/app/manage.py", "update_index"] + # ------------------------------------------------------------- # COMMON # -------------------------------------------------------------