2 min read | by Jordi Prats
With ArgoCD's ApplicationSet controller we can automate the Application creation by automatically generate Argo CD Applications based on the ApplicationSet template.
Withing the ApplicationSet we can choose between several generators that can be used to create the Application instances
One of the possible generators is the list generator. With it we can specify a list of elements with as many attributes as we need that will be rendered using the spec.template. For example:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: pet2cattle-versions
namespace: argocd
spec:
generators:
- list:
elements:
- target: 1.0.0
instance: v1
- target: 2.0.0
instance: v2
template:
metadata:
name: pet2cattle-{{ instance }}
spec:
project: default
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
source:
repoURL: ssh://git@github.com:jordiprats/helm-pet2cattle.git
path: .
targetRevision: "{{ target }}"
helm:
values: |
ingress:
hosts:
- "{{ instance }}.pet2cattle.com
destination:
server: https://kubernetes.default.svc
namespace: pet2cattle
This is going to create the following two Applications:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: pet2cattle-v1
spec:
project: default
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
source:
repoURL: ssh://git@github.com:jordiprats/helm-pet2cattle.git
path: .
targetRevision: "1.0.0"
helm:
values: |
ingress:
hosts:
- "v1.pet2cattle.com"
destination:
server: https://kubernetes.default.svc
namespace: pet2cattle
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: pet2cattle-v2
spec:
project: default
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
source:
repoURL: ssh://git@github.com:jordiprats/helm-pet2cattle.git
path: .
targetRevision: "2.0.0"
helm:
values: |
ingress:
hosts:
- "v2.pet2cattle.com"
destination:
server: https://kubernetes.default.svc
namespace: pet2cattle
So, with this generator we can just add more elements to the list to automatically deploy a new application.
Posted on 08/06/2022