Skip to content

Cluster generator in ApplicationSet silently ignored when selector is indented with 2 spaces instead 4 #22690

Open
@deniojunior-hotmart

Description

@deniojunior-hotmart

Checklist

  • I've searched in the docs and FAQ for my answer: https://bit.ly/argocd-faq.
  • I've included steps to reproduce the bug.
  • I've pasted the output of argocd version.

Describe the bug

The clusters generator in an ApplicationSet is silently ignored when the selector field is indented with 2 spaces instead of 4. ArgoCD does not throw a validation error or warning in the logs. Instead, the generator quietly returns 0 applications, which makes the issue hard to troubleshoot.

Example:

❌ Does not work (2 spaces after - clusters:):

generators:
  - clusters:
    selector:
      matchExpressions:
        - key: scope
          operator: In
          values: 
          - control-plane

✅ Works (4 spaces after - clusters:):

generators:
  - clusters:
      selector:
        matchExpressions:
          - key: scope
            operator: In
            values: 
            - control-plane

Note

Note that the selector field is indented with 4 spaces under - clusters: for the generator to function properly.

This is confusing because the 2-space version appears to be valid YAML. I’m not sure if this is expected behavior. If it is, the logs could be more explicit to help identify misconfigurations.

To Reproduce

  1. Create a cluster secret with the label that will be used for filtering:
apiVersion: v1
kind: Secret
metadata:
  name: in-cluster-secret
  namespace: argocd
  annotations:
    addons_repo_path: https://example.com/repo.git
    addons_repo_revision: HEAD
    addons_repo_url: path/to/app
    cluster_name: control-plane-cluster
    environment: staging
  labels:
    argocd.argoproj.io/secret-type: cluster
    scope: control-plane
data:
  name: Y29udHJvbC1wbGFuZS1jbHVzdGVyCg==
  server: aHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjCg==
  config: eyJiZWFyZXJUb2tlbiI6IiIsInRsc0NsaWVudENvbmZpZyI6eyJpbnNlY3VyZSI6ZmFsc2UsImNhRGF0YSI6IiJ9fQo=

Tip

Use base64 to decode the secret data if needed.

  • ✅ Confirm that the cluster secret with the label scope: control-plane exists in the argocd namespace after creating it.
kubectl get secrets -n argocd -l "argocd.argoproj.io/secret-type=cluster,scope=control-plane"
  1. Create an ApplicationSet using incorrect indentation (2 spaces after - clusters:):
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: addons
  namespace: argocd
spec:
  generators:
    - clusters:
      selector:
        matchExpressions:
          - key: scope
            operator: In
            values: 
            - control-plane
  template:
    metadata:
      name: 'addons-{{name}}'
    spec:
      project: default
      source:
        repoURL: https://example.com/repo.git
        path: path/to/app
        targetRevision: HEAD
      destination:
        name: '{{name}}'
        namespace: default
  1. Confirm that:
  • ❌ No Application objects are created.
kubectl get application -n argocd | grep addons-control-plane-cluster
  • ❌ Logs show generated 0 applications with no indication of misconfiguration.
kubectl logs <applicationset-controller-pod> -n argocd

time="2025-04-16T11:17:13Z" level=info msg="generated 0 applications" applicationset=argocd/addons generator="{nil nil nil nil nil nil nil nil &LabelSelector{MatchLabels:map[string]string{scope: control-plane,},MatchExpressions:[]LabelSelectorRequirement{},} nil}"
  1. Now, fix the indentation (4 spaces) and apply it:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: addons
  namespace: argocd
spec:
  generators:
    - clusters:
        selector:
          matchExpressions:
            - key: scope
              operator: In
              values: 
              - control-plane
  template:
    metadata:
      name: 'addons-{{name}}'
    spec:
      project: default
      source:
        repoURL: https://example.com/repo.git
        path: path/to/app
        targetRevision: HEAD
      destination:
        name: '{{name}}'
        namespace: default
  1. Force a reload by annotating the ApplicationSet:
kubectl annotate applicationset addons -n argocd "reconcile-timestamp=$(date +%s)" --overwrite
  1. Confirm that:
  • ✅ Application objects are created.
kubectl get application -n argocd | grep addons-control-plane-cluster

addons-control-plane-cluster   OutOfSync     Healthy
  • ✅ Logs show generated 1 applications:
kubectl logs <applicationset-controller-pod> -n argocd

time="2025-04-16T11:20:13Z" level=info msg="generated 1 applications" applicationset=argocd/addons generator="{nil &ClusterGenerator{Selector:{map[scope:control-plane] []},Template:ApplicationSetTemplate{ApplicationSetTemplateMeta:ApplicationSetTemplateMeta{Name:,Namespace:,Labels:map[string]string{},Annotations:map[string]string{},Finalizers:[],},Spec:ApplicationSpec{Source:nil,Destination:ApplicationDestination{Server:,Namespace:,Name:,},Project:,SyncPolicy:nil,IgnoreDifferences:[]ResourceIgnoreDifferences{},Info:[]Info{},RevisionHistoryLimit:nil,Sources:[]ApplicationSource{},},},Values:map[string]string{},} nil nil nil nil nil nil nil nil}"

Expected behavior

  • If this is a bug: the clusters generator should support 2-space indentation if it is valid YAML.
  • If this is an expected behavior: logs should indicate that the generator is being ignored due to structural issues, so it's easier to detect and fix.

Version

argocd: v2.11.0+d3f33c0
  BuildDate: 2024-05-07T18:31:19Z
  GitCommit: d3f33c00197e7f1d16f2a73ce1aeced464b07175
  GitTreeState: clean
  GoVersion: go1.22.2
  Compiler: gc
  Platform: darwin/arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcomponent:application-setsBulk application management related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions