argoproj / argo-cd

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

Provide a way to tell ArgoCD that it should not delete but only disown a resource #15005

Open ein-stein-chen opened 9 months ago

ein-stein-chen commented 9 months ago

Summary

Provide an option on the Application and/or Resource level so that ArgoCD will never delete a resource but only disown it (by removing the tracking label/annotation e.g. app.kubernetes.io/instance).
If the resource used server-side-apply then ArgoCD should remove all fields it managed.

Motivation

If Argo CD is used to patch existing resources in the cluster which are not created by Argo CD itself, it would create problems if Argo CD would delete the resource.

Example:
Using Argo CD for managing custom labels on cluster nodes.

This can be achieved by creating an Application with the sync option ServerSideApply=true and then creating a (or templating) partial Node objects that only contain the labels we want to set.

---
apiVersion: v1
kind: Node
metadata:
  name: kubernetes-worker-0
  labels:
    env: staging

But this makes it rather easy to accidentally delete the node (either by directly deleting the Node via the UI or when the Application is deleted or during sync when pruning and the file was removed).

It is already possible to work around some of those problems, by not setting finalizers on the Application and adding the argocd.argoproj.io/sync-options: "Delete=false,Prune=false" annotation.

But this will (only) leave the option to delete the Node via the UI while it is not easily possible to simply tell Argo CD to disown the Node which will then stay in the UI as OutOfSync forever.

Also, it would be nice to remove all the fields Argo CD set/managed when disowning the node.

Proposal

Add a sync option on the Resource level (e.g. Disown) that can be one of:

Related

dadurex commented 6 months ago

+1 to this proposal.

kaiyuanlim commented 6 months ago

+1

Would be nice to have this as some of the resources are moved to being provisioned for example by terraform instead.

gadiener commented 6 months ago

+1 I'd love to have that available

danmanners commented 5 months ago

+1 this would be really useful, especially for namespaces that may be referenced in multiple applications

glasser commented 3 months ago

Am I correct in understanding that this is a workaround for doing a one-time disown:

akloss-cibo commented 3 months ago

I can't speak for the original author, but this is what I do:

for wf in $( kubectl --namespace argocd get application "$1" -o yaml | yq eval '.status.resources[] | select(.kind == "Workflow" and .requiresPruning) | .name' - ) ; do
  kubectl patch workflow $wf --type=merge -p '{"metadata":{"labels":{"app.kubernetes.io/instance":null}}}'
done
prune998 commented 3 months ago

you also need to get rid of the annotation

  annotations:
    argocd.argoproj.io/tracking-id: <app>:/Namespace:argocd-demo-project/test-argo-keep-ns
prune998 commented 3 months ago

Maybe an annotation like resourceTrackingMethod: none that we add on a resource, so ArgoCD would create it without labels/annotations for tracking ? This would be like creating the resource from outside the ArgoCD Apps... but it will not appear in the UI...

akloss-cibo commented 3 months ago

This would be like creating the resource from outside the ArgoCD Apps... but it will not appear in the UI...

I can't speak for the original author of this issue, but that's definitely not a feature I'm interested in.

chrisxuwq commented 2 weeks ago

I would vote for this feature that could allow resources to be disowned by ArgoCD, or they'll always appears to be out-of-sync if we don't actually want to delete them..