Handle CronJob upgrade via active Job Pod deletion#1098
Open
trvrnrth wants to merge 2 commits into
Open
Conversation
Instead of immediately creating new Jobs we will instead delete pods belonging to active Jobs. This will cause the job controller to re-create the pods based on the defined policies. As such we will not violate the CronJob schedule, suspension and concurrency policies.
5 tasks
There was a problem hiding this comment.
Pull request overview
Resolves the dangerous behavior in which Reloader would create new Job instances from a (potentially suspended) CronJob when an associated ConfigMap/Secret changed. Instead, the CronJob UpdateFunc now deletes the running pods of currently active Jobs, allowing the Job controller to recreate them per the configured policies and respecting CronJob suspension/concurrency.
Changes:
- Replace
CreateJobFromCronjobwithRestartRunningCronjobPods, which deletes pods ofcronJob.Status.Activejobs viaPods.DeleteCollectionfiltered byJobNameLabelandstatus.phase=Running. - Add
pods: deletecollectionRBAC to both the static manifest and the Helm chart (gated byignoreCronJobs && ignoreJobs). - Update tests with a fake-client reactor for
delete-collectionon pods, plus various doc-comment typo fixes.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/pkg/callbacks/rolling_upgrade.go | Replace job-creation logic with pod deletion of active CronJob jobs; fix doc comment. |
| internal/pkg/callbacks/rolling_upgrade_test.go | Rewrite test to verify only running pods of active jobs are deleted; add fake reactor and helpers. |
| internal/pkg/handler/upgrade.go | Wire CronJob UpdateFunc to new RestartRunningCronjobPods; fix doc comments. |
| internal/pkg/testutil/kube.go | Doc-comment typo fixes. |
| pkg/kube/client.go | Doc-comment typo fix. |
| deployments/kubernetes/manifests/clusterrole.yaml | Add pods: deletecollection permission. |
| deployments/kubernetes/chart/reloader/templates/clusterrole.yaml | Conditionally add pods: deletecollection permission. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Instead of immediately creating new Jobs we will instead delete pods belonging to active Jobs. This will cause the job controller to re-create the pods based on the defined policies.
As such we will not violate the CronJob schedule, suspension and concurrency policies.
Resolves #822