argo-cd icon indicating copy to clipboard operation
argo-cd copied to clipboard

feat: add Prune and Delete as application level sync option

Open MrFreezeex opened this issue 7 months ago • 13 comments

Checklist:

  • [x] Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • [x] The title of the PR states what changed and the related issues number (used for the release note).
  • [x] The title of the PR conforms to the Toolchain Guide
  • [x] I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • [x] I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • [x] Does this PR require documentation updates?
  • [x] I've updated documentation as required by this PR.
  • [x] I have signed off all my commits as required by DCO
  • [x] I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • [x] My build is green (troubleshooting builds).
  • [x] My new feature complies with the feature status guidelines.
  • [x] I have added a brief description of why this PR is necessary and/or what this PR solves.
  • [ ] Optional. My organization is added to USERS.md.
  • [ ] Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

My goal was mainly to add Prune/Delete=confirm as a sync option as the deletion confirmation acts on the whole Application already and it's way more convenient in our env to add it on the application level than as annotation on the resources actually deployed.

For consistency I also added Prune/Delete=false support there (separate commit).

And the UI option in when editing the sync policy for the Prune and Delete sync options

Closes https://github.com/argoproj/argo-cd/issues/23380

MrFreezeex avatar Jun 12 '25 12:06 MrFreezeex

:x: Preview Environment undeployed from Bunnyshell

Available commands (reply to this comment):

  • :rocket: /bns:deploy to deploy the environment

bunnyshell[bot] avatar Jun 12 '25 12:06 bunnyshell[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 60.79%. Comparing base (492f712) to head (4720a94).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #23370   +/-   ##
=======================================
  Coverage   60.78%   60.79%           
=======================================
  Files         351      351           
  Lines       60439    60468   +29     
=======================================
+ Hits        36737    36760   +23     
- Misses      20782    20786    +4     
- Partials     2920     2922    +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jun 12 '25 13:06 codecov[bot]

Could you create an issue describing what the issue/enhancement is and why this change is needed and link it to this PR and your gitops-engine PR?

Sure! I just did that here: https://github.com/argoproj/argo-cd/issues/23380

MrFreezeex avatar Jun 13 '25 08:06 MrFreezeex

The deletion part LGTM. Maybe helpful to add a screenshot or video of the sync option working. Thanks

pjiang-dev avatar Jun 13 '25 22:06 pjiang-dev

Maybe helpful to add a screenshot or video of the sync option working. Thanks

Sure, will try to provide a video later today!

MrFreezeex avatar Jun 16 '25 11:06 MrFreezeex

(rebasing for the go.mod conflict below and bumping the gitops-engine fork, no other code change)

MrFreezeex avatar Jun 17 '25 13:06 MrFreezeex

@pjiang-dev here is the video (I had to fix a dumb typo https://github.com/argoproj/gitops-engine/compare/13f9343d366f59f29905dda9c8ef4e6257a67c67..03789b820ebec73de41af43a35493983c1832e01 in the gitops-engine so thanks for making me double check :see_no_evil:)

https://github.com/user-attachments/assets/4cad277a-b821-46cb-94e8-c28cc1235a82

MrFreezeex avatar Jun 17 '25 13:06 MrFreezeex

FYI here is the yaml that I am using in the video above:

---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: test-prune-confirm
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: default
  source:
    repoURL: https://github.com/MrFreezeex/test-argocd-confirm.git
    targetRevision: "testsyncopt"
    path: test-prune
    # path: test-empty
  destination:
    name: in-cluster
    namespace: test-prune-confirm
  syncPolicy:
    automated: {}
    syncOptions:
      - Prune=confirm
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: test-prune-false
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: default
  source:
    repoURL: https://github.com/MrFreezeex/test-argocd-confirm.git
    targetRevision: "testsyncopt"
    path: test-prune
    # path: test-empty
  destination:
    name: in-cluster
    namespace: test-prune-false
  syncPolicy:
    automated: {}
    syncOptions:
      - Prune=false
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: test-delete-confirm
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: default
  source:
    repoURL: https://github.com/MrFreezeex/test-argocd-confirm.git
    targetRevision: "testsyncopt"
    path: test-delete
  destination:
    name: in-cluster
    namespace: test-delete-confirm
  syncPolicy:
    automated: {}
    syncOptions:
      - Delete=confirm
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: test-delete-false
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: default
  source:
    repoURL: https://github.com/MrFreezeex/test-argocd-confirm.git
    targetRevision: "testsyncopt"
    path: test-delete
  destination:
    name: in-cluster
    namespace: test-delete-false
  syncPolicy:
    automated: {}
    syncOptions:
      - Delete=false

MrFreezeex avatar Jun 17 '25 13:06 MrFreezeex

Hi @agaudreault, kind reminder about this PR, would love to have your updated input on the matter whenever you have time do so :pray:

MrFreezeex avatar Jul 07 '25 15:07 MrFreezeex

Would also be ace to see this merged - just upgraded Argo on all our clusters only to find out that the option isn't there yet, just the annotation on resources 😁

shearn89 avatar Jul 28 '25 12:07 shearn89

+1 I really need it

sharovmerk avatar Sep 08 '25 12:09 sharovmerk

@agaudreault I added the change for the resource precedence as you suggested.

I also included the fix I did here https://github.com/argoproj/argo-cd/pull/23326 in a separate commit as this PR changed a bit the code related to that and the other PR won't really be applicable anymore. We could still keep the other fix PR as a cherry pick to the release branches if necessary. Although AFAIU no one complained about this bug and it's something that I discovered while developing this so it might be just fine to not cherry pick it :man_shrugging:.

Let me know WDYT of this new version :pray:

MrFreezeex avatar Oct 13 '25 13:10 MrFreezeex

Hi @agaudreault small reminder about this PR in case it drop of your radar :pray:

MrFreezeex avatar Dec 01 '25 13:12 MrFreezeex