Use Kubernetes CronJob for cron-based TaskSpawners#449
Merged
Conversation
There was a problem hiding this comment.
1 issue found across 10 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="internal/controller/taskspawner_controller.go">
<violation number="1" location="internal/controller/taskspawner_controller.go:91">
P2: Cron-based reconciliation doesn’t clean up an existing Deployment when a TaskSpawner is switched from polling to cron, so the old Deployment keeps running and can spawn duplicate tasks. Add a cleanup step before creating/updating the CronJob.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
43a7f34 to
90042b4
Compare
176ca44 to
a3dd3e3
Compare
There was a problem hiding this comment.
2 issues found across 13 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="internal/controller/taskspawner_controller.go">
<violation number="1" location="internal/controller/taskspawner_controller.go:259">
P2: When switching between cron and polling modes, stale status fields are not cleared. `reconcileCronJob` sets `CronJobName` but doesn't clear `DeploymentName`, and vice versa. After a mode switch, the status will reference a deleted resource, which could confuse users and tooling.</violation>
<violation number="2" location="internal/controller/taskspawner_controller.go:399">
P0: Bug: `reconcileCronJob` never resolves the workspace or detects GitHub App auth, and `BuildCronJob` hardcodes `nil`/`false` for these. CronJob-based TaskSpawners that reference a workspace will be missing `--github-owner`, `--github-repo` args, and all GitHub auth (PAT env var or token-refresher sidecar), causing them to fail at runtime.
`reconcileCronJob` needs workspace resolution logic (same as `reconcileDeployment`), `BuildCronJob` needs to accept `workspace` and `isGitHubApp` parameters, and the call sites in `createCronJob`/`updateCronJob` need to pass them through.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
a3dd3e3 to
5e544db
Compare
Replace the custom cron polling logic with native Kubernetes CronJob scheduling. Previously, cron-based TaskSpawners ran a long-lived Deployment that polled on pollInterval and computed missed cron ticks. This was confusing because pollInterval and cron schedule served overlapping purposes (issue #138). Now, when spec.when.cron is set, the controller creates a CronJob instead of a Deployment. The CronJob runs on the cron schedule itself, executing the spawner binary in one-shot mode (--one-shot flag) which runs a single discovery cycle and exits. This eliminates the need for pollInterval for cron use cases and delegates scheduling to Kubernetes. Key changes: - Add --one-shot flag to axon-spawner binary for single-cycle execution - Add BuildCronJob method to DeploymentBuilder for creating CronJobs - Split controller reconciliation into reconcileDeployment (GitHub/Jira) and reconcileCronJob (cron) paths - Add status.cronJobName field to TaskSpawnerStatus - Add RBAC for batch/cronjobs and watch CronJobs in SetupWithManager - Add tests for CronJob builder, schedule updates, and suspend toggle Closes #430 Related: #138 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5e544db to
83d2dae
Compare
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.
Summary
spec.when.cronis set, the controller now creates a CronJob (not a Deployment) that runs the spawner in one-shot mode on the cron schedule itselfpollInterval+ cron schedule overlap (closes Re implement TaskSpawnwer's cron #430, related to having pollinterval and cron doesn't make sense #138)--one-shotflag to the spawner binary for single-cycle execution used by CronJob podsstatus.cronJobNamefield to track the CronJob resourceTest plan
make verifypassesmake testpasses (all unit tests including new stale resource cleanup tests)when.cronand verify CronJob is created.spec.suspend🤖 Generated with Claude Code