refactor: move host-crontab generation into cron plugin

Host-crontab generation for `app.json` cron tasks now lives in the `cron` plugin, gated by a new `scheduler-uses-host-cron` trigger that the `docker-local` scheduler answers true while self-managed schedulers such as `k3s` answer false. This lets any host-cron scheduler participate in normal `app.json` cron without coupling to `scheduler-docker-local` or duplicating the crontab writer, while the `k3s` scheduler continues to manage its own in-cluster cron jobs.

Closes #8862.
This commit is contained in:
Jose Diaz-Gonzalez
2026-07-22 07:56:33 -04:00
parent e3687a62ed
commit c6b4ea75c1
24 changed files with 441 additions and 259 deletions

View File

@@ -18,6 +18,10 @@ EOF
teardown() {
rm -rf /var/lib/dokku/plugins/available/cron-entries /var/lib/dokku/plugins/enabled/cron-entries
# restore the default scheduler before destroy: a k3s-scheduled app cannot be
# torn down cleanly without a cluster, and would otherwise leak into the next
# test's cleanup_apps
dokku scheduler:set "$TEST_APP" selected docker-local 2>/dev/null || true
destroy_app
global_teardown
}
@@ -43,6 +47,32 @@ teardown() {
assert_failure
}
@test "(cron) scheduler-uses-host-cron" {
run /bin/bash -c "dokku plugin:trigger scheduler-uses-host-cron docker-local"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "true"
run /bin/bash -c "dokku plugin:trigger scheduler-uses-host-cron k3s"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "false"
run /bin/bash -c "dokku plugin:trigger scheduler-uses-host-cron null"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "false"
run /bin/bash -c "dokku plugin:trigger scheduler-uses-host-cron bogus-scheduler"
echo "output: $output"
echo "status: $status"
assert_success
assert_output ""
}
@test "(cron) invalid [missing-keys]" {
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP template_cron_file_invalid
echo "output: $output"
@@ -406,6 +436,39 @@ teardown() {
assert_failure
}
@test "(cron) k3s-scheduled app skips host crontab" {
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP template_cron_file_valid_single
echo "output: $output"
echo "status: $status"
assert_success
cron_id="$(dokku cron:list $TEST_APP --format json | jq -r '.[0].id')"
run /bin/bash -c "cat /var/spool/cron/crontabs/dokku"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "dokku cron:run $TEST_APP $cron_id"
# switch the app to a scheduler that manages its own cron backend
run /bin/bash -c "dokku scheduler:set $TEST_APP selected k3s"
echo "output: $output"
echo "status: $status"
assert_success
# regenerating the host crontab must now skip the k3s app's tasks, leaving
# no host-cron tasks and therefore no crontab file
run /bin/bash -c "dokku plugin:trigger scheduler-cron-write"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "cat /var/spool/cron/crontabs/dokku"
echo "output: $output"
echo "status: $status"
assert_failure
}
@test "(cron) cron:list --format json" {
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP template_cron_file_valid
echo "output: $output"