crossplane-contrib / provider-argocd

Crossplane provider to provision and manage Argo CD objects
Apache License 2.0
68 stars 35 forks source link

feat: add support for finalizers in application resource #159

Closed amotolani closed 2 months ago

amotolani commented 5 months ago

Description of your changes

Fixes #

I have:

How has this code been tested

MisterMX commented 4 months ago

The idea of finalizers in K8s is to have an operator (like, a Crossplane provider) suspend the deletion of a resource to perform some cleanup steps. Usually you would have a single finalizer added and removed by each operator.

@amotolani can you describe the use case why you would like to have a bunch of finalizers statically added here? It would forever block the deletion of the resource unless the user explicitly removes it before deleting the MR.

amotolani commented 4 months ago

The idea of finalizers in K8s is to have an operator (like, a Crossplane provider) suspend the deletion of a resource to perform some cleanup steps. Usually you would have a single finalizer added and removed by each operator.

@amotolani can you describe the use case why you would like to have a bunch of finalizers statically added here? It would forever block the deletion of the resource unless the user explicitly removes it before deleting the MR.

@MisterMX The Operator that uses these finalizers is the ArgoCD Operator. Adding this allows us to create the ArgoCD App with these finalizers to control behaviour of the ArgoCD App.

A specific use case for this is controlling the deletion behaviour for ArgoCD apps. Without deletion finalizers the default behaviour is to delete the ArgoCD App without cleaning up the resources created by the ArgoCD app in a cluster, adding finalizers will enable cascade deletion for ArgoCD Apps.

Reference Docs

MisterMX commented 4 months ago

Does this work with the delete flow of this controller? If a users adds arbitrary finalizers to an MR application and then deletes it with kubectl delete. Does ArgoCD cleanup all finalizers and finishes the deletion so the MR gets removed? Or is the controller stuck in a never ending delete reconcile if it is observing an ArgoCD app that is not going to be deleted due to a finalizer that is never removed?

amotolani commented 4 months ago

Does this work with the delete flow of this controller? If a users adds arbitrary finalizers to an MR application and then deletes it with kubectl delete. Does ArgoCD cleanup all finalizers and finishes the deletion so the MR gets removed? Or is the controller stuck in a never ending delete reconcile if it is observing an ArgoCD app that is not going to be deleted due to a finalizer that is never removed?

@MisterMX Sorry it took me a while to get back here.

ArgoCD will only cleanup valid finalizers. So if a user adds an arbitrary finalizer that is not valid it would block deletion of the ArgoCD Application and by extension the MR.

IMO this is an ArgoCD concern and not really one for the provider. Taking aside crossplane and provider-argocd, the same thing occurs when you create an ArgoCD application declaratively using the ArgoCD CRD application.argoproj.io

AFAIK Finalizers are the only way to control this deletion behaviour declaratively, and it comes with this issue you highlighted

amotolani commented 3 months ago

@MisterMX I made the suggested improvements