Use Kubernetes CronJob for cron-based TaskSpawners#449
Open
axon-agent[bot] wants to merge 3 commits intomainfrom
Open
Use Kubernetes CronJob for cron-based TaskSpawners#449axon-agent[bot] wants to merge 3 commits intomainfrom
axon-agent[bot] wants to merge 3 commits intomainfrom
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.
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>
- Copy p.args before appending --one-shot to avoid mutating the shared backing array from buildPodParts - Rename TestCronJobReconciliation_Create to TestIsCronBased since that is what the test actually verifies Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a TaskSpawner switches from polling-based (Deployment) to cron-based (CronJob) or vice versa, delete the old resource before creating the new one. Without this cleanup, the old Deployment/CronJob would keep running alongside the new resource, potentially spawning duplicate tasks. Add deleteStaleResource helper and tests for both switch directions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
43a7f34 to
90042b4
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