Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: PostDelete hook support #16595

Merged
merged 3 commits into from
Dec 18, 2023
Merged

Conversation

alexmt
Copy link
Collaborator

@alexmt alexmt commented Dec 12, 2023

Closes #7575

PR introduces Post delete hooks support. Hooks are executed during application deletion after all resources as removed. Hooks respect deletion policies.

  • PostDelete hooks
  • Docs
  • Hooks delete policy
  • Tests
Screen.Recording.2023-12-15.at.3.04.37.PM.mov

@alexmt alexmt force-pushed the post-delete-hooks branch 2 times, most recently from 688ac4c to 70c0a24 Compare December 16, 2023 21:40
Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Copy link

codecov bot commented Dec 16, 2023

Codecov Report

Attention: 104 lines in your changes are missing coverage. Please review.

Comparison is base (a761a49) 49.50% compared to head (230db9b) 49.51%.
Report is 12 commits behind head on master.

Files Patch % Lines
controller/appcontroller.go 43.82% 43 Missing and 7 partials ⚠️
controller/hook.go 58.87% 29 Missing and 15 partials ⚠️
pkg/apis/application/v1alpha1/types.go 0.00% 6 Missing ⚠️
controller/state.go 70.00% 2 Missing and 1 partial ⚠️
controller/sync.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #16595    +/-   ##
========================================
  Coverage   49.50%   49.51%            
========================================
  Files         270      271     +1     
  Lines       47488    47659   +171     
========================================
+ Hits        23508    23597    +89     
- Misses      21670    21731    +61     
- Partials     2310     2331    +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
@alexmt alexmt marked this pull request as ready for review December 16, 2023 22:25
@alexmt alexmt requested review from a team as code owners December 16, 2023 22:25
}
logCtx.Infof("Successfully deleted %d resources", len(objs))
logCtx.Infof("Resource entries removed from undefined cluster")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this log needed here? If it is needed not sure if it should be undefined cluster

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, thank you for catching it. I just forgot to delete this line - fixed!

return false, err
}
for _, policy := range hook.DeletePolicies(obj) {
if policy == common.HookDeletePolicyHookFailed && hookHealth.Status == health.HealthStatusDegraded || policy == common.HookDeletePolicyHookSucceeded && hookHealth.Status == health.HealthStatusHealthy {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this behaviour is different from the delete policy of the other hook types, as far as I remember in gitops-engine the delete policy would be compared with the whole app status instead of just the hook status. We might want to keep the behaviour same or else it can be confusing. I understand at deletion we probably won't have the app status to compare maybe so might be better to have special deletion policy just for the delete hooks?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another question here, what do we do if the deletion policy condition isn't met. Does the app itself remains or is it just the hook that sticks around?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. App deletion does not have status, however, I think the use case is similar: the user just needs control to preserve some hook for debugging. To match with gitops engine behavior it makes sense to use aggregated hooks status. Implemented

return false, err
}
for _, policy := range hook.DeletePolicies(obj) {
if policy == common.HookDeletePolicyHookFailed && hookHealth.Status == health.HealthStatusDegraded || policy == common.HookDeletePolicyHookSucceeded && hookHealth.Status == health.HealthStatusHealthy {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another question here, what do we do if the deletion policy condition isn't met. Does the app itself remains or is it just the hook that sticks around?

@alexmt
Copy link
Collaborator Author

alexmt commented Dec 17, 2023

If the deletion policy does not match, then the hook stays. It matches Helm behavior . Updated documentation as well.

Thank you for review @gdsoumya . PTAL

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
@alexmt alexmt requested a review from gdsoumya December 17, 2023 23:17
@crenshaw-dev crenshaw-dev changed the title feat: Pre/PostDelete hooks support feat: PostDelete hook support Dec 18, 2023
@alexmt alexmt merged commit dcc17f7 into argoproj:master Dec 18, 2023
26 checks passed
@alexmt alexmt deleted the post-delete-hooks branch December 18, 2023 16:40
JulienFuix pushed a commit to JulienFuix/argo-cd that referenced this pull request Feb 6, 2024
* feat: PostDelete hooks support

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>


---------

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
penglongli pushed a commit to penglongli/argo-cd that referenced this pull request Mar 6, 2024
* feat: PostDelete hooks support

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>

---------

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Signed-off-by: penglongli <pelenli@tencent.com>
lyda pushed a commit to lyda/argo-cd that referenced this pull request Mar 28, 2024
* feat: PostDelete hooks support

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>

---------

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Signed-off-by: Kevin Lyda <kevin@lyda.ie>
Hariharasuthan99 pushed a commit to AmadeusITGroup/argo-cd that referenced this pull request Jun 16, 2024
* feat: PostDelete hooks support

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>


---------

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A way to do something in hook after delete the Argo Application
3 participants