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:
- Changing Git providers is a mass edit. The URL sits in every Application for every environment: hundreds of files, often spread across repositories, each one a chance for a typo.
- A new environment is a copy. Copy a folder of Applications, find and replace the environment name, fix what the replace missed. Then the copies drift, because each one is edited by hand afterwards.
- No inventory. The only list of services is the set of Application files, and nobody can say for sure which service runs where.
- Access per repository. Hundreds of repository secrets in Argo CD, each to be recreated for the new provider.
Two facts, each written once
A deployment combines two independent facts:
- Where a service’s code and chart live: provider, repository, path.
- 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:
goTemplatewithmissingkey=error. A catalog file withoutchartorteamfails loudly instead of rendering an Application with an empty field.valueson the cluster generator holds the provider base URLs. Moving a whole organization to another provider is a change to these lines, or to theproviderkey of the services that move.- The Application name is service plus environment. It does not depend on where the code lives, and that is the most important line in the file (more on this below).
- Per-environment values live next to the chart in each service repository as
values-<env>.yaml.ignoreMissingValueFileslets a service skip an environment file when defaults are enough.
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:
-
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 -
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> -
Change
providerin the catalog in one merge request. For many files, runyqonce per file: given several files,yq -iwrites 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 -
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. -
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
-
Names that depend on location. If the Application name contains the provider or the repository URL, a move deletes the old Application and creates a new one. Applications generated by an ApplicationSet carry a finalizer that deletes their resources, unless
preserveResourcesOnDeletionis set. Keep names stable and keep that flag on. -
A deleted catalog file deletes the service everywhere. For production, consider
applicationsSync: create-updatein the ApplicationSet’ssyncPolicy, so it never deletes Applications on its own. It needs the policy override enabled in the ApplicationSet controller. -
Typos in
provider.indexreturns an empty string for an unknown key, so the Application gets a broken URL instead of a clear error. Check the catalog in CI:for f in catalog/services/*.yaml; do p=$(yq '.source.provider' "$f") case "$p" in github|gitlab|bitbucket|gitlab-onprem) ;; *) echo "$f: unknown provider '$p'"; exit 1 ;; esac done -
On-premises GitLab and TLS. The repo server must reach it over the network, and if it uses an internal CA, add that CA to the
argocd-tls-certs-cmConfigMap under the server’s hostname. -
Polling hundreds of repositories. Without webhooks, Argo CD polls every repository on each reconcile. Point webhooks from every provider at
/api/webhook: Argo CD understands GitHub, GitLab and Bitbucket events, and changes show up in seconds.
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
- No hardcoded
repoURLin Applications: one catalog entry per service - Provider base URLs defined in one place
- Environments are labeled clusters; a new one is a new Secret
- Application names do not depend on where the code lives
-
preserveResourcesOnDeletion: true, andcreate-updateconsidered for production - One credential template per provider, not one secret per repository
- A CI check for the catalog
- Webhooks from every provider
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.
