Skip to content

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

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

MrFreezeex
Copy link
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).

DO NOT MERGE AS IS, depends on: argoproj/gitops-engine#734

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

Copy link

bunnyshell bot commented Jun 12, 2025

❗ Preview Environment deployment failed on Bunnyshell

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove 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
Copy link

codecov bot commented Jun 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.15%. Comparing base (a3ef471) to head (38e4817).
Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #23370   +/-   ##
=======================================
  Coverage   60.15%   60.15%           
=======================================
  Files         343      343           
  Lines       59004    59041   +37     
=======================================
+ Hits        35494    35517   +23     
- Misses      20657    20661    +4     
- Partials     2853     2863   +10     

☔ 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
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
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
Contributor

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

@@ -14,6 +14,17 @@ metadata:
argocd.argoproj.io/sync-options: Prune=false
```

It also can be enabled at the application level like in the example below:
Copy link
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
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
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
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!

Signed-off-by: Arthur Outhenin-Chalandre <[email protected]>
As deletion confirmation acts on the whole Application it could makes
sense to add it as a sync option rather than a resource annotation. It
also could be more convenient to integrate in certain workflows for
users.

Signed-off-by: Arthur Outhenin-Chalandre <[email protected]>
@MrFreezeex
Copy link
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
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
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 +29 to +30
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
Member

Choose a reason for hiding this comment

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

Which one has the precedence? What happens if prune=false on the application level, but prune=confirm on the resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will apply both, in this case you will get a confirmation prompt and no resources will be pruned

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(This is the current behavior proposed by this PR but I can definitely take a look at figuring out some precedence policy if you want resource overriding app level or the other way around)

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
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
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

@@ -338,3 +338,5 @@ replace (
k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.33.1
k8s.io/sample-controller => k8s.io/sample-controller v0.33.1
)

replace github.com/argoproj/gitops-engine => github.com/MrFreezeex/gitops-engine v0.0.0-20250617130229-7f8ccfc83e5f
Copy link
Member

Choose a reason for hiding this comment

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

Remove when ready to merge

@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
For consistency with Prune/Delete=confirm that are now present as
application level sync option add Prune/Delete=false as sync option too.

Signed-off-by: Arthur Outhenin-Chalandre <[email protected]>
Signed-off-by: Arthur Outhenin-Chalandre <[email protected]>
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Changes Requested
Development

Successfully merging this pull request may close these issues.

Add deletion confirmation as an application level sync option
3 participants