argoproj / argo-cd

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

Application sets generating applications with the same name as the underlying dependencies fail to sync #20927

Open mishrasidhant opened 19 hours ago

mishrasidhant commented 19 hours ago

Checklist:

Describe the bug

There is a naming conflict in a nested structure that prevents certain applications from deploying correctly.

To Reproduce Using the main branch of this repo

  1. Create a root application that points to an appsets folder containing an ApplicationSet.
  2. Use a Git Directory generator in the ApplicationSet, pointing to a cluster-addons folder.
  3. The cluster-addons folder contains:
    • Kustomize YAML (argo-workflows)
    • Helm Chart (kubernetes-dashboard)
    • Application YAML pointing to 3rd party Helm charts (external-secrets and kube-prometheus-stack)
  4. The ApplicationSet names the applications it generates the same as their directory names:
    template:
     metadata:
       name: '{{.path.basename}}'
  5. The applications defined within cluster-addons are also named the same as their folder names:
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
     name: external-secrets
     namespace: argocd
    spec:
     project: default
     source:
       repoURL: https://charts.external-secrets.io
       chart: external-secrets
       targetRevision: 0.10.5
     destination:
       server: https://kubernetes.default.svc
       namespace: external-secrets
     syncPolicy:
       syncOptions:
         - CreateNamespace=true

Expected behavior

Argo CD should provide helpful feedback on what is going wrong when it tries to deploy the applications.

Screenshots

With naming conflict image image image image image

When fix is applied image image image

Version

argocd: v2.13.1+af54ef8
  BuildDate: 2024-11-20T18:35:51Z
  GitCommit: af54ef8db5adfa77a08d4d05b1318a2198084c22
  GitTreeState: clean
  GoVersion: go1.23.3
  Compiler: gc
  Platform: darwin/arm64
argocd-server: v2.13.1+af54ef8
  BuildDate: 2024-11-20T15:58:16Z
  GitCommit: af54ef8db5adfa77a08d4d05b1318a2198084c22
  GitTreeState: clean
  GoVersion: go1.23.1
  Compiler: gc
  Platform: linux/arm64
  Kustomize Version: v5.4.3 2024-07-19T16:40:33Z
  Helm Version: v3.15.4+gfa9efb0
  Kubectl Version: v0.31.0
  Jsonnet Version: v0.20.0

Logs

ComparisonError: Failed to load target state: failed to generate manifest for source 1 of 1: rpc error: code = Unknown desc = unable to resolve '0.10.5' to a commit SHA. Retrying attempt #3 at 12:49AM.

Additional context

The cluster-addons applications that point to 3rd party Helm charts (external-secrets, kube-prometheus-stack) would fail to sync and not deploy correctly. Helm charts and kustomize sources under cluster-addons would deploy without issues

Fix

Update the ApplicationSet to differentiate the applications it produces from those defined within cluster-addons:

template:
  metadata:
    name: '{{.path.basename}}-application' # used to be '{{.path.basename}}'

The code to reproduce the issue is available in this GitHub repository. The main branch contains the code that reproduces the bug, and the fix-name-conflict branch includes the fix.