Lab 07: CronWorkflows
CronWorkflow = workflowSpec (a normal Workflow spec) + schedule. Creates a Workflow on each tick, like a k8s CronJob.
Basic
apiVersion: argoproj.io/v1alpha1
kind: CronWorkflow
metadata:
name: hello-cron
namespace: argo
spec:
schedule: "* * * * *"
timezone: America/Los_Angeles
concurrencyPolicy: Replace
startingDeadlineSeconds: 60
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
workflowSpec:
serviceAccountName: argo
entrypoint: main
templates:
- name: main
container:
image: alpine:3.20
command: [sh, -c]
args: ["echo scheduled=\"{{workflow.scheduledTime}}\"; date -u"]
kubectl apply -f hello-cron.yaml
argo cron list -n argo
argo cron get -n argo hello-cron
argo list -n argo
argo logs -n argo @latest
argo submit -n argo --from cronworkflow/hello-cron --watch
- generated workflows are named
hello-cron-<unix timestamp> --from cronworkflow/...runs it now without waiting for the schedulescheduleis a standard 5-field cron expression; newer versions also accept ascheduleslist for multiple expressionstimezonetakes IANA names (America/New_York), notPST. Default is the controller’s timezone (UTC){{workflow.scheduledTime}}= the tick time that created the runstartingDeadlineSeconds= how late a missed run may still start (e.g. controller was down), 0 = no catch-up- history limits are about the finished workflows kept around
Concurrency policy
spec:
schedule: "*/2 * * * *"
concurrencyPolicy: Forbid
workflowSpec:
entrypoint: long
templates:
- name: long
container:
image: alpine:3.20
command: [sh, -c]
args: ["sleep 180"]
Allow(default) = overlapping runs OKForbid= skip the new run if the previous is still runningReplace= stop the running one, start the new one- run a 3 min job on a 2 min schedule and compare with
watch argo list -n argo
Stop strategy
spec:
schedule: "* * * * *"
stopStrategy:
expression: "cronworkflow.succeeded >= 3"
- the CronWorkflow suspends itself after the expression is true (3.6+)
- variables:
cronworkflow.succeeded,cronworkflow.failed,cronworkflow.failed > 0etc. - check with
argo cron get, status shows suspended
Timezone and DST
spec:
schedule: "30 2 * * *"
timezone: America/New_York
- scheduling follows the local wall clock, so around DST changes a local time can be skipped (spring forward: 02:30 doesn’t exist) or happen twice (fall back)
- avoid scheduling in the 01:00-03:00 window, or use
UTCfor anything that must run exactly once a day - no built-in duplicate protection, make the job idempotent
Suspend and resume
argo cron suspend -n argo hello-cron
argo cron get -n argo hello-cron # Suspended: true
argo cron resume -n argo hello-cron
- suspend keeps the object, just stops scheduling. Same as
spec.suspend: true - running workflows aren’t affected
Debugging
argo cron getshows last scheduled time, active workflows, and conditions (invalid cron expression shows up there)kubectl logs -n argo deploy/workflow-controllerfor schedule errors- not firing: suspended, bad
timezone,Forbidwith a stuck previous run
Cleanup
argo cron delete -n argo --all
argo delete -n argo --all
Next: Lab 08