0

While reading the Matric Generator: https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Matrix/ , I see we can combine two different Generators and deploy Applications on multiple Clusters at the same time.

For my use case where I have multiple folders in my Git Repo (Where I have my K8s resource yaml files) and I have 4 K8s clusters but I dont want all of my K8s yaml files in those folders to be deployed on all Clusters.

For example, this is my folder staructure:

https://www.test-gitlab.com/repo1/dev1

https://www.test-gitlab.com/repo1/dev2

https://www.test-gitlab.com/repo1/dev3 &

https://www.test-gitlab.com/repo1/dev4

Any my K8s Clusters are:

dev1

dev2

dev3 &

dev4

So from the above list, I want to target the files from dev1 folder to dev1 cluster and dev2 folder to dev2 cluster and so on.

Looks like by default, the Matric Generator (with git & cluster generator), it deploys all files from the provided path to all clusters.

How can I achieve this type of setup?

Cheers!!

1 Answers1

1

You don't need a matrix generator for this use case.

You can use either a simple list generator of you're fine "hardcoding" the list of folders or a Git generator if you want it to be dynamic.

With a list generator:

apiVersion: ...
kind: ApplicationSet
metadata:
  name: ...
  namespace: argocd
spec:
  generators:
  - list:
      elements:
      # If the mapping is one-to-one, you could even have only the folder attribute 
      - cluster: dev1
        folder: dev1
      - cluster: dev2
        folder: dev2
      - ...
  template:
    metadata:
      name: '{{cluster}}-myapp'
    spec:
      project: "my-project"
      source:
        repoURL: https://www.test-gitlab.com/repo1/
        targetRevision: HEAD
        path: '{{folder}}'
      destination:
        name: '{{cluster}}'
        namespace: ...

With a git generator:

apiVersion: ...
kind: ApplicationSet
metadata:
  name: ...
  namespace: argocd
spec:
  generators:
  - git:
      repoURL: https://www.test-gitlab.com/repo1/
      revision: HEAD
      directories:
      - path: *
  template:
    metadata:
      name: '{{path}}-myapp'
    spec:
      project: "my-project"
      source:
        repoURL: https://www.test-gitlab.com/repo1/
        targetRevision: HEAD
        path: '{{path}}'
      destination:
        name: '{{path}}'
        namespace: ...
crenshaw-dev
  • 7,504
  • 3
  • 45
  • 81
Gaël J
  • 11,274
  • 4
  • 17
  • 32