From 917ef86111843d1c691ccb78ce409f9e828df8ed Mon Sep 17 00:00:00 2001 From: Sangho Na Date: Fri, 10 May 2024 13:23:03 +1200 Subject: [PATCH 1/4] feat: Define cron jobs running mgmt commands in Helm chart --- helm/templates/cronjob.yaml | 39 +++++++++++++++++++++++++++++++++++++ helm/values.yaml | 23 +++++++++++++++++++++- 2 files changed, 61 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..1e9bb02e --- /dev/null +++ b/helm/templates/cronjob.yaml @@ -0,0 +1,39 @@ +{{- range .Values.cronjob.crons }} +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ .name | quote }} +spec: + schedule: {{ .schedule | quote }} + jobTemplate: + spec: + 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..69cb14e7 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,27 @@ memcached: affinity: {} +# ------------------------------------------------------------- +# SCHEDULED JOBS +# ------------------------------------------------------------- + +cronjob: + crons: + - name: mgmt-hourly + schedule: "0 * * * *" + image: + repository: "ghcr.io/ietf-tools/www" + pullPolicy: IfNotPresent + # tag: "v2.1.10" + command: ["python", "/app/manage.py", "publish_scheduled"] + - name: mgmt-weekly + schedule: "0 0 * * 0" + image: + repository: "ghcr.io/ietf-tools/www" + pullPolicy: IfNotPresent + # tag: "v2.1.10" + command: ["python", "/app/manage.py", "update_index"] + # ------------------------------------------------------------- # COMMON # ------------------------------------------------------------- From f801e5edfadf26cd62e54811cce8c9f37471be6f Mon Sep 17 00:00:00 2001 From: Sangho Na Date: Fri, 10 May 2024 16:26:19 +1200 Subject: [PATCH 2/4] chore: Use UTC for cron jobs --- helm/templates/cronjob.yaml | 1 + helm/values.yaml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/helm/templates/cronjob.yaml b/helm/templates/cronjob.yaml index 1e9bb02e..f31ac555 100644 --- a/helm/templates/cronjob.yaml +++ b/helm/templates/cronjob.yaml @@ -6,6 +6,7 @@ metadata: name: {{ .name | quote }} spec: schedule: {{ .schedule | quote }} + timeZone: {{ .timeZone | quote }} jobTemplate: spec: template: diff --git a/helm/values.yaml b/helm/values.yaml index 69cb14e7..8fcbb2f6 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -207,6 +207,7 @@ cronjob: crons: - name: mgmt-hourly schedule: "0 * * * *" + timeZone: "Etc/UTC" image: repository: "ghcr.io/ietf-tools/www" pullPolicy: IfNotPresent @@ -214,6 +215,7 @@ cronjob: command: ["python", "/app/manage.py", "publish_scheduled"] - name: mgmt-weekly schedule: "0 0 * * 0" + timeZone: "Etc/UTC" image: repository: "ghcr.io/ietf-tools/www" pullPolicy: IfNotPresent From dd3b8b36d950e667a3a655d5c18448c1671ac453 Mon Sep 17 00:00:00 2001 From: Sangho Na Date: Fri, 10 May 2024 16:40:24 +1200 Subject: [PATCH 3/4] chore: Prevent cron jobs from overlapping --- helm/values.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helm/values.yaml b/helm/values.yaml index 8fcbb2f6..0add2a9c 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -206,7 +206,7 @@ memcached: cronjob: crons: - name: mgmt-hourly - schedule: "0 * * * *" + schedule: "0 * * * *" # "At minute 0." timeZone: "Etc/UTC" image: repository: "ghcr.io/ietf-tools/www" @@ -214,7 +214,7 @@ cronjob: # tag: "v2.1.10" command: ["python", "/app/manage.py", "publish_scheduled"] - name: mgmt-weekly - schedule: "0 0 * * 0" + schedule: "30 0 * * 0" # "At 00:30 on Sunday." timeZone: "Etc/UTC" image: repository: "ghcr.io/ietf-tools/www" From adff04cc19d113249e0bc8d3f41e598f43883e1a Mon Sep 17 00:00:00 2001 From: Sangho Na Date: Mon, 13 May 2024 10:33:00 +1200 Subject: [PATCH 4/4] chore: Disable retries on failed jobs --- helm/templates/cronjob.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/helm/templates/cronjob.yaml b/helm/templates/cronjob.yaml index f31ac555..9928ff71 100644 --- a/helm/templates/cronjob.yaml +++ b/helm/templates/cronjob.yaml @@ -7,8 +7,10 @@ metadata: spec: schedule: {{ .schedule | quote }} timeZone: {{ .timeZone | quote }} + concurrencyPolicy: Forbid jobTemplate: spec: + backoffLimit: 0 # No retries template: spec: restartPolicy: Never