argoproj / applicationset

The ApplicationSet controller manages multiple Argo CD Applications as a single ApplicationSet unit, supporting deployments to large numbers of clusters, deployments of large monorepos, and enabling secure Application self-service.
https://argocd-applicationset.readthedocs.io/
Apache License 2.0
584 stars 278 forks source link

Matrix generator - Combine SCM and Git Generators, consume parameters from parent #645

Open AlissonRS opened 1 year ago

AlissonRS commented 1 year ago

I was looking to have SCM generator discover repos in my organization that have a specific folder "k8s", then combine with Git generator to discover folders and generate one Application for each folder.

Consider two repos as follow:

Repo A k8s --- api --- job-a

Repo B k8s --- web --- api

So it would find both repos as both have the k8s folder, then create 4 applications (one for each subfolder).

So I could create an ApplicationSet as below:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: stakelands-appset
  namespace: argocd
spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]
  generators:
  - merge:
      generators:
        - scmProvider:
            github:
              organization: my-org
            cloneProtocol: ssh
            branchMatch: "\b(main|develop)\b"
            filters:
            - pathsExist: [k8s]
        - git:
            repoURL: '{{ url }}'
            revision: '{{ branch }}'
            directories:
            - path: k8s/*
  template:
    metadata:
      name: '{{.path.basename}}'
    spec:
      project: "default"
      source:
        repoURL: '{{ url }}'
        targetRevision: '{{ branch }}'
        path: '{{.path.path}}'
      destination:
        server: https://kubernetes.default.svc

Notice how in the Git generator I'm trying to use {{ url }} and {{ branch }} found by the SCM generator.

I thought this was implemented in #530 but I'm not sure that's the case, at least this is not working for me, and in the Matrix docs there is an example of combining Git + Cluster generators, but I don't really see the cluster generator referencing parameters from the Git generator, perhaps I misunderstood how it works.

Thanks!

AlissonRS commented 1 year ago

Btw this would also solve #279

Another solution would be just making SCM provider to support finding multiple paths (similar to Git generator), then there would be no need to use matrix generator.