fix: Remove default BeforeHookCreation hook deletion policy #25957
+19
−20
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
This PR removes the default deletion policy for resources with hook annotations. Resources with hook annotations should not be automatically deleted when only the hook phase annotation is specified.
Motivation
Previously, resources with hook annotations would be automatically deleted due to two different mechanisms:
BeforeHookCreationdeletion policy applied in the gitops-engineThis was unexpected behavior because:
Changes
1. gitops-engine/pkg/sync/hook/delete_policy.go
Removed the automatic assignment of
BeforeHookCreationdeletion policy when no policy is specified:Before:
After:
2. controller/hook.go
Removed the auto-deletion logic in the
cleanupHooksfunction for resources with PreDelete/PostDelete hook annotations:Before:
After:
3. Updated Tests and Documentation
gitops-engine/pkg/sync/hook/delete_policy_test.gogitops-engine/pkg/sync/doc.goto clarify that resources with hook annotations are NOT deleted by defaultBehavior Changes
Before this PR:
☠️ This Job resource would be automatically deleted and recreated on every sync
After this PR:
✅ This Job resource will persist across syncs
To get the old auto-delete behavior:
Testing
gitops-engine/pkg/sync/hookpassgitops-engine/pkg/syncpassMigration Guide
For users who relied on the old default behavior and want resources with hook annotations to be deleted before recreation, add an explicit deletion policy:
Available deletion policies:
BeforeHookCreation- Delete the resource before creating it (old default behavior)HookSucceeded- Delete the resource after it succeedsHookFailed- Delete the resource after it failsImpact
This is a behavior change that makes ArgoCD more intuitive:
Related Issues
Fixes #25956
Checklist