-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Conversation
688ac4c
to
70c0a24
Compare
Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Codecov ReportAttention:
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. |
70c0a24
to
0e74e77
Compare
0e74e77
to
f3874a6
Compare
controller/appcontroller.go
Outdated
} | ||
logCtx.Infof("Successfully deleted %d resources", len(objs)) | ||
logCtx.Infof("Resource entries removed from undefined cluster") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
controller/hook.go
Outdated
return false, err | ||
} | ||
for _, policy := range hook.DeletePolicies(obj) { | ||
if policy == common.HookDeletePolicyHookFailed && hookHealth.Status == health.HealthStatusDegraded || policy == common.HookDeletePolicyHookSucceeded && hookHealth.Status == health.HealthStatusHealthy { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
controller/hook.go
Outdated
return false, err | ||
} | ||
for _, policy := range hook.DeletePolicies(obj) { | ||
if policy == common.HookDeletePolicyHookFailed && hookHealth.Status == health.HealthStatusDegraded || policy == common.HookDeletePolicyHookSucceeded && hookHealth.Status == health.HealthStatusHealthy { |
There was a problem hiding this comment.
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?
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>
* feat: PostDelete hooks support Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com> --------- Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
* 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>
* 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>
* feat: PostDelete hooks support Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com> --------- Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
* The finalizers: - post-delete-finalizer.argocd.argoproj.io - post-delete-finalizer.argoproj.io/cleanup are added by ArgoCD when the rendered manifests include a post-delete hook. In this case, the application will not be deleted since we could not satisfy the finalizer condition. Therefore, removed the finalizers. See: [1] for PostDeleteFinalizerName reference [2] for implementation of these finalizers adding --- [1] https://github.com/argoproj/argo-cd/blame/8a447d9ae01f0c4358bc0d7553c120c43a8b99e5/pkg/apis/application/v1alpha1/application_defaults.go#L12-L13 [2] argoproj/argo-cd#16595
* Fixed applications removal stuck due to obstructive finalizers * The finalizers: - post-delete-finalizer.argocd.argoproj.io - post-delete-finalizer.argoproj.io/cleanup are added by ArgoCD when the rendered manifests include a post-delete hook. In this case, the application will not be deleted since we could not satisfy the finalizer condition. Therefore, removed the finalizers. See: [1] for PostDeleteFinalizerName reference [2] for implementation of these finalizers adding --- [1] https://github.com/argoproj/argo-cd/blame/8a447d9ae01f0c4358bc0d7553c120c43a8b99e5/pkg/apis/application/v1alpha1/application_defaults.go#L12-L13 [2] argoproj/argo-cd#16595 * refactor: adjust application finalizers filtering * Adjust application finalizers filtering, follow a suggestion and thanks to @wingyplus. Using .filter() for filtering as we still need the values of finalizers to show in the debug message. * Apply suggestions from code review * Clean up an extended comment with a clean and concise one. * Handle the errors from command output and YAML parsing separately for an easier to read code. * Inspect an error properly to align with the application output log. Co-authored-by: Dag Andersen <dagbjerreandersen@gmail.com> * Apply suggestions from code review * A proper json string argument passing, switch from `--patch-file` to `--patch` instead. Co-authored-by: Dag Andersen <dagbjerreandersen@gmail.com> * chore: drop unused module and apply code formatting * Drop unused module `std::env` * Apply code formatting --------- Co-authored-by: Dag Andersen <dagbjerreandersen@gmail.com>
Closes #7575
PR introduces Post delete hooks support. Hooks are executed during application deletion after all resources as removed. Hooks respect deletion policies.
Screen.Recording.2023-12-15.at.3.04.37.PM.mov