Discuss your project

Blog

Argo CD ApplicationSets for 300+ services that can change Git providers

Mher Poghosyan · 29 November 2026 · 7 min read

On the core product platform of an iGaming and crypto company, our lead engineer, Mher Poghosyan, redesigned how Argo CD ApplicationSets deploy the product. After the redesign, new environments come up faster and scale more easily, and 300+ services can move between GitHub, GitLab, Bitbucket and on-premises GitLab without the days or weeks of work such a move used to take.

This article explains the pattern behind that kind of setup, with working YAML: what usually goes wrong in the first version of a GitOps repository, and how to arrange generators so that “where a service lives” and “where it runs” are each written down once.

Why moving repositories takes weeks

Most GitOps setups start the same way. Someone writes an Argo CD Application for the first service, copies it for the second, and a year later there is one Application per service per environment, each with a hardcoded repoURL:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: payments-api-staging
  namespace: argocd
spec:
  project: payments
  source:
    repoURL: https://github.com/example-org/payments-api.git
    targetRevision: main
    path: deploy/chart
    helm:
      valueFiles: [values-staging.yaml]
  destination:
    name: staging
    namespace: payments

With a few hundred services, this has predictable costs:

Two facts, each written once

A deployment combines two independent facts:

  1. Where a service’s code and chart live: provider, repository, path.
  2. Where it runs: which clusters, which environments.

In ApplicationSet terms, a Git file generator reads a service catalog, a cluster generator lists the environments, and a matrix generator combines them. The template builds repoURL from the catalog, so no Application contains a hardcoded URL.

The service catalog

One small file per service in the GitOps repository:

# catalog/services/payments-api.yaml
service: payments-api
team: payments
source:
  provider: github
  repo: payments-api
  chart: deploy/chart

The provider is a short key, not a URL. Base URLs are defined once, in the ApplicationSet below. A file per service, rather than one long list, means adding a service is a one-file merge request that the owning team can make, with few merge conflicts.

Two naming details save debugging time. The key is service, not name, because the cluster generator already provides name (the cluster’s name). And there is no top-level path key, because the Git file generator reserves path for the file’s own location.

Environments as labeled clusters

Each environment is a cluster registered in Argo CD, and the cluster Secret carries labels:

apiVersion: v1
kind: Secret
metadata:
  name: cluster-staging
  namespace: argocd
  labels:
    argocd.argoproj.io/secret-type: cluster
    env: staging
    deploy-services: "true"
type: Opaque
stringData:
  name: staging
  server: https://<cluster-endpoint>
  config: |
    {"bearerToken": "<token>", "tlsClientConfig": {"caData": "<base64-ca>"}}

A new environment then means registering one cluster with the right labels. Every service in the catalog appears there on the next reconcile, with that environment’s values.

The ApplicationSet

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: services
  namespace: argocd
spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]
  syncPolicy:
    preserveResourcesOnDeletion: true
  generators:
    - matrix:
        generators:
          - clusters:
              selector:
                matchLabels:
                  deploy-services: "true"
              values:               # one place for every provider's base URL
                github: https://github.com/example-org
                gitlab: https://gitlab.com/example-org
                bitbucket: https://bitbucket.org/example-org
                gitlab-onprem: https://gitlab.example.internal/example-org
          - git:
              repoURL: https://github.com/example-org/gitops.git
              revision: main
              files:
                - path: "catalog/services/*.yaml"
  template:
    metadata:
      name: '{{ .service }}-{{ index .metadata.labels "env" }}'
    spec:
      project: '{{ .team }}'
      source:
        repoURL: '{{ index .values .source.provider }}/{{ .source.repo }}.git'
        targetRevision: main
        path: '{{ .source.chart }}'
        helm:
          valueFiles:
            - 'values-{{ index .metadata.labels "env" }}.yaml'
          ignoreMissingValueFiles: true
      destination:
        server: '{{ .server }}'
        namespace: '{{ .team }}'
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
          - CreateNamespace=true

What each part does:

The GitOps repository with the catalog is the one URL left hardcoded. It moves rarely, and when it does, it is a single change.

Moving services to another provider

With this structure, moving a group of services is a short, reviewable procedure:

  1. Mirror each repository with all branches and tags:

    git clone --mirror https://github.com/example-org/payments-api.git
    cd payments-api.git
    git push --mirror https://gitlab.example.internal/example-org/payments-api.git
  2. Give Argo CD access once per provider with a credential template. It matches every repository URL under the prefix, so there is no secret per repository:

    apiVersion: v1
    kind: Secret
    metadata:
      name: creds-gitlab-onprem
      namespace: argocd
      labels:
        argocd.argoproj.io/secret-type: repo-creds
    stringData:
      type: git
      url: https://gitlab.example.internal/example-org
      username: argocd
      password: <access-token>
  3. Change provider in the catalog in one merge request. For many files, run yq once per file: given several files, yq -i writes all of them into the first one.

    for f in catalog/services/*.yaml; do
      yq -i 'with(select(.source.provider == "github"); .source.provider = "gitlab-onprem")' "$f"
    done
  4. Argo CD updates the existing Applications in place: same name, new repoURL. If the mirror is complete, the manifests are identical and the Applications stay Synced. That is your check: any diff means the new repository is not on the same commit.

  5. Archive the old repositories after a quiet period, so nobody pushes to them by habit.

CI pipelines and image registries move separately; this covers the deployment side.

Pitfalls

Argo CD also has an SCM Provider generator that discovers repositories through the GitHub, GitLab or Bitbucket API. It saves writing a catalog, but it ties discovery to one provider’s API and deploys whatever matches a filter. When moving between providers is part of the plan, an explicit catalog is the safer source of truth.

Checklist

The idea carries beyond Argo CD: write each fact once and generate the rest. The same thinking is behind the one-flag mesh building block in our article about a zero-trust Istio mesh. If your GitOps repository has grown into hundreds of copied files, tell us what is in the way.

#argocd#gitops#kubernetes#devops