# ramendr/ramen architecture

> Architecture diagram of the GitHub repository ramendr/ramen, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ramendr/ramen
- Repository: https://github.com/ramendr/ramen

## Overview

#### Purpose and runtime entry points
Ramen is a Go-based Kubernetes/OCM operator for disaster recovery across paired managed clusters. It reconciles custom resources to protect workloads and persistent data, then coordinates planned relocation or unplanned failover. The controller-manager binary starts at `cmd/main.go`; its API contract is defined in `api/v1alpha1/`. It is deployed in distinct hub and DR-cluster roles through `config/hub/manager/kustomization.yaml` and `config/dr-cluster/manager/kustomization.yaml`.

#### API and desired-state boundary
Ramen’s alpha CRDs express topology, policy, placement orchestration, cluster configuration, maintenance state, and data-protection objects. Key resources include `DRCluster`, `DRPolicy`, `DRPlacementControl` (DRPC), and `VolumeReplicationGroup` (VRG), defined in:
- `api/v1alpha1/drcluster_types.go`
- `api/v1alpha1/drpolicy_types.go`
- `api/v1alpha1/drplacementcontrol_types.go`
- `api/v1alpha1/volumereplicationgroup_types.go`

Generated/installable API surfaces are under `config/crd/bases/` and samples under `config/samples/`.

#### Hub-side orchestration
The hub reconciles DR cluster inventory/configuration and policy validity, then uses DRPC to turn an OCM placement plus DR policy into a chosen primary cluster and recovery workflow. Primary controllers are:
- `internal/controller/drcluster_controller.go`
- `internal/controller/drclusterconfig_controller.go`
- `internal/controller/drpolicy_controller.go`
- `internal/controller/drplacementcontrol_controller.go`

DRPC has specialized global, VolSync, watcher, network-mapping, and dry-run paths (`internal/controller/drplacementcontrol_global.go`, `internal/controller/drplacementcontrolvolsync.go`, `internal/controller/drpc_networkmapping.go`). This is the control-plane boundary between OCM placement decisions and per-cluster protection actions.

#### Managed-cluster protection engine
VRG is the managed-cluster execution unit: it selects PVCs, establishes protection state, reports status, and drives promotion/demotion during failover or relocation. Its main reconciler and strategy modules are:
- `internal/controller/volumereplicationgroup_controller.go`
- `internal/controller/vrg_volrep.go`
- `internal/controller/vrg_volgrouprep.go`
- `internal/controller/vrg_volsync.go`

The control flow is policy/placement → DRPC decision → VRG desired state on participating clusters → replication and workload readiness/status returned to the hub.

#### Replication and workload-protection adapters
Ramen isolates backend-specific mechanisms behind controller modules:
- CSI-addons VolumeReplication/VolumeGroupReplication for vendor-assisted replication: `internal/controller/vrg_volrep.go`, `internal/controller/vrg_volgrouprep.go`.
- VolSync snapshot/rsync protection and secret propagation: `internal/controller/volsync/vshandler.go`, `internal/controller/volsync/secret_propagator.go`.
- CephFS consistency-group replication: `internal/controller/cephfscg/cghandler.go`, `internal/controller/cephfscg/replicationgroupsource.go`.
- Velero request construction for discovered Kubernetes objects: `internal/controller/kubeobjects/velero/requests.go`.
- Recipe and lifecycle hooks for application-aware capture/recovery: `internal/controller/vrg_recipe.go`, `internal/controller/hooks/hooks_factory.go`.

These adapters are external-service boundaries; the operator creates and observes their Kubernetes APIs rather than implementing storage replication itself.

#### Platform integrations and operational boundary
Ramen depends on Kubernetes controller-runtime, OCM managed-cluster/placement resources, CSI-addons, and optionally Argo CD ApplicationSets, Velero, VolSync, Ceph/ODF, and S3-compatible object storage. S3 access is encapsulated in `internal/controller/s3utils.go` and `internal/controller/s3_store_accessors.go`. RBAC and leader-election permissions are packaged in `config/rbac/`; monitoring is exposed through `config/prometheus/`.

#### Packaging and validation
Kustomize assembles hub and managed-cluster deployments, CRDs, RBAC, certificates, and OLM artifacts (`config/hub/`, `config/dr-cluster/`, `config/olm-install/`). The container build is rooted at `Dockerfile`. Multi-cluster end-to-end execution is a separate Go harness in `e2e/`, while `test/drenv/` provisions local/external DR environments and integrations such as MinIO, OCM, Velero, VolSync, and Rook/Ceph.

Main entry points: [`internal/controller/volumereplicationgroup_controller.go`](https://github.com/ramendr/ramen/blob/main/internal/controller/volumereplicationgroup_controller.go) (VRG reconciler), [`cmd/main.go`](https://github.com/ramendr/ramen/blob/main/cmd/main.go) (Controller manager), [`internal/controller/drplacementcontrol_controller.go`](https://github.com/ramendr/ramen/blob/main/internal/controller/drplacementcontrol_controller.go) (DRPC orchestration), [`internal/controller/drcluster_controller.go`](https://github.com/ramendr/ramen/blob/main/internal/controller/drcluster_controller.go) (Cluster and policy reconcilers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and deployment"]
  node_manager["Controller manager<br/>Go entry point<br/>[main.go]"]
  node_api["DR custom resources<br/>Kubernetes API"]
  node_crds["Installable CRDs<br/>generated manifests"]
  node_hub_deployment["Hub deployment<br/>Kustomize overlay<br/>[kustomization.yaml]"]
  node_dr_deployment["DR-cluster deployment<br/>Kustomize overlay<br/>[kustomization.yaml]"]
  node_observability["RBAC and monitoring<br/>operational manifests"]
end

subgraph group_hub["Hub control plane"]
  node_cluster_policy["Cluster and policy reconcilers<br/>hub controllers"]
  node_drpc["DRPC orchestration<br/>hub controller"]
  node_ocm{{"OCM placement<br/>external Kubernetes APIs"}}
end

subgraph group_managed["Managed-cluster engine"]
  node_vrg["VRG reconciler<br/>managed-cluster controller"]
end

subgraph group_adapters["Protection adapters"]
  node_replication{{"CSI replication<br/>storage adapter<br/>[vrg_volrep.go]"}}
  node_volsync{{"VolSync protection<br/>protection adapter<br/>[vshandler.go]"}}
  node_cephfs{{"CephFS consistency groups<br/>storage adapter<br/>[cghandler.go]"}}
  node_velero{{"Velero object protection<br/>backup adapter<br/>[requests.go]"}}
  node_hooks["Recipes and lifecycle hooks<br/>application adapter<br/>[vrg_recipe.go]"]
  node_object_store[("S3 object storage<br/>external storage<br/>[s3utils.go]")]
end

node_hub_deployment -->|"deploys"| node_manager
node_dr_deployment -->|"deploys"| node_manager
node_manager -->|"watches and updates"| node_api
node_crds -->|"installs schema for"| node_api
node_manager -->|"runs on hub"| node_cluster_policy
node_manager -->|"runs on hub"| node_drpc
node_manager -->|"runs on DR clusters"| node_vrg
node_cluster_policy -->|"validates inventory and policy"| node_drpc
node_api -->|"DRPC and policy desired state"| node_drpc
node_ocm -->|"placement decisions"| node_drpc
node_drpc -->|"propagates protection actions"| node_vrg
node_vrg -->|"returns readiness and status"| node_drpc
node_vrg -->|"promotes, demotes, replicates"| node_replication
node_vrg -->|"drives snapshot and rsync"| node_volsync
node_vrg -->|"drives consistency groups"| node_cephfs
node_vrg -->|"protects Kubernetes objects"| node_velero
node_vrg -->|"runs application lifecycle"| node_hooks
node_volsync -->|"stores replication data"| node_object_store
node_vrg -->|"accesses protection artifacts"| node_object_store
node_observability -.->|"authorizes and monitors"| node_manager

click node_manager "https://github.com/ramendr/ramen/blob/main/cmd/main.go"
click node_hub_deployment "https://github.com/ramendr/ramen/blob/main/config/hub/manager/kustomization.yaml"
click node_dr_deployment "https://github.com/ramendr/ramen/blob/main/config/dr-cluster/manager/kustomization.yaml"
click node_cluster_policy "https://github.com/ramendr/ramen/blob/main/internal/controller/drcluster_controller.go"
click node_drpc "https://github.com/ramendr/ramen/blob/main/internal/controller/drplacementcontrol_controller.go"
click node_vrg "https://github.com/ramendr/ramen/blob/main/internal/controller/volumereplicationgroup_controller.go"
click node_replication "https://github.com/ramendr/ramen/blob/main/internal/controller/vrg_volrep.go"
click node_volsync "https://github.com/ramendr/ramen/blob/main/internal/controller/volsync/vshandler.go"
click node_cephfs "https://github.com/ramendr/ramen/blob/main/internal/controller/cephfscg/cghandler.go"
click node_velero "https://github.com/ramendr/ramen/blob/main/internal/controller/kubeobjects/velero/requests.go"
click node_hooks "https://github.com/ramendr/ramen/blob/main/internal/controller/vrg_recipe.go"
click node_object_store "https://github.com/ramendr/ramen/blob/main/internal/controller/s3utils.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_manager,node_api,node_crds,node_hub_deployment,node_dr_deployment,node_observability toneBlue
class node_cluster_policy,node_drpc,node_ocm toneAmber
class node_vrg toneMint
class node_replication,node_volsync,node_cephfs,node_velero,node_hooks,node_object_store toneRose
```

## Components

### API and deployment

- [Controller manager](https://github.com/ramendr/ramen/blob/main/cmd/main.go): Go entry point · Runs reconciler sets in hub or DR-cluster deployment roles. · `cmd/main.go`
- **DR custom resources**: Kubernetes API · DRCluster, DRPolicy, DRPC, and VRG desired-state contract.
- **Installable CRDs**: generated manifests
- [Hub deployment](https://github.com/ramendr/ramen/blob/main/config/hub/manager/kustomization.yaml): Kustomize overlay · `config/hub/manager/kustomization.yaml`
- [DR-cluster deployment](https://github.com/ramendr/ramen/blob/main/config/dr-cluster/manager/kustomization.yaml): Kustomize overlay · `config/dr-cluster/manager/kustomization.yaml`
- **RBAC and monitoring**: operational manifests

### Hub control plane

- [Cluster and policy reconcilers](https://github.com/ramendr/ramen/blob/main/internal/controller/drcluster_controller.go): hub controllers · Maintains DR inventory, configuration, and policy validity. · `internal/controller/drcluster_controller.go`
- [DRPC orchestration](https://github.com/ramendr/ramen/blob/main/internal/controller/drplacementcontrol_controller.go): hub controller · Converts OCM placement and DR policy into primary-cluster and recovery actions. · `internal/controller/drplacementcontrol_controller.go`
- **OCM placement**: external Kubernetes APIs

### Managed-cluster engine

- [VRG reconciler](https://github.com/ramendr/ramen/blob/main/internal/controller/volumereplicationgroup_controller.go): managed-cluster controller · Selects PVCs, drives protection state, and reports failover readiness. · `internal/controller/volumereplicationgroup_controller.go`

### Protection adapters

- [CSI replication](https://github.com/ramendr/ramen/blob/main/internal/controller/vrg_volrep.go): storage adapter · Uses CSI-addons VolumeReplication and VolumeGroupReplication APIs. · `internal/controller/vrg_volrep.go`
- [VolSync protection](https://github.com/ramendr/ramen/blob/main/internal/controller/volsync/vshandler.go): protection adapter · Handles snapshot/rsync protection and secret propagation. · `internal/controller/volsync/vshandler.go`
- [CephFS consistency groups](https://github.com/ramendr/ramen/blob/main/internal/controller/cephfscg/cghandler.go): storage adapter · `internal/controller/cephfscg/cghandler.go`
- [Velero object protection](https://github.com/ramendr/ramen/blob/main/internal/controller/kubeobjects/velero/requests.go): backup adapter · Builds backup and recovery requests for discovered Kubernetes objects. · `internal/controller/kubeobjects/velero/requests.go`
- [Recipes and lifecycle hooks](https://github.com/ramendr/ramen/blob/main/internal/controller/vrg_recipe.go): application adapter · Provides application-aware capture and recovery hooks. · `internal/controller/vrg_recipe.go`
- [S3 object storage](https://github.com/ramendr/ramen/blob/main/internal/controller/s3utils.go): external storage · `internal/controller/s3utils.go`

## Connections

- Hub deployment → Controller manager: deploys
- DR-cluster deployment → Controller manager: deploys
- Controller manager → DR custom resources: watches and updates
- Installable CRDs → DR custom resources: installs schema for
- Controller manager → Cluster and policy reconcilers: runs on hub
- Controller manager → DRPC orchestration: runs on hub
- Controller manager → VRG reconciler: runs on DR clusters
- Cluster and policy reconcilers → DRPC orchestration: validates inventory and policy
- DR custom resources → DRPC orchestration: DRPC and policy desired state
- OCM placement → DRPC orchestration: placement decisions
- DRPC orchestration → VRG reconciler: propagates protection actions
- VRG reconciler → DRPC orchestration: returns readiness and status
- VRG reconciler → CSI replication: promotes, demotes, replicates
- VRG reconciler → VolSync protection: drives snapshot and rsync
- VRG reconciler → CephFS consistency groups: drives consistency groups
- VRG reconciler → Velero object protection: protects Kubernetes objects
- VRG reconciler → Recipes and lifecycle hooks: runs application lifecycle
- VolSync protection → S3 object storage: stores replication data
- VRG reconciler → S3 object storage: accesses protection artifacts
- RBAC and monitoring → Controller manager: authorizes and monitors
