From b3b4d324b437c40c173996e3b7524adcd851456f Mon Sep 17 00:00:00 2001 From: Arie Peterson <arie@greenhost.nl> Date: Wed, 14 Jul 2021 14:57:29 +0200 Subject: [PATCH] Allow custom cron jobs --- README.md | 5 +++-- templates/cron-schedule.yaml | 5 ++++- templates/statefulset.yaml | 2 +- values-local.yaml.example | 5 +++++ values.yaml | 2 ++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9303aa9..dc48a67 100644 --- a/README.md +++ b/README.md @@ -91,8 +91,9 @@ $ kubectl logs <pod> -c init-wordpress Helm will set up the kubernetes pods that are needed to run your website: 1. A WordPress pod that serves the site - - If you enabled `backup.enabled` or `wordpress.mu_cron.enabled`, this pod - will also contain a sidecar container that runs cron jobs. + - If you have `backup.enabled` or `wordpress.mu_cron.enabled`, or have a + non-empty `customCron`, this pod will also contain a sidecar container that + runs cron jobs. 2. Two MariaDB pods running the database (master-slave setup by default, unless you changed this in `values-local.yaml`) 3. If you configured Redis, a Redis pod is also set up diff --git a/templates/cron-schedule.yaml b/templates/cron-schedule.yaml index 88beda8..a9ab91a 100644 --- a/templates/cron-schedule.yaml +++ b/templates/cron-schedule.yaml @@ -13,5 +13,8 @@ data: {{ .Values.wordpress.mu_cron.cronjob.schedule }} curl -s -w '%{http_code}' {{- if .Values.wordpress.mu_cron.cronjob.curlInsecure }} -k {{- end }} -L 'http://{{ include "wordpress.fullname" . }}:{{ .Values.service.port }}{{ .Values.wordpress.mu_cron.cronjob.path }}?doing_wp_cron&{{ required "Please set wordpress.mu_cron.secret to a random secret" .Values.wordpress.mu_cron.secret }}' {{- end }} {{- if .Values.backup.enabled }} - {{ .Values.backup.schedule }} cd /var/local/ansible && ansible-playbook backup.yml -e @secrets/secret-vars.yaml + {{ .Values.backup.schedule }} cd /var/local/ansible && ansible-playbook backup.yml -e @secrets/secret-vars.yaml +{{- end }} +{{- range .Values.customCron }} + {{ .schedule }} {{ .command }} {{- end }} diff --git a/templates/statefulset.yaml b/templates/statefulset.yaml index f2666d5..ca2a948 100644 --- a/templates/statefulset.yaml +++ b/templates/statefulset.yaml @@ -128,7 +128,7 @@ spec: subPath: .htaccess resources: {{ toYaml .Values.resources | indent 12 }} - {{- if or .Values.backup.enabled .Values.wordpress.mu_cron.enabled }} + {{- if or .Values.backup.enabled .Values.wordpress.mu_cron.enabled .Values.customCron }} - name: {{ .Chart.Name }}-cron image: "{{ .Values.initImage.repository }}:{{ .Values.initImage.tag }}" imagePullPolicy: {{ .Values.initImage.pullPolicy }} diff --git a/values-local.yaml.example b/values-local.yaml.example index 396de73..51f827c 100644 --- a/values-local.yaml.example +++ b/values-local.yaml.example @@ -180,6 +180,11 @@ redis: # # The cron schedule that determines when backups are made. # # Run at 3:37 every day. # schedule: "37 3 * * *" + +# customCron: +# - schedule: "5 * * * *" +# command: "echo test" + # It's advisable to set resource limits to prevent your K8s cluster from # crashing # resources: diff --git a/values.yaml b/values.yaml index 5acf023..3c09437 100644 --- a/values.yaml +++ b/values.yaml @@ -319,6 +319,8 @@ backup: schedule: "0 2 * * *" isDate: true +customCron: [] + wpSalts: {} # Some of the variables configured above are put into a variable here, that's -- GitLab