argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
18.05k stars 5.51k forks source link

Prevent deleting resources but delete the hook after the sync is completed #6112

Open ayushi-inno opened 3 years ago

ayushi-inno commented 3 years ago

Summary

We are using helm charts behind argo application , and we have some dependencies between the subcharts, for example a schema migration or mongo pod to run before any other applications. So to ensure that we used presync hooks for all those resources , like mongo service/pod , schema manager job along with the sync waves. So I do not want my resources to be pruned on each sync.

Motivation

Annotations used - annotations: argocd.argoproj.io/hook: PreSync argocd.argoproj.io/sync-wave: "-2" argocd.argoproj.io/sync-options: Prune=false

This is working fine when we are launching a new application , but when a new sync is detected or an existing sync is terminated for a running application , all of the resources with this annotations are first getting deleted and then again created. This is creating issues like pod for mongo getting restarted again and again leading to data loss or some global config maps or external service names being pruned on new sync. And the argocd.argoproj.io/hook-delete-policy: HookSucceeded description says that "The hook resource is deleted after the hook succeeded (e.g. Job/Workflow completed successfully)" , but i want the resource to be in place.

Proposal

Can there be a way to delete the hook from a resource but not the resource once sync is completed. Or apply presync as a part of helm resources and check those resources states , if anything changes there apply them , but most importantly do not prune out those resources .

hjorth commented 3 years ago

To accomplish this I use the workaround with: argocd.argoproj.io/hook-delete-policy: HookFailed