cloudogu/gitops-patterns
Intro
This repo collects some patterns (AKA strategies, models, approaches, best practices, etc.) about
GitOps process design (AKA GitOps repository structures, etc.) as well as links to talks, articles and example repos.
It originated in schnatterer's talk
about the "perfect" GitOps process, our experience in consulting,
and our GitOps trainings for both Flux and ArgoCD.
You can read more about the patterns in this series of articles.

PRs welcome!
Contents
Articles
Pattern categories
Let's group GitOps patterns into separate categories to make them easier to grasp.
See also part 1️⃣ of the article series.
- Operator deployment: GitOps operators ↔ Clusters/Namespaces
- Repository: How many repos?
- Promotion:
- Environments: How to model environments/stages?
- Implementation: How to implement the actual process of promotion?
- Wiring: Bootstrapping operator, linking repos and folders
GitOps Patterns
Operator deployment
See also part 2️⃣ of the article series.
- Hub and Spoke [^1][^2] 1 Operator : n Clusters
Synonyms: Management Cluster [^18] - sounds familiar, e.g. from Cluster API, but it requires a cluster. In SaaS/PaaS constellations, the central instance may not even be operated in a cluster. Therefore, the term "Hub and Spoke" seems more fitting to us, especially since it is also well known from computer networks or logistics.

- Instance Per Cluster [^18] : 1 Operator : 1 Cluster
Synonyms: Standalone [^1] - could apply to both "Instance per Cluster" and "Instance per Namespace"; does not define the relationship to clusters and namespaces precisely enough, as not every operator supports both deployment patterns.

- Instance per Namespace: n Operators : 1 Cluster
Synonyms: Namespaced [^3]

More Patterns:
- Split-Instance[^1]: 1 Operator : n Clusters; components split between management and target clusters
- Hybrids of Hub and Spoke and Instance per Cluster patterns: "Instance per Logical Group" and "Argo Managing more Argos".[^18]
Repository structure
See also part 3️⃣ of the article series.
- Monorepo [^2][^4]
Opposite: polyrepo [^2]
- Repo per Team [^4]
More generalized: Team ➡️ Tenant[^4]
- Repo per Application [^2][^4]
Implementations:
- Repo separation [^19]
Keep code in app repo, config in config repo 
- Config replication [^3]
Keep config in app repo and have CI server replicate it to the config repo
- Repo pointer [^6][^3][^4]
Keep the whole config in app repo and add a pointer from config repo (e.g. Argo CD Application or a Flux GitRepository+Kustomization), avoiding redundancy 
- Config Split [^20]
Keep parts of the config in app repo (e.g. helm chart or kustomize base), and rest in config repo (e.g. value.yamls or overlays for different envs).
Then have the config repo point to the app repo (e.g. via ArgoCD Application or Flux Kustomization).
Alternative implementations: have CI server push chart to **helm registry**
Or use push **helm chart to OCI registry**
Or use any config management tool (e.g. `helm template`, `kustomize build`, `kubectl kustomize`, [jsonnet](https://jsonnet.org/), [cuelang](https://cuelang.org/), [timoni](https://timoni.sh/), etc. ) on the CI server for pushing the final manifests as **OCI artifacts[^22] to the registry** (Rendered Manifests Pattern[^23]).
Then have the config repo point to the OCI artifact (e.g. via Flux `Kustomization`).
This way, the OCI registry functions as a "GitOps Cache"[^21]:
The operator only needs to pull the artifacts instead of rendering/overlaying the config from different sources.

- Repo per environment [^4]
Synonym: Environment per repository[^5], Repo per Stage
Promotion
See also part 4️⃣ of the article series.
We understand the term "promotion" as the process of deploying applications to different environments.
Sometimes, the term "promotion" is prefixed with other words: Release/Application/Environment/Workload/Change.
For promotion, we see different sets of patterns:
- one regarding the modelling of environments and
- one regarding the implementation of the actual process of promotion.
Environments
- Folder/Directory per environment
Synonym: Environment per folder [^5]
- Repo per environment [^4]
Synonym: Environment per repo [^5]
- Branch per environment
Synonym: Environment per branch [^5]
Often discouraged [^6] or declared an anti-pattern[^7][^14], but can work [^13].
- Preview environments [^9] [^10] [^11]
Synonyms: ephemeral, dynamic, pull request[^8], test, temporary[^9]
Beyond the GitOps world also known as "Preview Deployments"[^15] and "Deploy Previews"[^16]
Implementation