ArgoCD + ApplicationSet

Overview

Now you’re going to deploy the same application using Argo CD, but this time into two namespaces at the same time.

We will use an ApplicationSet for this.

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: kitchensink-basic
  namespace: openshift-gitops
  labels:
    argocd-root-app: "true"
spec:
  generators: (1)
  - list:
      elements:
      - env: demo-4a
        desc: "Demo 4a"
      - env: demo-4b
        desc: "Demo 4b"
  template: (2)
    metadata:
      name: kitchensink-basic-app-{{ env }}
      namespace: openshift-gitops
      labels:
        kitchensink-root-app: "true"
      finalizers:
      - resources-finalizer.argocd.argoproj.io
    spec:
      destination:
        namespace: '{{ env }}'
        name: in-cluster
      ignoreDifferences:
      - group: apps.openshift.io
        kind: DeploymentConfig
        jqPathExpressions:
          - .spec.template.spec.containers[].image
      project: default
      syncPolicy:
        automated:
          selfHeal: true
        syncOptions:
          - CreateNamespace=true
      source:
        path: basic/base
        repoURL: "https://repository-gitea-system.apps.%BASE_SUBDOMAIN%/%USERNAME%/kitchensink-conf"
        targetRevision: main
1 We introduce the concept of generators. One Application per element.
2 Template to create Application objects underneath

The ApplicationSet controller is a Kubernetes controller that adds support for an ApplicationSet CustomResourceDefinition (CRD). This controller/CRD enables both automation and greater flexibility managing Argo CD Applications across a large number of clusters and within monorepos, plus it makes self-service usage possible on multitenant Kubernetes clusters.

Let’s explain the key parts:

1.- Generators

Generators, definitions that allow you to generate objects defined with the template.

  generators:
  - list:
      elements:
      - env: kitchensink-dev
      - env: kitchensink-test
2.- Template

Template that uses the generator as a model to generate objects of type Application.

  template:
    metadata:
      name: kitchensink-basic-app-{{ env }}
      namespace: openshift-gitops
      labels:
        kitchensink-root-app: "true"
      ...

Deploy Kitchensink app with ArgoCD + ApplicationSet

You have to run the next command that created the ApplicationSet object that deploys Kitchensink app in appset-a-%USERNAME% and appset-b-%USERNAME% by using a list generator and deploys the descriptors stored in git.

cat <<EOF | oc apply -n openshift-gitops -f -
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: kitchensink-basic-%USERNAME%
  namespace: openshift-gitops
  labels:
    argocd-root-app: "true"
    username: %USERNAME%
spec:
  generators: (1)
  - list:
      elements:
      - env: appset-a-%USERNAME%
        desc: "ApplicationSet A"
      - env: appset-b-%USERNAME%
        desc: "ApplicationSet B"
  template:
    metadata:
      name: kitchensink-basic-app-{{ env }}
      namespace: openshift-gitops
      labels:
        kitchensink-root-app: "true"
        username: %USERNAME%
      finalizers:
      - resources-finalizer.argocd.argoproj.io
    spec:
      destination:
        namespace: '{{ env }}'
        name: in-cluster
      ignoreDifferences:
      - group: apps.openshift.io
        kind: DeploymentConfig
        jqPathExpressions:
          - .spec.template.spec.containers[].image
      project: default
      syncPolicy:
        automated:
          selfHeal: true
        syncOptions:
          - CreateNamespace=true
      source:
        path: basic/base
        repoURL: "https://repository-gitea-system.apps.%BASE_SUBDOMAIN%/%USERNAME%/kitchensink-conf"
        targetRevision: main
EOF

Again, as we saw in the previous chapter, we can check the deployment status in both Argo and OpenShift.

Argo

Open the following link to see the new Application objects you just created through the ApplicationSet in ArgoCD UI.

https://openshift-gitops-server-openshift-gitops.apps.%BASE_SUBDOMAIN%
Apps

OpenShift

To see the progress of deployment you should go to namespace appset-a-%USERNAME% and namespace appset-b-%USERNAME% in the OpenShift web console or just copy the following links.

appset-a-%USERNAME%
https://console-openshift-console.apps.%BASE_SUBDOMAIN%/topology/ns/appset-a-%USERNAME%?view=graph
appset-b-%USERNAME%
https://console-openshift-console.apps.%BASE_SUBDOMAIN%/topology/ns/appset-b-%USERNAME%?view=graph