Skip to content

Commit 5e233b8

Browse files
Adding more comprehensive package documentation
1 parent 4b4243f commit 5e233b8

File tree

4 files changed

+98
-5
lines changed

4 files changed

+98
-5
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Package multigrescluster implements the controller for the root MultigresCluster resource.
2+
//
3+
// The MultigresCluster controller acts as the central orchestrator for the database system.
4+
// It is responsible for translating the high-level user intent into specific child resources.
5+
// Its primary responsibilities include:
6+
//
7+
// 1. Global Component Management:
8+
// It directly manages singleton resources defined at the cluster level, such as the
9+
// Global TopoServer (via a child TopoServer CR) and the MultiAdmin deployment.
10+
//
11+
// 2. Resource Fan-Out (Child CR Management):
12+
// It projects the configuration defined in the MultigresCluster spec (Cells and Databases)
13+
// into discrete child Custom Resources (Cell and TableGroup). These child resources are
14+
// then reconciled by their own respective controllers.
15+
//
16+
// 3. Template Resolution:
17+
// It leverages the 'pkg/resolver' module to fetch CoreTemplates, CellTemplates, and
18+
// ShardTemplates, merging them with user-defined overrides to produce the final
19+
// specifications for child resources.
20+
//
21+
// 4. Status Aggregation:
22+
// It continually observes the status of its child resources to produce a high-level
23+
// summary of the cluster's health (e.g., "All cells ready", "Database X has Y/Z shards ready").
24+
//
25+
// 5. Lifecycle Management:
26+
// It utilizes finalizers to ensure that all child resources are gracefully terminated
27+
// and cleaned up before the parent MultigresCluster is removed.
28+
package multigrescluster
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Package tablegroup implements the controller for the TableGroup resource.
2+
//
3+
// The TableGroup controller acts as a "middle-manager" in the Multigres hierarchy,
4+
// sitting between the root MultigresCluster and the leaf Shard resources.
5+
//
6+
// Responsibilities:
7+
//
8+
// 1. Shard Lifecycle Management:
9+
// It watches TableGroup resources and creates, updates, or deletes (prunes)
10+
// child Shard resources to match the list of fully resolved shard specifications
11+
// provided in the TableGroup spec.
12+
//
13+
// 2. Status Aggregation:
14+
// It monitors the status of all owned Shards and aggregates them into the
15+
// TableGroup's status (e.g., ReadyShards / TotalShards), providing a summarized
16+
// view for the parent MultigresCluster controller.
17+
//
18+
// Design Note:
19+
// This controller is intentionally "dumb" regarding configuration logic. It does not
20+
// perform template resolution or defaulting. It expects fully resolved specs to be
21+
// pushed down from the parent MultigresCluster controller, and its only job is to
22+
// enforce that state on the child Shards.
23+
package tablegroup

pkg/resolver/doc.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Package resolver provides the central logic for calculating the "Effective Specification" of a MultigresCluster.
2+
//
3+
// In the Multigres Operator, a cluster's configuration can come from multiple sources:
4+
// 1. Inline Configurations (defined directly in the MultigresCluster CR).
5+
// 2. Template References (pointing to CoreTemplate, CellTemplate, or ShardTemplate CRs).
6+
// 3. Overrides (partial patches applied on top of a template).
7+
// 4. Hardcoded Defaults (fallback values for safety).
8+
//
9+
// The Resolver is the single source of truth for merging these sources. It ensures that
10+
// the Reconciler and the Webhook always agree on what the final configuration should be.
11+
//
12+
// # Logic Hierarchy
13+
//
14+
// When calculating the final configuration for a component, the Resolver applies the
15+
// following precedence (highest to lowest):
16+
//
17+
// 1. Inline Spec (if provided, it ignores templates entirely).
18+
// 2. Overrides (patches specific fields of the template).
19+
// 3. Template Spec (the base configuration from the referenced CR).
20+
// 4. Global Defaults (hardcoded constants like default images or replicas).
21+
//
22+
// # Dual Usage
23+
//
24+
// This package is designed to be used in two distinct phases:
25+
//
26+
// 1. Mutation (Webhook):
27+
// The 'PopulateClusterDefaults' method is safe to call during admission. It applies
28+
// static defaults (images, explicit template names) to the API object itself,
29+
// solving the "Invisible Defaults" problem without making external API calls.
30+
//
31+
// 2. Reconciliation (Controller):
32+
// The 'Resolve...' and 'Merge...' methods are used during reconciliation. They
33+
// fetch external templates from the API server and merge them to determine the
34+
// actual state the child resources (StatefulSets, Services) should match.
35+
//
36+
// Usage:
37+
//
38+
// // Create a resolver
39+
// res := resolver.NewResolver(client, namespace, cluster.Spec.TemplateDefaults)
40+
//
41+
// // Webhook: Apply static defaults to the object
42+
// res.PopulateClusterDefaults(cluster)
43+
//
44+
// // Controller: Calculate final config for a specific component
45+
// template, err := res.ResolveShardTemplate(ctx, "my-shard-template")
46+
// finalConfig := resolver.MergeShardConfig(template, overrides, nil)
47+
package resolver

pkg/resolver/resolver.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// Package resolver provides the central logic for resolving MultigresCluster
2-
// defaults, templates, and configurations.
3-
//
4-
// It serves as the single source of truth for merging user inputs,
5-
// cluster-level defaults, and external templates into a final resource specification.
61
package resolver
72

83
import (

0 commit comments

Comments
 (0)