feat(scheduled-task): add run-once job mode that runs on deploy - #206
Open
fedemaleh wants to merge 3 commits into
Open
feat(scheduled-task): add run-once job mode that runs on deploy#206fedemaleh wants to merge 3 commits into
fedemaleh wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a "Run once" mode to the
scheduled_taskscope. When selected, deploying the scope creates a Kubernetes Job (instead of a CronJob) that executes immediately on deploy, and the deployment waits for the Job to finish, reporting success or failure based on the Job's result.How it works
The whole feature keys off a single sentinel value:
scope.capabilities.cron == "run-once".service-spec.json.tpl): a new"Run once"option is added to the existing Task Frequency (cron) dropdown — no new required field, fully retro-compatible. When "Run once" is picked, the CronJob-only fields Concurrency policy and History are hidden in the UI (they have no meaning for a one-shot Job). Retries stays (it maps to the Job'sbackoffLimit).deployment.yaml.tpl): a plain gomplateif/elserenders either aJob(withbackoffLimit,activeDeadlineSeconds,ttlSecondsAfterFinished: 86400) or the unchangedCronJob. The CronJob render is byte-identical to before (verified by diffing real-gomplate output against the base template).deployment/wait_job): polls the Job'sComplete/Failedconditions up toJOB_WAIT_TIMEOUT(default 600s, configurable invalues.yaml). It's wired intoinitial.yamlandblue_green.yamlby replacing the inheritedwait deployment activestep, and is a no-op for CronJob deployments (so the step is safe on both paths).scope/trigger): for run-once scopes there's no CronJob to spawn from, so the action falls back to cloning the last Job of the scope (stripping server-managed fields) and creating a fresh one. Scheduled scopes are unchanged.Notes / decisions
activeDeadlineSecondsequalsJOB_WAIT_TIMEOUT; the wait poller runs a short grace period longer so Kubernetes marks the JobDeadlineExceededfirst and the operator sees the specific failure reason.if/else, nodefine/tmpl.Exec) — an explicit design choice to keep the CronJob output untouched and each branch a complete, readable manifest.apply_templateswithACTION: delete(it removes the Job, never creates/runs one), so there is nothing to wait for.Test plan
bats scheduled_task/deployment/tests/{build_deployment,wait_job,workflow_overrides}.bats scheduled_task/scope/tests/{trigger,workflow_overrides}.bats— 38 passing, including:JOB_WAIT_TIMEOUToverride + file-param volumes preserved in Job modewait_jobsuccess / failure / timeout / no-op / namespace resolution /set -uguardwait deployment activewithwait_job