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

Argocd cli app sync fails for apps with resources with "Prune=false" #8134

Open
3 tasks done
joaosilva15 opened this issue Jan 10, 2022 · 1 comment
Open
3 tasks done
Labels
bug Something isn't working

Comments

@joaosilva15
Copy link

If you are trying to resolve an environment-specific issue or have a one-off question about the edge case that does not require a feature then please consider asking a question in argocd slack channel.

Checklist:

  • I've searched in the docs and FAQ for my answer: https://bit.ly/argocd-faq.
  • I've included steps to reproduce the bug.
  • I've pasted the output of argocd version.

Describe the bug

When syncing apps with the command argocd app sync <appname> --prune on applications that have resources with the annotation argocd.argoproj.io/sync-options: Prune=false and have resources to be pruned the argo command exits with error until the sync is successful.
After all the resources that should be pruned are deleted the command exits without error.

To Reproduce

  1. Create an application with resources with the annotations argocd.argoproj.io/sync-options: Prune=false. The auto-sync is disabled
  2. Make a change to remove a resource from the application (one that is suppose to be deleted by argo)
  3. Run the command argocd.argoproj.io/sync-options: Prune=false from the console
  4. The command will error until the resource disappears. The error message is FATA[0002] 1 resources require pruning

Expected behavior

The argocd command should not error if the resource that "requires pruning" needs to be ignored

Version

argocd: v2.2.2+03b17e0.dirty
  BuildDate: 2022-01-01T16:55:19Z
  GitCommit: 03b17e0233e64787ffb5fcf65c740cc2a20822ba
  GitTreeState: dirty
  GoVersion: go1.17.5
  Compiler: gc
  Platform: darwin/amd64
argocd-server: v2.2.2+03b17e0
  BuildDate: 2022-01-01T06:27:52Z
  GitCommit: 03b17e0233e64787ffb5fcf65c740cc2a20822ba
  GitTreeState: clean
  GoVersion: go1.16.11
  Compiler: gc
  Platform: linux/amd64
  Ksonnet Version: v0.13.1
  Kustomize Version: v4.2.0 2021-06-30T22:49:26Z
  Helm Version: v3.7.1+g1d11fcb
  Kubectl Version: v0.22.2
  Jsonnet Version: v0.17.0

I believe the problem lies in

pruningRequired := app.Status.OperationState.SyncResult.Resources.PruningRequired()
which checks if any resource requires pruning without checking if it has the annotations. The fix should be to only count resources that should actually be pruned. Looking at the current code I do not see a way of figuring out in
func (r ResourceResults) PruningRequired() (num int) {
if the resource is to be pruned or not except by the message on the sync which would be ignored (no prune). If you have a better solution and give me some tips I could open a PR.

@joaosilva15 joaosilva15 added the bug Something isn't working label Jan 10, 2022
@thesuperzapper
Copy link

For those watching, this is still an issue as of ArgoCD v2.10.1.

This issue's true cause is the Application resource does not correctly populate status.resources to reflect that resources with argocd.argoproj.io/sync-options: Prune=false do not actually require pruning (see #17188), if we fix that issue, then this problem will be completely resolved.

This issue also causes the UI and argocd app get to display the wrong information about resources, saying they "require pruning" even if they have argocd.argoproj.io/sync-options: Prune=false.


There is a slight workaround until #17188 is resolved, which is to additionally annotate your resources with argocd.argoproj.io/compare-options: IgnoreExtraneous, which makes them not actually "part of the app" from ArgoCD's perspective (so not contributing to if an app is "out of sync").

Note that the argocd app sync only "fails" if the actual final state is "out of sync", which it won't be if all the requiresPruning=true apps are IgnoreExtraneous:

} else if len(selectedResources) == 0 && app.Status.Sync.Status != argoappv1.SyncStatusCodeSynced {

WARNING: this workaround ONLY works if you are using argocd.argoproj.io/sync-options: Prune=false because you are generating the resource outside of ArgoCD itself, if you are using it because you don't want ArgoCD to remove the resource, because sometimes your app contains that resource, and other times it does not, then you will need to push for #17188 to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants