Q: Your company uses a central GitOps repository where ArgoCD monitors application manifests. When 60 developers open PRs simultaneously, ephemeral environment commits cause constant git merge conflicts and rebase failures in the central GitOps repo. How do you architect GitOps for ephemeral environments without repository contention?
Managing high-velocity ephemeral environment GitOps states without git merge conflicts across 100+ active pull request branches.
Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Use ArgoCD Pull Request Generator Directly Against Source Repos
Instead of committing preview manifests into a shared config repository, configure ArgoCD's `PullRequest` generator directly targeting the application source repository.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: ephemeral-preview-apps
spec:
generators:
- pullRequest:
github:
owner: acme-corp
repo: checkout-service
labels: ["preview"]
template:
metadata:
name: 'checkout-pr-{{number}}'
spec:
source:
repoURL: 'https://github.com/acme-corp/checkout-service.git'
targetRevision: '{{head_sha}}'
path: ./deploy/helm
destination:
namespace: 'pr-{{number}}'
server: 'https://kubernetes.default.svc'
Filter Ephemeral Environments with GitHub PR Labels
Only spin up preview environments when developers add a specific label (e.g. `preview`). This prevents spinning up clusters for minor documentation typo fixes.
Automated Environment Teardown on PR Merge
When the PR closes or merges, the ApplicationSet controller automatically detects the closed PR state and cleanly deletes the associated ArgoCD Application and Kubernetes namespace.
- Use ArgoCD ApplicationSet pullRequest generators instead of committing preview manifests to central repos.
- Trigger ephemeral preview environments conditionally using GitHub PR labels (e.g. 'preview').
- Rely on the ApplicationSet controller to automatically destroy ephemeral environments upon PR closure.