Skip to main content

☑️ Prevent CronJob from executing jobs concurrently

By default, the cron job allows concurrently running jobs but generally speaking, the behavior of your cron jobs will be more deterministic if you prevent them from running concurrently. Allowing concurrent cron jobs often requires locking mechanisms (to avoid race conditions) in addition to startup/cleanup handling.

Targeted objects by this rule (types of kind): CronJob

Complexity: easy (What does this mean?)

Policy as code identifier: CRONJOB_MISSING_CONCURRENCYPOLICY_KEY


This rule will fail

If a CronJob doesn't have concurrencyPolicy set or concurrencyPolicy is set to Allow

kind: CronJob
spec:
schedule: "*/1 * * * *"
kind: CronJob
spec:
concurrencyPolicy: Allow

Rule output in the CLI

$ datree test *.yaml

>> File: failExample.yaml
❌ Prevent CronJob from executing jobs concurrently [1 occurrence]
💡 Missing property object `concurrencyPolicy` - the behavior will be more deterministic when the jobs run one at a time

How to fix this failure

Set concurrencyPolicy to either Forbid or Replace

kind: CronJob
spec:
concurrencyPolicy: Forbid
kind: CronJob
spec:
concurrencyPolicy: Replace

Read more