argoproj / argo-cd

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

ClusterWorkflow Template no namespace application is causing thousands of orphaned instances #20430

Open keekdageek opened 3 weeks ago

keekdageek commented 3 weeks ago

Describe the bug

We are creating a Cluster Workflow Templates application a namespace. The application project includes the orphanedResources.warn = true which then leads to ArgoCD reporting pretty much every resource in the cluster orphaned and starts to slow down the performance.

I'm aware of the workaround to just remove the orphanedResources from the project which is what we are doing.

apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: devops-ignore-orphan
  namespace: argo-system
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  description: "AppProject for managing devops instances of Applications that don't report orphaned"
  sourceRepos:
    - 'https://argoproj.github.io/argo-helm'
    - 'https://foobarcom/devops/cicd/devops-deployment-manifests'
    - '7777777777777.dkr.ecr.us-east-1.amazonaws.com/devops/cicd'
    - '7777777777777.dkr.ecr.us-west-2.amazonaws.com/devops/cicd'
  destinations:
    - namespace: "*"
      server: '*'
  clusterResourceWhitelist:
    - group: 'rbac.authorization.k8s.io'
      kind: ClusterRole
    - group: 'rbac.authorization.k8s.io'
      kind: ClusterRoleBinding
    - group: 'apiextensions.k8s.io'
      kind: CustomResourceDefinition
    - group: 'argoproj.io'
      kind: ClusterWorkflowTemplate
    - group: ''
      kind: Namespace

  orphanedResources:
    warn: true

It appears to be related to how belongToAnotherApp is calculated, in particular how the appKey := ctrl.toAppKey(appName) is calculated for this type of appproject without a namespace

https://github.com/argoproj/argo-cd/blob/9b11b21f00f006ec5bfca1ff39210e54b65bf4b5/controller/appcontroller.go#L600-L604

To Reproduce

Setup apprproject like defined above with a Cluster no namespace resource

Expected behavior

Don't show orphanedInstances seamlessly without the performance hit or check for this case and inform the user that it doesn't work with this type of application.

Version

❯ argocd version
argocd: v2.11.5+c4b283c
  BuildDate: 2024-07-15T18:15:32Z
  GitCommit: c4b283ce0c092aeda00c78ae7b3b2d3b28e7feec
  GitTreeState: clean
  GoVersion: go1.21.12
  Compiler: gc
  Platform: darwin/arm64
argocd-server: v2.11.5+c4b283c
  BuildDate: 2024-07-15T17:39:54Z
  GitCommit: c4b283ce0c092aeda00c78ae7b3b2d3b28e7feec
  GitTreeState: clean
  GoVersion: go1.21.10
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v5.2.1 2023-10-19T20:13:51Z
  Helm Version: v3.14.4+g81c902a
  Kubectl Version: v0.26.11
  Jsonnet Version: v0.20.0
andrii-korotkov-verkada commented 2 days ago

AppKey includes the namespace https://github.com/argoproj/argo-cd/blob/9b11b21f00f006ec5bfca1ff39210e54b65bf4b5/controller/appcontroller.go#L2398

We are creating a Cluster Workflow Templates application a namespace.

Can you rephrase it, please? I'm having a hard time understanding what exactly is being done. It'd be helpful if you share some resources definitions and application manifest.