Cron & jobs
The Drupal Operator uses several Kubernetes Jobs and CronJobs to manage:
- Drupal cron
- Automatic database backups
- Automatic files backups
- Database import
- Files import
- Optional locale/translation updates
The main orchestration logic is in roles/setup/tasks/main.yaml.
Drupal cron
Controlled by:
drupal_cron(boolean, defaulttrue)drupal_cron_schedule(default"*/5 * * * *")
When drupal_cron: true, the operator creates a CronJob:
- Name:
<name>-drupal-cron - Namespace: same as the Drupal CR
The CronJob runs Drupal cron on the schedule you specify.
Suspend / resume behavior
In roles/setup/tasks/main.yaml, before imports or major updates the operator:
-
Suspends the Drupal CronJob:
apiVersion: batch/v1 kind: CronJob name: "
-drupal-cron" spec: suspend: true -
Deletes Jobs and Pods created by that CronJob.
After the Drupal Deployment is available again, it:
-
Unsuspends the CronJob:
apiVersion: batch/v1 kind: CronJob name: "
-drupal-cron" spec: suspend: false
This avoids cron tasks running while the site is undergoing imports or upgrades.
Automatic backup CronJobs
Controlled by:
backup_db(boolean, defaultfalse)backup_files(boolean, defaultfalse)backup_db_cron_schedule(default"0 3 * * *")backup_files_cron_schedule(default"0 5 * * *")
When enabled, the operator creates:
-
Database backup CronJob:
- Name:
<name>-auto-db-backup - Template:
templates/automatic-db-backup.yaml.j2
- Name:
-
Files backup CronJob:
- Name:
<name>-auto-files-backup - Template:
templates/automatic-files-backup.yaml.j2
- Name:
These CronJobs typically:
- Use
drupal_backup_secretto get credentials (for S3 or other backends). - Run backup scripts that dump the DB or archive files to external storage.
As with Drupal cron, the operator:
- Suspends these CronJobs before imports/updates.
- Deletes Jobs created by them.
- Unsuspends them after Drupal is ready again.
See Importing DB & files, and backups for more context.
Import Jobs (DB and files)
These are one-shot Jobs, not CronJobs.
-
Database import Job:
- Name:
<name>-db-import - Template:
templates/mariadb-import-job.yml.j2
- Name:
-
Files import Job:
- Name:
<name>-files-import - Template:
templates/files-import-job.yml.j2
- Name:
Creation and execution are driven by:
drupal_import_databaseanddrupal_database_backup_pathdrupal_import_filesanddrupal_files_backup_pathchange_causeand calculated checksums (seeimports-backups.md)
The operator:
- Deletes any existing import Jobs and their Pods.
- Creates new Jobs if the relevant checksum has changed.
-
Uses
kubernetes.core.k8s_infowithuntilto wait until:status.succeeded > 0
-
Updates the
DrupalCR status with timestamps and checksum fields.
Locale update Job
Controlled by:
drupal_locale_update(boolean, defaultfalse)
When drupal_locale_update: true, the operator creates a Job:
- Name:
<name>-drupal-locale-update - Template:
templates/drupal-locale-update-job.yaml.j2
This Job is created after the Drupal Deployment is ready and is meant to handle tasks such as:
- Downloading translation files
- Running
drushcommands to update locale/translation data
In the main tasks:
- Any existing
<name>-drupal-locale-updateJob and its Pods are deleted before a new one is created.
Cleanup pattern
Before creating new Jobs or CronJobs, the operator systematically cleans up:
-
Existing Jobs:
kind: Job name: "
-db-import" name: " -files-import" name: " -drupal-locale-update" -
Pods created by those Jobs (via label selectors).
- Jobs and Pods created by Drupal cron and backup CronJobs when suspending them.
This pattern:
- Prevents old Jobs from interfering with new runs.
- Keeps the namespace clean of completed/failed Jobs and Pods over time.
Summary
- CronJobs:
<name>-drupal-cron(Drupal cron)<name>-auto-db-backup(DB backup, optional)-
<name>-auto-files-backup(files backup, optional) -
Jobs:
<name>-db-import(database import, one-shot)<name>-files-import(files import, one-shot)<name>-drupal-locale-update(locale update, optional)
The operator coordinates these so that imports, backups, and cron run safely around deployment changes.