4040
4141```
4242multigres-operator/
43- ├── api/v1alpha1/ # CRD definitions and types
43+ ├── go.mod # Root module (primarily for cmd)
4444├── cmd/multigres-operator/ # Main entry point
45- ├── internal/
46- │ ├── controller/ # Main reconciler and component reconcilers
47- │ │ ├── etcd/
48- │ │ ├── multigateway/
49- │ │ ├── multiorch/
50- │ │ └── multipooler/
51- │ ├── resources/ # Pure resource builder functions
52- │ ├── webhook/ # Admission webhooks (defaulting, validation)
53- │ └── testutil/ # Test helpers and utilities
45+ ├── pkg/
46+ │ ├── cluster-handler/ # Cluster-level orchestration (separate Go module)
47+ │ │ ├── go.mod
48+ │ │ └── controller/
49+ │ │ └── multigrescluster/ # MultigresCluster reconciler
50+ │ ├── data-handler/ # Data plane management (separate Go module)
51+ │ │ ├── go.mod
52+ │ │ └── controller/
53+ │ │ └── cell/ # Cell reconciler
54+ │ └── resource-handler/ # Component resources (separate Go module)
55+ │ ├── go.mod
56+ │ └── controller/
57+ │ ├── multigateway/
58+ │ ├── multiorch/
59+ │ ├── multipooler/
60+ │ └── etcd/
5461├── config/ # Kubernetes manifests for operator deployment
5562├── docs/ # Architecture, conventions, and development guides
5663└── plans/ # Planning documents
57- ```
58-
59- ### API Layer (` api/v1alpha1 ` )
60- - ** Purpose** : Defines Multigres custom resource schema
61- - ** Components** : MultigresSpec, MultigresStatus, component specs (MultiGatewaySpec, MultiOrchSpec, MultiPoolerSpec, EtcdSpec)
62- - ** Validation** : Kubebuilder markers for OpenAPI validation and defaults
6364
64- ### Controller Layer (` internal/controller ` )
65- - ** MultigresReconciler** : Main controller - manages lifecycle, finalizers, status aggregation
66- - ** Component Reconcilers** : etcd, multigateway, multiorch, multipooler reconcilers run in parallel
67- - ** Responsibilities** : Create/update resources, check component health, update status
65+ Note: go.work file can be created locally for development convenience. It is in .gitignore.
66+ ```
6867
69- ### Resource Layer (` internal/resources ` )
70- - ** Pure Functions** : Build Kubernetes manifests (Deployments, StatefulSets, Services, HPAs)
71- - ** Label Management** : Consistent label generation for resource selection
72- - ** No Side Effects** : Same input always produces same output
68+ ### Multi-Module Architecture
69+
70+ The operator is organized into three independent Go modules with clear separation of concerns. Developers can use ** Go workspaces** locally (` go.work ` ) for easier cross-module development, though this file is not committed to the repository:
71+
72+ #### Cluster Handler Module (` pkg/cluster-handler ` )
73+ - ** Purpose** : High-level cluster orchestration
74+ - ** Responsibilities** :
75+ - Uses the ` MultigresCluster ` custom resource as its primary input
76+ - Coordinates creation of child resources (MultiGateway, MultiOrch, MultiPooler, Etcd, Cell)
77+ - Aggregates status from child resources
78+ - Handles cluster-wide lifecycle (finalizers, upgrades)
79+ - ** Independence** : Can be tested and versioned separately from resource handlers
80+
81+ #### Data Handler Module (` pkg/data-handler ` )
82+ - ** Purpose** : Data plane management and topology
83+ - ** Responsibilities** :
84+ - Uses the ` Cell ` custom resource as its primary input (data topology abstraction)
85+ - Handles data plane configuration and routing
86+ - Coordinates with Vitess/Multigres data components
87+ - ** Independence** : Data plane logic isolated from control plane and resource management
88+
89+ #### Resource Handler Module (` pkg/resource-handler ` )
90+ - ** Purpose** : Individual component resource management
91+ - ** Responsibilities** :
92+ - Uses the ` MultiGateway ` , ` MultiOrch ` , ` MultiPooler ` , ` Etcd ` custom resources as its primary inputs
93+ - Creates and reconciles Kubernetes resources (Deployments, StatefulSets, Services, HPAs)
94+ - Implements pure resource builder functions
95+ - Component-specific health checking and status reporting
96+ - ** Independence** : Component reconcilers can evolve independently of cluster orchestration
97+
98+ ### Benefits of Multi-Module Structure
99+
100+ - ** Clear Boundaries** : Each module has distinct responsibilities and can be understood independently
101+ - ** Independent Testing** : Unit and integration tests scoped to each module
102+ - ** Parallel Development** : Teams can work on different modules without conflicts
103+ - ** Selective Imports** : Main binary only imports what it needs from each module
104+ - ** Version Flexibility** : Modules can evolve at different paces (though currently developed in lockstep)
73105
74106## Core Components
75107
@@ -85,14 +117,14 @@ The operator follows a standard Kubernetes reconciliation pattern:
85117
86118### Component Reconcilers
87119
88- Each Multigres component has its own reconciler :
120+ The ** resource-handler ** module contains individual reconcilers for each Multigres component :
89121
90- - ** etcd Reconciler** : Manages StatefulSet for etcd cluster, headless and client Services
91- - ** multigateway Reconciler** : Manages Deployment, Service, and optional HPA for MultiGateway
92- - ** multiorch Reconciler** : Manages Deployment and optional HPA for MultiOrch
93- - ** multipooler Reconciler** : Manages StatefulSet with multi-container pods (pooler, pgctld, postgres), and optional HPA
122+ - ** etcd Reconciler** ( ` pkg/resource-handler/controller/etcd ` ) : Manages StatefulSet for etcd cluster, headless and client Services
123+ - ** multigateway Reconciler** ( ` pkg/resource-handler/controller/multigateway ` ) : Manages Deployment, Service, and optional HPA for MultiGateway
124+ - ** multiorch Reconciler** ( ` pkg/resource-handler/controller/multiorch ` ) : Manages Deployment and optional HPA for MultiOrch
125+ - ** multipooler Reconciler** ( ` pkg/resource-handler/controller/multipooler ` ) : Manages StatefulSet with multi-container pods (pooler, pgctld, postgres), and optional HPA
94126
95- All component reconcilers run in parallel.
127+ All component reconcilers run in parallel and are independent of each other .
96128
97129### Resource Builders
98130
@@ -146,8 +178,8 @@ Current preference is init container pattern (same as Istio, NGINX Ingress), but
146178## Technology Stack
147179
148180### Language and Runtime
149- - ** Language** : Go 1.24 +
150- - ** Key Features** : Concurrency, interfaces, strong typing
181+ - ** Language** : Go 1.25 +
182+ - ** Key Features** : Concurrency, interfaces, strong typing, workspaces for multi-module projects
151183
152184### Key Dependencies
153185- ** Framework** : Kubebuilder v3 - scaffolding and patterns for Kubernetes operators
0 commit comments