Skip to content

feat: add Prune and Delete as application level sync option#23370

Merged
agaudreault merged 5 commits intoargoproj:masterfrom
MrFreezeex:sync-option-confirm
Mar 13, 2026
Merged

feat: add Prune and Delete as application level sync option#23370
agaudreault merged 5 commits intoargoproj:masterfrom
MrFreezeex:sync-option-confirm

Conversation

@MrFreezeex
Copy link
Copy Markdown
Contributor

@MrFreezeex MrFreezeex commented Jun 12, 2025

Checklist:

  • 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.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • 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 #23380

@bunnyshell
Copy link
Copy Markdown

bunnyshell bot commented Jun 12, 2025

❌ Preview Environment deleted from Bunnyshell

Available commands (reply to this comment):

  • 🚀 /bns:deploy to deploy the environment

@MrFreezeex MrFreezeex force-pushed the sync-option-confirm branch 2 times, most recently from f5381c1 to b2ca286 Compare June 12, 2025 12:50
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 12, 2025

Codecov Report

❌ Patch coverage is 95.38462% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.03%. Comparing base (3a4b0a0) to head (cc318b8).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
gitops-engine/pkg/sync/sync_context.go 85.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #23370      +/-   ##
==========================================
+ Coverage   62.98%   63.03%   +0.04%     
==========================================
  Files         414      414              
  Lines       56153    56198      +45     
==========================================
+ Hits        35370    35425      +55     
+ Misses      17416    17409       -7     
+ Partials     3367     3364       -3     

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

@MrFreezeex MrFreezeex marked this pull request as ready for review June 12, 2025 15:07
@MrFreezeex MrFreezeex requested review from a team as code owners June 12, 2025 15:07
@MrFreezeex MrFreezeex force-pushed the sync-option-confirm branch from b2ca286 to 5d5a4c3 Compare June 12, 2025 15:16
Copy link
Copy Markdown
Contributor

@pjiang-dev pjiang-dev left a comment

Choose a reason for hiding this comment

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

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?

@MrFreezeex
Copy link
Copy Markdown
Contributor Author

MrFreezeex commented Jun 13, 2025

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: #23380

@MrFreezeex MrFreezeex requested a review from pjiang-dev June 13, 2025 08:23
@pjiang-dev
Copy link
Copy Markdown
Contributor

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

@pjiang-dev pjiang-dev added the ready-for-review An approver should give a final review and merge the PR label Jun 13, 2025
@github-project-automation github-project-automation bot moved this to Ready for final review in Argo CD Review Jun 13, 2025
argocd.argoproj.io/sync-options: Prune=false
```

It also can be enabled at the application level like in the example below:
Copy link
Copy Markdown
Contributor

@pjiang-dev pjiang-dev Jun 13, 2025

Choose a reason for hiding this comment

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

Also just one question, if an application's resource has prune=true enabled, but the application has prune=false, which one takes priority? I am assuming resource level should take priority ? Same with the other options.
If not documented somewhere already i think its worth mentioning in the docs

Copy link
Copy Markdown
Contributor Author

@MrFreezeex MrFreezeex Jun 16, 2025

Choose a reason for hiding this comment

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

The Prune/Delete=true are not an actual thing, it's just something added in the UI that can act as a default option. Prune=helloworld would be similarly handled technically :p.

For the rest of the options there is not really a priority thing currently, both behavior will apply. For instance if you have Delete=confirm and Delete=false on some resources it will ask you for confirmation and do not delete the resource marked as delete=false (and similarly with prune). I will add clarification for that in docs, thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done! Let me know if the new doc is more clear!

@MrFreezeex MrFreezeex force-pushed the sync-option-confirm branch from 5d5a4c3 to 5ab9a2b Compare June 16, 2025 11:13
@MrFreezeex
Copy link
Copy Markdown
Contributor Author

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

Sure, will try to provide a video later today!

@MrFreezeex
Copy link
Copy Markdown
Contributor Author

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

@MrFreezeex MrFreezeex force-pushed the sync-option-confirm branch 2 times, most recently from 98975a0 to 12498ec Compare June 17, 2025 13:38
@MrFreezeex
Copy link
Copy Markdown
Contributor Author

@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 🙈)

recording.mp4

@MrFreezeex
Copy link
Copy Markdown
Contributor Author

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

Comment on lines +52 to +65
It also can be enabled at the application level like in the example below:

```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
syncPolicy:
syncOptions:
- Prune=confirm
```

Note that setting a Prune sync option on the application level will not override
the same sync option set on a specific resource, both will still be applied.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of repeating the doc, specify that the same value can be use either through the annotation or the sync option.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't mind doing that but IIUC adding both like that is consistent with the current doc, for instance ServerSideApply: https://argo-cd.readthedocs.io/en/stable/user-guide/sync-options/#server-side-apply

@github-project-automation github-project-automation bot moved this from Ready for final review to Changes Requested in Argo CD Review Jun 17, 2025
@agaudreault agaudreault added this to the v3.2 milestone Jun 17, 2025
@MrFreezeex MrFreezeex force-pushed the sync-option-confirm branch from 12498ec to 38e4817 Compare June 17, 2025 14:58
@MrFreezeex MrFreezeex requested a review from agaudreault June 19, 2025 20:48
@MrFreezeex
Copy link
Copy Markdown
Contributor Author

MrFreezeex commented Jul 7, 2025

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

@MrFreezeex
Copy link
Copy Markdown
Contributor Author

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

@agaudreault agaudreault modified the milestones: v3.2, v3.3 Dec 5, 2025
@MrFreezeex MrFreezeex force-pushed the sync-option-confirm branch from ae73ef9 to 48858af Compare January 9, 2026 16:23
@agaudreault agaudreault self-assigned this Jan 12, 2026
@MrFreezeex MrFreezeex force-pushed the sync-option-confirm branch 3 times, most recently from 5fc1319 to 71ffdba Compare February 17, 2026 16:53
@MrFreezeex
Copy link
Copy Markdown
Contributor Author

@agaudreault FYI I just rebased this PR on master now that this #25915 has been merged (thanks again!), and fixed some issues that popped on the new CI and this should be ready again for review!

@MrFreezeex
Copy link
Copy Markdown
Contributor Author

MrFreezeex commented Mar 9, 2026

Hi @agaudreault kind reminder abut this, it would be super awesome if this could make it in time for the 3.4 release 🙏

@MrFreezeex
Copy link
Copy Markdown
Contributor Author

MrFreezeex commented Mar 9, 2026

I just rebased to make the CI the "Ensure Go modules synchronicity" test pass (I am not sure why it fails though since I don't update the go.mod/any dependency here, perhaps it's when updating the branch via merge 🤷‍♂️)

EDIT: Nevermind it was actually related to this PR with k8s.io/utils that I am using here meaning that it's no longer an indirect dependency and I just fixed it in my last push!

@MrFreezeex MrFreezeex force-pushed the sync-option-confirm branch 2 times, most recently from c5ba5a1 to dd9650c Compare March 9, 2026 13:10
Copy link
Copy Markdown
Member

@agaudreault agaudreault left a comment

Choose a reason for hiding this comment

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

Overall, the feature LGTM. Few refactors required here and there.

This will facilitate adding logic on sync options that can be defined
both at the app and resource level and the resource level should
override the app level option.

Also fix GetAnnotationCSVs to preserve the order returned (as map in
golang doesn't preserve the insertion order) to make dedup works in
GetOptionValue.

Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@ledger.fr>
@MrFreezeex MrFreezeex force-pushed the sync-option-confirm branch from dd9650c to ac9fd6e Compare March 12, 2026 15:32
Add support for Delete and Prune sync options on the application level.
When at the application level those options are only changing the
"default behavior" for resources deployed by this application.

The behavior is still to process this at the resource level and the resource
level always override the app level Delete option.

Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@ledger.fr>
@MrFreezeex MrFreezeex force-pushed the sync-option-confirm branch 3 times, most recently from 019fa7d to 874246b Compare March 12, 2026 17:12
t.Context(), &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "test-configmap",
Labels: map[string]string{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You need to set the tracking annotation correctly here instead of an app instance label.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ohh thanks a lot! The test are green now 🎉

Copy link
Copy Markdown
Member

@agaudreault agaudreault left a comment

Choose a reason for hiding this comment

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

LGTM. Ready to merge when test are fixed.

Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@ledger.fr>
Also reorder the PruneLast option so that all prune options are grouped

Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@ledger.fr>
@MrFreezeex MrFreezeex force-pushed the sync-option-confirm branch from 874246b to a3e5ec9 Compare March 12, 2026 20:16
@agaudreault agaudreault merged commit b7e2027 into argoproj:master Mar 13, 2026
28 checks passed
@github-project-automation github-project-automation bot moved this from Changes Requested to Done in Argo CD Review Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review An approver should give a final review and merge the PR

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add deletion confirmation as an application level sync option

5 participants